mangalsana's picture
Update app.py
1942eab verified
import gradio as gr
import os
from mistralai import Mistral
api_key = os.getenv("MISTRAL_API_KEY")
if not api_key:
raise ValueError("MISTRAL_API_KEY not found in Secrets.")
client = Mistral(api_key=api_key)
def analyze_fault(log_input):
if not log_input.strip():
return "Please provide a factory log."
try:
prompt = f"""
You are an industrial automation expert working in an ABB Smart Factory.
Use Kepner-Tregoe (KT) structured problem analysis methodology.
Return output in structured JSON format only.
Factory Log:
---
{log_input}
---
"""
response = client.chat.complete(
model="mistral-large-latest",
messages=[{"role": "user", "content": prompt}],
temperature=0.2,
max_tokens=800
)
return response.choices[0].message.content
except Exception as e:
return f"Error occurred: {str(e)}"
with gr.Blocks(title="ABB Smart Factory – KT Fault Intelligence") as demo:
gr.Markdown("## 🏭 ABB Smart Factory – AI KT Fault Intelligence System")
log_input = gr.Textbox(label="Factory Log Input", lines=12)
output = gr.Textbox(label="AI KT Analysis Output", lines=20)
analyze_button = gr.Button("Analyze Fault")
analyze_button.click(analyze_fault, inputs=log_input, outputs=output)
demo.launch(server_name="0.0.0.0", server_port=7860)