import streamlit as st from groq import Groq import os import schemdraw import schemdraw.elements as elm # Set your Groq API Key os.environ["GROQ_API_KEY"] = "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" client = Groq(api_key=os.environ.get("GROQ_API_KEY")) # Streamlit UI st.title("Electronics RAG App") st.sidebar.title("Options") st.sidebar.write("Choose an option below to get started:") # Sidebar Options option = st.sidebar.selectbox("Choose a feature:", ["Ask Electronics Question", "Generate Circuit Diagram"]) if option == "Ask Electronics Question": st.header("Ask Electronics Question") user_question = st.text_input("Enter your question:") if st.button("Submit Question"): if user_question: try: # Query Groq API chat_completion = client.chat.completions.create( messages=[{"role": "user", "content": user_question}], model="llama3-8b-8192", stream=False, ) response = chat_completion.choices[0].message.content st.success("Answer:") st.write(response) except Exception as e: st.error(f"An error occurred: {e}") else: st.warning("Please enter a question!") elif option == "Generate Circuit Diagram": st.header("Generate Circuit Diagram") circuit_description = st.text_area("Describe your circuit (e.g., 'A resistor, capacitor, and voltage source in series'):") if st.button("Generate Diagram"): if circuit_description: # Generate a mock circuit diagram try: with schemdraw.Drawing() as d: d += elm.SourceV().label("V1").up() d += elm.Resistor().label("R1").right() d += elm.Capacitor().label("C1").down() d += elm.Line().left() d += elm.Line().up() st.pyplot(d.fig) st.success("Circuit Diagram Generated!") except Exception as e: st.error(f"An error occurred: {e}") else: st.warning("Please describe your circuit!") st.sidebar.info("Developed for creating and exploring electronics concepts interactively.")