Spaces:
Sleeping
Sleeping
File size: 1,912 Bytes
65ff9c9 |
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 |
import streamlit as st
import requests
import os
# Set your Groq API Key
GROQ_API_KEY = os.getenv("GROQ_API_KEY") # Set this in Hugging Face Secrets
# Groq API endpoint
API_URL = "https://api.groq.com/openai/v1/chat/completions"
# Define the assistant's behavior
SYSTEM_PROMPT = """
You are a mechanical failure diagnosis assistant.
Based on user input describing machine issues (like noises, overheating, etc.), you must:
1. Identify possible causes.
2. Recommend fixes or checks.
3. List basic tools or methods needed.
Keep answers clear, concise, and helpful for technicians and engineers.
"""
# Streamlit UI
st.set_page_config(page_title="Failure Diagnosis Bot", page_icon="๐ ๏ธ")
st.title("๐ ๏ธ Mechanical Failure Diagnosis Bot")
st.markdown("Describe the issue you're facing with any mechanical system (e.g., gear noise, motor overheating).")
user_query = st.text_input("๐ Describe your machine problem:")
if st.button("Diagnose") and user_query:
with st.spinner("Analyzing..."):
headers = {
"Authorization": f"Bearer {GROQ_API_KEY}",
"Content-Type": "application/json"
}
data = {
"model": "llama3-8b-8192",
"messages": [
{"role": "system", "content": SYSTEM_PROMPT},
{"role": "user", "content": user_query}
]
}
response = requests.post(API_URL, headers=headers, json=data)
if response.status_code == 200:
reply = response.json()["choices"][0]["message"]["content"]
st.markdown("### ๐ง Diagnosis Result:")
st.write(reply)
else:
st.error("Failed to get a response from the diagnosis engine. Please try again.")
else:
st.markdown("Enter a fault description above and click **Diagnose** to begin.")
st.markdown("---")
st.caption("Powered by Groq โข Built with โค๏ธ by EngGloss")
|