Spaces:
Sleeping
Sleeping
Luciferalive
commited on
Commit
•
74a1f1c
1
Parent(s):
889cf93
Update app.py
Browse files
app.py
CHANGED
@@ -1,3 +1,31 @@
|
|
1 |
import gradio as gr
|
|
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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=0)
|
7 |
+
|
8 |
+
# Function to classify feedback
|
9 |
+
def classify_feedback(feedback_text):
|
10 |
+
# Classify feedback using the loaded model
|
11 |
+
labels = ["Value", "Facilities", "Experience", "Functionality", "Quality"]
|
12 |
+
result = classifier(feedback_text, labels, multi_label=True)
|
13 |
+
|
14 |
+
# Get the top two labels associated with the feedback
|
15 |
+
top_labels = [label for label, _ in result["labels"][:2]]
|
16 |
+
scores = [score for _, score in result["scores"][:2]]
|
17 |
+
|
18 |
+
return {top_labels[i]: scores[i] for i in range(len(top_labels))}
|
19 |
+
|
20 |
+
# Create Gradio interface
|
21 |
+
feedback_textbox = gr.inputs.Textbox(lines=5, label="Enter your feedback:")
|
22 |
+
feedback_output = gr.outputs.Textbox(label="Top 2 Labels with Scores:")
|
23 |
+
|
24 |
+
gr.Interface(
|
25 |
+
fn=classify_feedback,
|
26 |
+
inputs=feedback_textbox,
|
27 |
+
outputs=feedback_output,
|
28 |
+
title="Feedback Classifier",
|
29 |
+
description="Enter your feedback and get the top 2 associated labels with scores.",
|
30 |
+
capture_session=True
|
31 |
+
).launch()
|