SupportTicket / app.py
anandshah7
Update app.py
33cdb2e
import gradio as gr
import pandas as pd
import matplotlib
import matplotlib.pyplot as plt
import numpy as np
import openpyxl
file_name = "cluster_fin_iter1.xlsx"
ques_1 = "what category is having the highest number of issues?"
ques_2 = "what category is having the highest number of issues ?"
def greet(name, intensity):
return "Hello, " + name + "!" * int(intensity)
def get_data():
df = pd.read_excel(file_name)
return df
def echo(message, history):
#TBD - Integerate with Llama 3. the below logic is just for the demo
message = message.lower()
if(message == "what category is having the highest number of issues?"):
merge_data = get_merge_data()
man_category = merge_data.max(axis=0) #TBD with the model
return "category 23: PR guide and contributor notes"
elif(message == "what category is having the highest number of issues?"):
merge_data = get_merge_data()
man_category = merge_data.max(axis=0)
return "category 23: PR guide and contributor notes"
elif(message == "what is category 23?"):
res = "category 23: PR Guides and contributor notes"
elif(message == "what all categories?" or message == "categories?"):
labels = get_labels()
res = str(labels['New_label'])
elif(message=="total categories"):
labels = get_labels()
res = "Total categories " + str(labels["cluster"].count())
elif (message == "least affected category?"):
merge_data = get_merge_data()
min_category = merge_data.min(axis = 0)
return "Least affected category is " + min_category["New_label"]
else:
res = "Can you repeat that again"
message = res
return message
def get_merge_data():
df = get_data()
bar_df = df['cluster'].value_counts().to_frame('count').rename_axis('cluster').reset_index()
label_df = pd.read_excel("cluster_label_final.xlsx")
df_merge_label = pd.merge(bar_df, label_df, "left", on="cluster")
return df_merge_label
def get_labels():
label_df = pd.read_excel("cluster_label_final.xlsx")
return label_df
def bar_plot_fn():
new_df = []
df = get_data()
bar_df = df['cluster'].value_counts().to_frame('count').rename_axis('cluster').reset_index()
label_df = pd.read_excel("cluster_label_final.xlsx")
df_merge_label = pd.merge(bar_df,label_df,"left",on="cluster")
print(bar_df)
fig = plt.figure()
return gr.BarPlot(
value=df_merge_label,
x='cluster',
y='count',
title="Automated Ticketing system",
tooltip=["cluster","New_label", "count"],
y_lim=[10, 4000],
)
# __________________
with gr.Blocks() as bar_plot:
with gr.Row():
with gr.Column():
plot = gr.BarPlot()
with gr.Row():
with gr.Column():
gr.ChatInterface(
fn=echo,
title="AI Agent For ATS",
multimodal= False)
bar_plot.load(fn=bar_plot_fn, outputs=plot)
bar_plot.launch(share=True)