import gradio as gr from transformers import pipeline import numpy as np import matplotlib.pyplot as plt # Load NLP Model (example with Hugging Face pipeline) def initialize_model(): return pipeline("text-davinci-003") # Replace with your fine-tuned model if needed # Circuit Design Logic (Stub for now) def circuit_design(query): if "amplifier" in query.lower(): return { "design": "Use an operational amplifier with a gain of 10x. Suggested op-amp: LM741.", "schematic": "Example circuit diagram: Input -> Resistor (10k) -> Op-Amp -> Output." } elif "microcontroller" in query.lower(): return { "design": "Use a PIC16F877A for basic embedded applications.", "schematic": "Connect power pins, I/O peripherals, and crystal oscillator (20 MHz)." } else: return {"design": "Design not found.", "schematic": ""} # Testing Guidance Logic (Stub for now) def testing_guidance(query): if "amplifier" in query.lower(): return "Test using an oscilloscope to measure input and output signals. Ensure expected gain." elif "microcontroller" in query.lower(): return "Test by flashing firmware and checking functionality of I/O peripherals." else: return "No specific testing guidance found." # Chatbot response generation def chatbot_response(query): nlp_model = initialize_model() general_response = nlp_model(query) # Enhance response for circuit-specific queries if any(keyword in query.lower() for keyword in ["design", "circuit", "schematic"]): circuit_info = circuit_design(query) return general_response["generated_text"] + f"\n\nDesign Guidance: {circuit_info['design']}\nSchematic: {circuit_info['schematic']}" elif "test" in query.lower(): return general_response["generated_text"] + f"\n\nTesting Guidance: {testing_guidance(query)}" return general_response["generated_text"] # Gradio Interface def interface(query): response = chatbot_response(query) return response # Launch Gradio App with gr.Blocks() as app: gr.Markdown("# Embedded Systems Chatbot") with gr.Row(): user_query = gr.Textbox(label="Enter your query:", placeholder="Ask about circuit design, components, or testing...") response = gr.Textbox(label="Response:", interactive=False) submit_button = gr.Button("Submit") submit_button.click(interface, inputs=[user_query], outputs=[response]) app.launch()