flutterbasit commited on
Commit
e759644
·
verified ·
1 Parent(s): befdaf2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +64 -0
app.py ADDED
@@ -0,0 +1,64 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from groq import Groq
3
+ import os
4
+ import schemdraw
5
+ import schemdraw.elements as elm
6
+ from pyngrok import ngrok
7
+
8
+ # Set your Groq API Key
9
+ os.environ["GROQ_API_KEY"] = "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"
10
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
11
+ # Start ngrok to create a tunnel to the streamlit app
12
+ public_url = ngrok.connect(8501)
13
+ st.write(f" * Your Streamlit app is running on: {public_url}")
14
+
15
+ # Streamlit UI
16
+ st.title("Electronics RAG App")
17
+ st.sidebar.title("Options")
18
+ st.sidebar.write("Choose an option below to get started:")
19
+
20
+ # Sidebar Options
21
+ option = st.sidebar.selectbox("Choose a feature:", ["Ask Electronics Question", "Generate Circuit Diagram"])
22
+
23
+ if option == "Ask Electronics Question":
24
+ st.header("Ask Electronics Question")
25
+ user_question = st.text_input("Enter your question:")
26
+ if st.button("Submit Question"):
27
+ if user_question:
28
+ try:
29
+ # Query Groq API
30
+ chat_completion = client.chat.completions.create(
31
+ messages=[{"role": "user", "content": user_question}],
32
+ model="llama3-8b-8192",
33
+ stream=False,
34
+ )
35
+ response = chat_completion.choices[0].message.content
36
+ st.success("Answer:")
37
+ st.write(response)
38
+ except Exception as e:
39
+ st.error(f"An error occurred: {e}")
40
+ else:
41
+ st.warning("Please enter a question!")
42
+
43
+ elif option == "Generate Circuit Diagram":
44
+ st.header("Generate Circuit Diagram")
45
+ circuit_description = st.text_area("Describe your circuit (e.g., 'A resistor, capacitor, and voltage source in series'):")
46
+
47
+ if st.button("Generate Diagram"):
48
+ if circuit_description:
49
+ # Generate a mock circuit diagram
50
+ try:
51
+ with schemdraw.Drawing() as d:
52
+ d += elm.SourceV().label("V1").up()
53
+ d += elm.Resistor().label("R1").right()
54
+ d += elm.Capacitor().label("C1").down()
55
+ d += elm.Line().left()
56
+ d += elm.Line().up()
57
+ st.pyplot(d.fig)
58
+ st.success("Circuit Diagram Generated!")
59
+ except Exception as e:
60
+ st.error(f"An error occurred: {e}")
61
+ else:
62
+ st.warning("Please describe your circuit!")
63
+
64
+ st.sidebar.info("Developed for creating and exploring electronics concepts interactively.")