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