Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import requests
|
| 3 |
+
import os
|
| 4 |
+
|
| 5 |
+
# Set your Groq API Key
|
| 6 |
+
GROQ_API_KEY = os.getenv("GROQ_API_KEY") # Set this in Hugging Face Secrets
|
| 7 |
+
|
| 8 |
+
# Groq API endpoint
|
| 9 |
+
API_URL = "https://api.groq.com/openai/v1/chat/completions"
|
| 10 |
+
|
| 11 |
+
# Define the assistant's behavior
|
| 12 |
+
SYSTEM_PROMPT = """
|
| 13 |
+
You are a mechanical failure diagnosis assistant.
|
| 14 |
+
Based on user input describing machine issues (like noises, overheating, etc.), you must:
|
| 15 |
+
1. Identify possible causes.
|
| 16 |
+
2. Recommend fixes or checks.
|
| 17 |
+
3. List basic tools or methods needed.
|
| 18 |
+
|
| 19 |
+
Keep answers clear, concise, and helpful for technicians and engineers.
|
| 20 |
+
"""
|
| 21 |
+
|
| 22 |
+
# Streamlit UI
|
| 23 |
+
st.set_page_config(page_title="Failure Diagnosis Bot", page_icon="🛠️")
|
| 24 |
+
st.title("🛠️ Mechanical Failure Diagnosis Bot")
|
| 25 |
+
st.markdown("Describe the issue you're facing with any mechanical system (e.g., gear noise, motor overheating).")
|
| 26 |
+
|
| 27 |
+
user_query = st.text_input("🔍 Describe your machine problem:")
|
| 28 |
+
|
| 29 |
+
if st.button("Diagnose") and user_query:
|
| 30 |
+
with st.spinner("Analyzing..."):
|
| 31 |
+
headers = {
|
| 32 |
+
"Authorization": f"Bearer {GROQ_API_KEY}",
|
| 33 |
+
"Content-Type": "application/json"
|
| 34 |
+
}
|
| 35 |
+
|
| 36 |
+
data = {
|
| 37 |
+
"model": "llama3-8b-8192",
|
| 38 |
+
"messages": [
|
| 39 |
+
{"role": "system", "content": SYSTEM_PROMPT},
|
| 40 |
+
{"role": "user", "content": user_query}
|
| 41 |
+
]
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
response = requests.post(API_URL, headers=headers, json=data)
|
| 45 |
+
|
| 46 |
+
if response.status_code == 200:
|
| 47 |
+
reply = response.json()["choices"][0]["message"]["content"]
|
| 48 |
+
st.markdown("### 🧠 Diagnosis Result:")
|
| 49 |
+
st.write(reply)
|
| 50 |
+
else:
|
| 51 |
+
st.error("Failed to get a response from the diagnosis engine. Please try again.")
|
| 52 |
+
else:
|
| 53 |
+
st.markdown("Enter a fault description above and click **Diagnose** to begin.")
|
| 54 |
+
|
| 55 |
+
st.markdown("---")
|
| 56 |
+
st.caption("Powered by Groq • Built with ❤️ by EngGloss")
|