Luciferalive commited on
Commit
0725cd2
1 Parent(s): c27f172

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load the model
5
+ model_name = "knowledgator/comprehend_it-base"
6
+ classifier = pipeline("zero-shot-classification", model=model_name, device="cpu")
7
+
8
+ # Function to classify feedback
9
+ def classify_feedback(feedback_text):
10
+ # Classify feedback using the loaded model
11
+ labels = ["Procedures", "Maintenance", "Operations", "Health", "Safety"]
12
+
13
+ result = classifier(feedback_text, labels, multi_label=True)
14
+
15
+ # Get the top two labels associated with the feedback
16
+ top_labels = result["labels"][:2]
17
+ scores = result["scores"][:2]
18
+
19
+ # Generate HTML content for displaying the scores as meters/progress bars
20
+ html_content = ""
21
+ for i in range(len(top_labels)):
22
+ score_percentage = scores[i] * 100 # Convert score to percentage
23
+ html_content += f"<div><b>{top_labels[i]}:</b> {scores[i]:.2f} <div style='background-color: #e0e0e0; border-radius: 10px;'><div style='height: 24px; width: {score_percentage}%; background-color: #76b900; border-radius: 10px;'></div></div></div>"
24
+
25
+ return html_content
26
+
27
+ # Create Gradio interface
28
+ feedback_textbox = gr.Textbox(label="Enter your feedback:")
29
+ feedback_output = gr.HTML(label="Top 2 Labels with Scores:")
30
+
31
+ gr.Interface(
32
+ fn=classify_feedback,
33
+ inputs=feedback_textbox,
34
+ outputs=feedback_output,
35
+ title="Feedback Classifier",
36
+ description="Enter your feedback and get the top 2 associated labels with scores."
37
+ ).launch()