File size: 2,380 Bytes
6b30090
 
 
 
 
b07dc93
6b30090
 
c79be7e
6b30090
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b07dc93
 
6b30090
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
import streamlit as st
from groq import Groq
import os
import schemdraw
import schemdraw.elements as elm
import matplotlib.pyplot as plt  # Ensure matplotlib is imported

# Set your Groq API Key
client = Groq(api_key=os.getenv("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()

                    # To display the diagram correctly in Streamlit, use st.pyplot
                    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.")