Spaces:
Sleeping
Sleeping
Update streamlit_app.py
Browse files- streamlit_app.py +19 -20
streamlit_app.py
CHANGED
|
@@ -2,16 +2,16 @@ import streamlit as st
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
# Load API key from
|
| 6 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 7 |
|
| 8 |
SYSTEM_PROMPT = """
|
| 9 |
-
You are an
|
| 10 |
1. Likely reason(s) for the vehicle issue
|
| 11 |
-
2.
|
| 12 |
-
3. Suggested fixes or
|
| 13 |
|
| 14 |
-
Keep your
|
| 15 |
"""
|
| 16 |
|
| 17 |
def query_groq(user_input):
|
|
@@ -21,8 +21,8 @@ def query_groq(user_input):
|
|
| 21 |
"Content-Type": "application/json"
|
| 22 |
}
|
| 23 |
|
| 24 |
-
|
| 25 |
-
"model": "llama2-70b-4096", # Or
|
| 26 |
"messages": [
|
| 27 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 28 |
{"role": "user", "content": user_input}
|
|
@@ -32,34 +32,33 @@ def query_groq(user_input):
|
|
| 32 |
}
|
| 33 |
|
| 34 |
try:
|
| 35 |
-
response = requests.post(url, headers=headers, json=
|
| 36 |
response.raise_for_status()
|
| 37 |
return response.json()["choices"][0]["message"]["content"]
|
| 38 |
except Exception as e:
|
| 39 |
return f"β Error: {str(e)}"
|
| 40 |
|
| 41 |
-
# Streamlit
|
| 42 |
-
st.set_page_config(page_title="Vehicle
|
| 43 |
-
|
| 44 |
-
st.
|
| 45 |
-
st.markdown("Describe your car issue (e.g. *my engine is overheating*) and get expert suggestions.")
|
| 46 |
|
| 47 |
if "chat_history" not in st.session_state:
|
| 48 |
st.session_state.chat_history = []
|
| 49 |
|
| 50 |
with st.form("chat_form", clear_on_submit=True):
|
| 51 |
-
user_input = st.text_input("
|
| 52 |
-
submitted = st.form_submit_button("
|
| 53 |
|
| 54 |
if submitted and user_input:
|
| 55 |
-
with st.spinner("Analyzing..."):
|
| 56 |
-
|
| 57 |
st.session_state.chat_history.append(("You", user_input))
|
| 58 |
-
st.session_state.chat_history.append(("Bot",
|
| 59 |
|
| 60 |
# Display chat history
|
| 61 |
-
for
|
| 62 |
-
if
|
| 63 |
st.markdown(f"**π§ You:** {message}")
|
| 64 |
else:
|
| 65 |
st.markdown(f"**π€ Bot:** {message}")
|
|
|
|
| 2 |
import requests
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
# Load Groq API key from Hugging Face secret
|
| 6 |
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 7 |
|
| 8 |
SYSTEM_PROMPT = """
|
| 9 |
+
You are an experienced automobile technician. Based on the user's question, provide:
|
| 10 |
1. Likely reason(s) for the vehicle issue
|
| 11 |
+
2. Diagnosis or explanation
|
| 12 |
+
3. Suggested fixes or preventive actions
|
| 13 |
|
| 14 |
+
Keep your answers simple, practical, and useful for everyday car owners.
|
| 15 |
"""
|
| 16 |
|
| 17 |
def query_groq(user_input):
|
|
|
|
| 21 |
"Content-Type": "application/json"
|
| 22 |
}
|
| 23 |
|
| 24 |
+
data = {
|
| 25 |
+
"model": "llama2-70b-4096", # Or another valid Groq-supported model
|
| 26 |
"messages": [
|
| 27 |
{"role": "system", "content": SYSTEM_PROMPT},
|
| 28 |
{"role": "user", "content": user_input}
|
|
|
|
| 32 |
}
|
| 33 |
|
| 34 |
try:
|
| 35 |
+
response = requests.post(url, headers=headers, json=data)
|
| 36 |
response.raise_for_status()
|
| 37 |
return response.json()["choices"][0]["message"]["content"]
|
| 38 |
except Exception as e:
|
| 39 |
return f"β Error: {str(e)}"
|
| 40 |
|
| 41 |
+
# Streamlit interface
|
| 42 |
+
st.set_page_config(page_title="Vehicle Diagnostic Chatbot", page_icon="π")
|
| 43 |
+
st.title("π Vehicle Issue Diagnostic Chatbot")
|
| 44 |
+
st.markdown("Describe your car problem (e.g. *my car is overheating*) and get expert suggestions.")
|
|
|
|
| 45 |
|
| 46 |
if "chat_history" not in st.session_state:
|
| 47 |
st.session_state.chat_history = []
|
| 48 |
|
| 49 |
with st.form("chat_form", clear_on_submit=True):
|
| 50 |
+
user_input = st.text_input("Enter your vehicle issue:")
|
| 51 |
+
submitted = st.form_submit_button("Submit")
|
| 52 |
|
| 53 |
if submitted and user_input:
|
| 54 |
+
with st.spinner("Analyzing your problem..."):
|
| 55 |
+
reply = query_groq(user_input)
|
| 56 |
st.session_state.chat_history.append(("You", user_input))
|
| 57 |
+
st.session_state.chat_history.append(("Bot", reply))
|
| 58 |
|
| 59 |
# Display chat history
|
| 60 |
+
for sender, message in st.session_state.chat_history:
|
| 61 |
+
if sender == "You":
|
| 62 |
st.markdown(f"**π§ You:** {message}")
|
| 63 |
else:
|
| 64 |
st.markdown(f"**π€ Bot:** {message}")
|