File size: 3,061 Bytes
13c0a49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
import os
import openai
import pandas as pd
from sklearn.preprocessing import LabelEncoder
import numpy as np
import gradio as gr

openai.api_key = os.getenv("OPENAI_API_KEY")

def classify_defect(defect_description):
    response = openai.Completion.create(
    engine="text-davinci-003",
    prompt= f"Classify the following defect description into one of the given classes:Software Issue, Hardware Issue, Access Issue \nDefect Description:{defect_description}\nDefect Class:",
    temperature= 0,
    max_tokens= 50,
    n=1,
    stop=None
    #timeout=15,
    )
    classification = response.choices[0].text.strip()
    return classification
def access(defect_description):
    response = openai.Completion.create(
    engine="text-davinci-003",
    prompt=f"Classify the following defect description into one of the given classes:Login, Network \nDefect Description:{defect_description}\nDefect Class:",
    max_tokens= 225,
    n=1,
    stop=None
    #timeout=15,
    )
    classification = response.choices[0].text.strip()
    return classification
def software(defect_description):
    response = openai.Completion.create(
    model="text-davinci-003",
    prompt=f"identify the software from each item in below list:\n[{defect_description}]\nsoftware:",
    temperature=0.71,
    max_tokens=73,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
    )
    classification = response.choices[0].text.strip()
    return classification
def hardware(defect_description):
    response = openai.Completion.create(
    engine="text-davinci-003",
    prompt=f"identify the object from each item in below list:\n[{defect_description}]\nobject:",
    temperature=0.71,
    max_tokens=73,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
    )
    classification = response.choices[0].text.strip()
    return classification
def mainissue(defect_description):
    response = openai.Completion.create(
    engine="text-davinci-003",
    prompt=f"identify the main issue from defect description given below:\n{defect_description}\nmain issue:",
    temperature=0.71,
    max_tokens=73,
    top_p=1,
    frequency_penalty=0,
    presence_penalty=0
    )
    classification = response.choices[0].text.strip()
    return classification
def main(defect_description):
    defect_class = classify_defect(defect_description)
    main_issue = mainissue(defect_description)
    if defect_class == "Software Issue":
        sub_class = software(defect_description)
    elif defect_class == "Hardware Issue":
        sub_class = hardware(defect_description)
    elif defect_class =="Access Issue":
        sub_class = access(defect_description)
    else:
        sub_class = "Error"
    return defect_class, sub_class, main_issue
inputs = gr.inputs.Textbox(label="Ticket Description")
outputs = [gr.outputs.Textbox(label="Ticket Category"), gr.outputs.Textbox(label="Ticket Sub Category"),gr.outputs.Textbox(label="Main Issue of The Ticket")]

demo = gr.Interface(fn=main,inputs=inputs,outputs=outputs, title="AI Based Ticket Classification")
demo.launch()