Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Groq API configuration
|
| 6 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY")
|
| 7 |
+
GROQ_MODEL = "mixtral-8x7b-32768" # or "llama3-70b-8192", etc.
|
| 8 |
+
|
| 9 |
+
API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
| 10 |
+
HEADERS = {
|
| 11 |
+
"Authorization": f"Bearer {GROQ_API_KEY}",
|
| 12 |
+
"Content-Type": "application/json"
|
| 13 |
+
}
|
| 14 |
+
|
| 15 |
+
def query_groq(prompt):
|
| 16 |
+
payload = {
|
| 17 |
+
"model": GROQ_MODEL,
|
| 18 |
+
"messages": [
|
| 19 |
+
{"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."},
|
| 20 |
+
{"role": "user", "content": prompt}
|
| 21 |
+
],
|
| 22 |
+
"temperature": 0.5
|
| 23 |
+
}
|
| 24 |
+
response = requests.post(API_URL, headers=HEADERS, json=payload)
|
| 25 |
+
if response.status_code == 200:
|
| 26 |
+
return response.json()["choices"][0]["message"]["content"]
|
| 27 |
+
else:
|
| 28 |
+
return f"Error: {response.status_code} - {response.text}"
|
| 29 |
+
|
| 30 |
+
# Streamlit UI
|
| 31 |
+
st.set_page_config(page_title="Failure Diagnosis Bot", page_icon="🤖")
|
| 32 |
+
|
| 33 |
+
st.title("🤖 Failure Diagnosis Bot")
|
| 34 |
+
st.markdown("Diagnose machine faults based on symptoms.")
|
| 35 |
+
|
| 36 |
+
user_input = st.text_area("Describe your machine's issue:")
|
| 37 |
+
|
| 38 |
+
if st.button("Diagnose"):
|
| 39 |
+
if not user_input.strip():
|
| 40 |
+
st.warning("Please enter a description of the issue.")
|
| 41 |
+
else:
|
| 42 |
+
with st.spinner("Analyzing..."):
|
| 43 |
+
result = query_groq(user_input)
|
| 44 |
+
st.success("Diagnosis:")
|
| 45 |
+
st.markdown(result)
|