Spaces:
Sleeping
Sleeping
import os | |
import openai | |
import pandas as pd | |
from sklearn.preprocessing import LabelEncoder | |
import numpy as np | |
import gradio as gr | |
openai.api_key = "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" | |
def classify_cause(incident_description): | |
response = openai.Completion.create( | |
engine="text-davinci-003", | |
prompt= f"Identify the root cause from the below list:\nincident_description:{incident_description}\n", | |
temperature= 0, | |
max_tokens= 50, | |
n=1, | |
stop=None | |
#timeout=15, | |
) | |
classification = response.choices[0].text.strip() | |
return classification | |
def classify_class(incident_description): | |
response = openai.Completion.create( | |
engine="text-davinci-003", | |
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", | |
temperature= 0, | |
max_tokens= 50, | |
n=1, | |
stop=None | |
#timeout=15, | |
) | |
classification = response.choices[0].text.strip() | |
return classification | |
def main(incident_description): | |
defect_class = classify_class(incident_description) | |
main_issue = classify_cause(incident_description) | |
return defect_class, main_issue | |
inputs = gr.inputs.Textbox(label="Flight Incident Description") | |
outputs = [gr.outputs.Textbox(label="Main Issue of the flight incident"), | |
gr.outputs.Textbox(label="category of the flight incident")] | |
demo = gr.Interface(fn=main,inputs=inputs,outputs=outputs, title="Flight predictive maintanance root cause") | |
demo.launch() | |