diff --git a/Beginner_Projects/contents_lab.json b/Beginner_Projects/contents_lab.json new file mode 100644 index 0000000000..dac7815737 --- /dev/null +++ b/Beginner_Projects/contents_lab.json @@ -0,0 +1,93 @@ + + +{ + "components": [ + { + "name": "resistor", + "values": [ + { + "resistance": "10 ohms", + "availability": "Yes, this resistor is available in the lab.", + "count":20 + }, + { + "resistance": "100 ohms", + "availability": "Yes, this resistor is available in the lab." + } + ] + }, + { + "name": "inductor", + "values": [ + { + "inductance": "100 microhenries", + "availability":"Yes,this inductor is available in the lab.", + "count":40 + }, + { + "inductance": "1 millihenry", + "availability": "No, this inductor is not available in the lab." + } + ] + }, + { + "name": "capacitor", + "values": [ + { + "capacitance": "10 microfarads", + "availability": "Yes, this capacitor is available in the lab.", + "count":70 + }, + { + "capacitance": "100 microfarads", + "availability": "Yes, this capacitor is available in the lab." + } + ] + }, + { + "name": "transistor", + "values": [ + { + "type": "npn", + "model": "2N2222", + "availability": "Yes, this transistor is available in the lab." + }, + { + "type": "pnp", + "model": "2N2907", + "availability": "Yes, this transistor is available in the lab." + } + ] + }, + { + "name": "mosfet", + "values": [ + { + "type": "n channel", + "model": "IRF540", + "availability": "Yes, this MOSFET is available in the lab." + }, + { + "type": "p channel", + "model": "IRF9540", + "availability": "No, this MOSFET is not available in the lab." + } + ] + }, + { + "name": "ic", + "values": [ + { + "type": "operational amplifier", + "model": "LM358", + "availability": "Yes, this IC is available in the lab." + }, + { + "type": "555 timer", + "model": "LM555", + "availability": "Yes, this IC is available in the lab." + } + ] + } + ] +} diff --git a/Beginner_Projects/labbot.ipynb b/Beginner_Projects/labbot.ipynb new file mode 100644 index 0000000000..17833dfe7a --- /dev/null +++ b/Beginner_Projects/labbot.ipynb @@ -0,0 +1,256 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "text": [ + "Writing contents_lab.json\n" + ] + } + ], + "source": [ + "%%writefile contents_lab.json\n", + "\n", + "\n", + "{\n", + " \"components\": [\n", + " {\n", + " \"name\": \"resistor\",\n", + " \"values\": [\n", + " {\n", + " \"resistance\": \"10 ohms\",\n", + " \"availability\": \"Yes, this resistor is available in the lab.\",\n", + " \"count\":20\n", + " },\n", + " {\n", + " \"resistance\": \"100 ohms\",\n", + " \"availability\": \"Yes, this resistor is available in the lab.\"\n", + " }\n", + " ]\n", + " },\n", + " {\n", + " \"name\": \"inductor\",\n", + " \"values\": [\n", + " {\n", + " \"inductance\": \"100 microhenries\",\n", + " \"availability\":\"Yes,this inductor is available in the lab.\",\n", + " \"count\":40\n", + " },\n", + " {\n", + " \"inductance\": \"1 millihenry\",\n", + " \"availability\": \"No, this inductor is not available in the lab.\"\n", + " }\n", + " ]\n", + " },\n", + " {\n", + " \"name\": \"capacitor\",\n", + " \"values\": [\n", + " {\n", + " \"capacitance\": \"10 microfarads\",\n", + " \"availability\": \"Yes, this capacitor is available in the lab.\",\n", + " \"count\":70\n", + " },\n", + " {\n", + " \"capacitance\": \"100 microfarads\",\n", + " \"availability\": \"Yes, this capacitor is available in the lab.\"\n", + " }\n", + " ]\n", + " },\n", + " {\n", + " \"name\": \"transistor\",\n", + " \"values\": [\n", + " {\n", + " \"type\": \"npn\",\n", + " \"model\": \"2N2222\",\n", + " \"availability\": \"Yes, this transistor is available in the lab.\"\n", + " },\n", + " {\n", + " \"type\": \"pnp\",\n", + " \"model\": \"2N2907\",\n", + " \"availability\": \"Yes, this transistor is available in the lab.\"\n", + " }\n", + " ]\n", + " },\n", + " {\n", + " \"name\": \"mosfet\",\n", + " \"values\": [\n", + " {\n", + " \"type\": \"n channel\",\n", + " \"model\": \"IRF540\",\n", + " \"availability\": \"Yes, this MOSFET is available in the lab.\"\n", + " },\n", + " {\n", + " \"type\": \"p channel\",\n", + " \"model\": \"IRF9540\",\n", + " \"availability\": \"No, this MOSFET is not available in the lab.\"\n", + " }\n", + " ]\n", + " },\n", + " {\n", + " \"name\": \"ic\",\n", + " \"values\": [\n", + " {\n", + " \"type\": \"operational amplifier\",\n", + " \"model\": \"LM358\",\n", + " \"availability\": \"Yes, this IC is available in the lab.\"\n", + " },\n", + " {\n", + " \"type\": \"555 timer\",\n", + " \"model\": \"LM555\",\n", + " \"availability\": \"Yes, this IC is available in the lab.\"\n", + " }\n", + " ]\n", + " }\n", + " ]\n", + "}\n" + ] + }, + { + "cell_type": "code", + "execution_count": 2, + "metadata": {}, + "outputs": [], + "source": [ + "import json\n", + "import nltk\n", + "from nltk.tokenize import word_tokenize\n", + "from nltk.corpus import stopwords\n", + "import pyttsx3\n", + "import speech_recognition as sr\n", + "\n", + "#initialize text to speech\n", + "engine=pyttsx3.init()\n", + "\n", + "#initialize speech recognizer\n", + "recognizer=sr.Recognizer()\n", + "\n", + "#load components data from json\n", + "def load_components():\n", + " with open('contents_lab.json','r') as file:\n", + " data=json.load(file)\n", + " return data['components']\n", + "components=load_components()\n", + "\n", + "#func to preprocess the user's question\n", + "def preprocess_question(question):\n", + " stop_words=set(stopwords.words('english'))\n", + " tokens=word_tokenize(question.lower())\n", + " filtered_tokens=[word for word in tokens if word.isalnm() and word not in stop_words]\n", + " return'_'.join(filtered_tokens)\n", + "\n", + "#function to provide audio feedback\n", + "def provide_audio_feedback(text):\n", + " engine.say(text)\n", + " engine.runAndWait()\n", + "\n", + "#func to check availability of a specific component\n", + "def check_availability(component_name,attribute_name,attribute_value):\n", + " count=0\n", + " selected_component=next((comp for comp in components if comp['name'].lower()==component_name.lower()),None)\n", + " if not selected_component:\n", + " response=\"Component not found.Please enter a valid component name.\"\n", + " return response\n", + " \n", + " for value in selected_component['values']:\n", + " if value.get(attribute_name)==attribute_value:\n", + " count+=1\n", + "\n", + " if count>0:\n", + " return f\"There are{count}{attribute_value}{component_name} of {attribute_value} found in the lab.\"\n", + " else:\n", + " return f\"No {component_name} with {attribute_name} of {attribute_value} found in the lab.\"\n", + " \n", + "#func for user input from microphone\n", + "def get_speech_input(prompt):\n", + " with sr.Microphone() as source:\n", + " print(prompt)\n", + " provide_audio_feedback(prompt)\n", + " audio=recognizer.listen(source)\n", + " try:\n", + " text=recognizer.recognize_google(audio)\n", + " print(f\"You Said:{text}\")\n", + " return text\n", + " except sr.UnknownValueError:\n", + " print(\"Sorry, I did not understand that.\")\n", + " provide_audio_feedback(\"Sorry, I did not understand that.\")\n", + " return None\n", + " except sr.RequestError:\n", + " print(\"Sorry, there was an issue with the speech recognition service.\")\n", + " provide_audio_feedback(\"Sorry, there was an issue with the speech recognition service.\")\n", + " return None" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [] + }, + { + "cell_type": "code", + "execution_count": 3, + "metadata": {}, + "outputs": [], + "source": [ + "\n", + "# Function for checking interaction\n", + "def simulate_component_check():\n", + " while True:\n", + " component_name = get_speech_input(\"Enter the component name or say 'exit' to quit:\")\n", + " if component_name and component_name.lower() in ['exit', 'quit', 'stop']:\n", + " provide_audio_feedback(\"Ending the component check.\")\n", + " print(\"Ending the component check.\")\n", + " break\n", + "\n", + " attribute_name = get_speech_input(\"Enter the attribute you want to check:\")\n", + " if not attribute_name:\n", + " continue\n", + "\n", + " attribute_value = get_speech_input(f\"Enter the value for {attribute_name}:\")\n", + " if not attribute_value:\n", + " continue\n", + "\n", + " response = check_availability(component_name, attribute_name, attribute_value)\n", + " print(response)\n", + " provide_audio_feedback(response)\n" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# Run the component check simulation\n", + "simulate_component_check()" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "codemirror_mode": { + "name": "ipython", + "version": 3 + }, + "file_extension": ".py", + "mimetype": "text/x-python", + "name": "python", + "nbconvert_exporter": "python", + "pygments_lexer": "ipython3", + "version": "3.12.3" + } + }, + "nbformat": 4, + "nbformat_minor": 2 +}