File size: 1,501 Bytes
7c57145
 
 
 
 
 
621d3d1
7c57145
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import streamlit as st
import requests
import os

# Groq API configuration
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
GROQ_MODEL = "llama3-70b-8192"  #  "llama3-70b-8192", etc.

API_URL = "https://api.groq.com/openai/v1/chat/completions"
HEADERS = {
    "Authorization": f"Bearer {GROQ_API_KEY}",
    "Content-Type": "application/json"
}

def query_groq(prompt):
    payload = {
        "model": GROQ_MODEL,
        "messages": [
            {"role": "system", "content": "You are a helpful mechanical fault diagnosis assistant. When a user describes a mechanical issue, provide possible causes, recommended fixes, and required tools."},
            {"role": "user", "content": prompt}
        ],
        "temperature": 0.5
    }
    response = requests.post(API_URL, headers=HEADERS, json=payload)
    if response.status_code == 200:
        return response.json()["choices"][0]["message"]["content"]
    else:
        return f"Error: {response.status_code} - {response.text}"

# Streamlit UI
st.set_page_config(page_title="Failure Diagnosis Bot", page_icon="🤖")

st.title("🤖 Failure Diagnosis Bot")
st.markdown("Diagnose machine faults based on symptoms.")

user_input = st.text_area("Describe your machine's issue:")

if st.button("Diagnose"):
    if not user_input.strip():
        st.warning("Please enter a description of the issue.")
    else:
        with st.spinner("Analyzing..."):
            result = query_groq(user_input)
        st.success("Diagnosis:")
        st.markdown(result)