Spaces:
Sleeping
Sleeping
| 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") | |