File size: 2,073 Bytes
45542fe
 
 
 
e4ec6de
45542fe
 
e4ec6de
45542fe
b8ff17d
e4ec6de
b8ff17d
 
45542fe
b8ff17d
45542fe
 
 
e4ec6de
 
45542fe
 
 
 
 
b8ff17d
e4ec6de
45542fe
 
 
 
 
 
 
 
 
b8ff17d
45542fe
 
 
 
 
e4ec6de
 
 
 
45542fe
 
 
 
 
e4ec6de
 
45542fe
 
e4ec6de
 
45542fe
e4ec6de
45542fe
e4ec6de
b8ff17d
e4ec6de
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
64
import streamlit as st
import requests
import os

# Load your Groq API key from Hugging Face secret
GROQ_API_KEY = os.getenv("GROQ_API_KEY")

# System prompt for the chatbot
SYSTEM_PROMPT = """
You are an experienced automobile technician. Based on the user's question, provide:
1. Likely reasons for the vehicle issue
2. Diagnosis or explanation
3. Suggested fixes or preventive actions

Keep your answers simple, practical, and useful for everyday car owners.
"""

def query_groq(user_input):
    url = "https://api.groq.com/openai/v1/chat/completions"  # βœ… Correct endpoint

    headers = {
        "Authorization": f"Bearer {GROQ_API_KEY}",
        "Content-Type": "application/json"
    }

    data = {
        "model": "llama3-70b-8192",  # βœ… Supported Groq model
        "messages": [
            {"role": "system", "content": SYSTEM_PROMPT},
            {"role": "user", "content": user_input}
        ],
        "temperature": 0.5,
        "max_tokens": 500
    }

    try:
        response = requests.post(url, headers=headers, json=data)
        response.raise_for_status()
        return response.json()["choices"][0]["message"]["content"]
    except Exception as e:
        return f"❌ Error: {str(e)}"

# Streamlit UI
st.set_page_config(page_title="Vehicle Diagnostic Chatbot", page_icon="πŸš—")
st.title("πŸš— Vehicle Issue Diagnostic Chatbot")
st.markdown("Describe your vehicle issue (e.g. *My car is overheating*) and get expert help.")

if "chat_history" not in st.session_state:
    st.session_state.chat_history = []

with st.form("chat_form", clear_on_submit=True):
    user_input = st.text_input("Describe your vehicle problem:")
    submitted = st.form_submit_button("Get Diagnosis")

if submitted and user_input:
    with st.spinner("Analyzing..."):
        bot_reply = query_groq(user_input)
        st.session_state.chat_history.append(("You", user_input))
        st.session_state.chat_history.append(("Bot", bot_reply))

# Show chat history
for sender, message in st.session_state.chat_history:
    st.markdown(f"**{sender}:** {message}")