Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import openai
|
| 3 |
+
import pandas as pd
|
| 4 |
+
from sklearn.preprocessing import LabelEncoder
|
| 5 |
+
import numpy as np
|
| 6 |
+
import gradio as gr
|
| 7 |
+
|
| 8 |
+
openai.api_key = "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"
|
| 9 |
+
|
| 10 |
+
def classify_cause(incident_description):
|
| 11 |
+
response = openai.Completion.create(
|
| 12 |
+
engine="text-davinci-003",
|
| 13 |
+
prompt= f"Identify the root cause from the below list:\nincident_description:{incident_description}\n",
|
| 14 |
+
temperature= 0,
|
| 15 |
+
max_tokens= 50,
|
| 16 |
+
n=1,
|
| 17 |
+
stop=None
|
| 18 |
+
#timeout=15,
|
| 19 |
+
)
|
| 20 |
+
classification = response.choices[0].text.strip()
|
| 21 |
+
return classification
|
| 22 |
+
def classify_class(incident_description):
|
| 23 |
+
response = openai.Completion.create(
|
| 24 |
+
engine="text-davinci-003",
|
| 25 |
+
prompt= f"Classify the following incident description into one of the given classes:Aircraft Autopilot Problem, Auxiliary Power Problem,Cabin Pressure Problem, Engine Problem,Fuel System Problem,Avionics Problem,Communications Problem,Electrical System Problem,Engine Problem,Fire/Smoke Problem,Fuel System Problem,Ground Service Problem,Hydraulic System Problem,Ice/Frost Problem,Landing Gear Problem,Maintenance Problem,Oxygen System Problem,other problem\nincident_description:{incident_description}\n",
|
| 26 |
+
temperature= 0,
|
| 27 |
+
max_tokens= 50,
|
| 28 |
+
n=1,
|
| 29 |
+
stop=None
|
| 30 |
+
#timeout=15,
|
| 31 |
+
)
|
| 32 |
+
classification = response.choices[0].text.strip()
|
| 33 |
+
return classification
|
| 34 |
+
|
| 35 |
+
inputs = gr.inputs.Textbox(label="Flight Incident Description")
|
| 36 |
+
outputs = [gr.outputs.Textbox(label="Main Issue of the flight incident"),
|
| 37 |
+
gr.outputs.Textbox(label="category of the flight incident")]
|
| 38 |
+
|
| 39 |
+
demo = gr.Interface(fn=main,inputs=inputs,outputs=outputs, title="Flight predictive maintanance root cause")
|
| 40 |
+
demo.launch()
|
| 41 |
+
|
| 42 |
+
|
| 43 |
+
|