File size: 1,906 Bytes
9ccd3cd
 
 
 
 
 
 
3b4eba5
9ccd3cd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f510ce0
 
 
 
 
9ccd3cd
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
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()