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