adzee17 commited on
Commit
b8ff17d
Β·
verified Β·
1 Parent(s): 353a47a

Update streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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 environment variable
6
  GROQ_API_KEY = os.getenv("GROQ_API_KEY")
7
 
8
  SYSTEM_PROMPT = """
9
- You are an expert automobile technician. Based on the user's question, provide:
10
  1. Likely reason(s) for the vehicle issue
11
- 2. A simple diagnosis
12
- 3. Suggested fixes or actions to prevent it
13
 
14
- Keep your answer clear, short, and helpful for general car users.
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
- payload = {
25
- "model": "llama2-70b-4096", # Or mixtral-8x7b-32768
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=payload)
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 UI
42
- st.set_page_config(page_title="Vehicle Issue Chatbot", page_icon="πŸš—", layout="centered")
43
-
44
- st.title("🚘 Vehicle Fault Diagnostic Chatbot")
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("Your vehicle issue:")
52
- submitted = st.form_submit_button("Get Advice")
53
 
54
  if submitted and user_input:
55
- with st.spinner("Analyzing..."):
56
- response = query_groq(user_input)
57
  st.session_state.chat_history.append(("You", user_input))
58
- st.session_state.chat_history.append(("Bot", response))
59
 
60
  # Display chat history
61
- for speaker, message in st.session_state.chat_history:
62
- if speaker == "You":
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}")