mangalsana commited on
Commit
dbacffc
·
verified ·
1 Parent(s): 044f10b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -32
app.py CHANGED
@@ -3,63 +3,52 @@ import os
3
  from mistralai import Mistral
4
 
5
  api_key = os.getenv("MISTRAL_API_KEY")
 
 
 
 
6
  client = Mistral(api_key=api_key)
7
 
8
  def analyze_fault(log_input):
9
  if not log_input.strip():
10
  return "Please provide a factory log."
11
 
12
- prompt = f"""
 
13
  You are an industrial automation expert working in an ABB Smart Factory.
14
 
15
  Use Kepner-Tregoe (KT) structured problem analysis methodology.
16
 
17
- Follow strictly:
18
- 1. Problem Description (What, Where, When, Extent)
19
- 2. What IS analysis
20
- 3. What IS NOT analysis
21
- 4. Possible Causes
22
- 5. Most Probable Root Cause
23
- 6. Corrective Action
24
- 7. Preventive Action
25
- 8. Impact Assessment
26
- 9. Severity Level (Low/Medium/High/Critical)
27
- 10. Confidence Score (0-100%)
28
 
29
  Factory Log:
30
  ---
31
  {log_input}
32
  ---
33
-
34
- Return output in structured JSON format only.
35
  """
36
 
37
- response = client.chat.complete(
38
- model="mistral-large-latest",
39
- messages=[{"role": "user", "content": prompt}],
40
- temperature=0.2
41
- )
 
42
 
43
- return response.choices[0].message.content
 
 
 
44
 
45
 
46
  with gr.Blocks(title="ABB Smart Factory – KT Fault Intelligence") as demo:
47
  gr.Markdown("## 🏭 ABB Smart Factory – AI KT Fault Intelligence System")
48
- gr.Markdown("Paste Smart Factory Log below and analyze using structured KT methodology.")
49
-
50
- log_input = gr.Textbox(
51
- label="Factory Log Input",
52
- lines=12,
53
- placeholder="Paste factory PLC or robotic log here..."
54
- )
55
 
56
- output = gr.Textbox(
57
- label="AI KT Analysis Output",
58
- lines=20
59
- )
60
 
61
  analyze_button = gr.Button("Analyze Fault")
62
-
63
  analyze_button.click(analyze_fault, inputs=log_input, outputs=output)
64
 
 
 
65
  demo.launch(server_name="0.0.0.0", server_port=7860)
 
3
  from mistralai import Mistral
4
 
5
  api_key = os.getenv("MISTRAL_API_KEY")
6
+
7
+ if not api_key:
8
+ raise ValueError("MISTRAL_API_KEY not found in Secrets.")
9
+
10
  client = Mistral(api_key=api_key)
11
 
12
  def analyze_fault(log_input):
13
  if not log_input.strip():
14
  return "Please provide a factory log."
15
 
16
+ try:
17
+ prompt = f"""
18
  You are an industrial automation expert working in an ABB Smart Factory.
19
 
20
  Use Kepner-Tregoe (KT) structured problem analysis methodology.
21
 
22
+ Return output in structured JSON format only.
 
 
 
 
 
 
 
 
 
 
23
 
24
  Factory Log:
25
  ---
26
  {log_input}
27
  ---
 
 
28
  """
29
 
30
+ response = client.chat.complete(
31
+ model="mistral-large-latest",
32
+ messages=[{"role": "user", "content": prompt}],
33
+ temperature=0.2,
34
+ max_tokens=800
35
+ )
36
 
37
+ return response.choices[0].message.content
38
+
39
+ except Exception as e:
40
+ return f"Error occurred: {str(e)}"
41
 
42
 
43
  with gr.Blocks(title="ABB Smart Factory – KT Fault Intelligence") as demo:
44
  gr.Markdown("## 🏭 ABB Smart Factory – AI KT Fault Intelligence System")
 
 
 
 
 
 
 
45
 
46
+ log_input = gr.Textbox(label="Factory Log Input", lines=12)
47
+ output = gr.Textbox(label="AI KT Analysis Output", lines=20)
 
 
48
 
49
  analyze_button = gr.Button("Analyze Fault")
 
50
  analyze_button.click(analyze_fault, inputs=log_input, outputs=output)
51
 
52
+
53
+
54
  demo.launch(server_name="0.0.0.0", server_port=7860)