File size: 1,626 Bytes
889cf93
74a1f1c
889cf93
74a1f1c
 
11c95b0
 
74a1f1c
 
 
 
 
 
25ba03e
d775997
 
74a1f1c
1fbc1a9
 
 
 
25ba03e
 
 
 
 
4297311
25ba03e
74a1f1c
 
d775997
25ba03e
74a1f1c
25ba03e
74a1f1c
 
 
 
25ba03e
 
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
import gradio as gr
from transformers import pipeline

# Load the model
model_name = "knowledgator/comprehend_it-base"
classifier = pipeline("zero-shot-classification", model=model_name, device="cpu")

# Function to classify feedback
def classify_feedback(feedback_text):
    # Classify feedback using the loaded model
    labels = ["Value", "Facilities", "Experience", "Functionality", "Quality"]
    result = classifier(feedback_text, labels, multi_label=True)
    
    # Get the top two labels associated with the feedback
    top_labels = result["labels"][:2]
    scores = result["scores"][:2]
    
    # Check if the accuracy of the top label is less than 30%
    if scores[0] < 0.5:
        return "Please provide another relevant feedback."
    
    # Generate HTML content for displaying the scores as meters/progress bars
    html_content = ""
    for i in range(len(top_labels)):
        score_percentage = scores[i] * 100  # Convert score to percentage
        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>"
    
    return html_content

# Create Gradio interface
feedback_textbox = gr.Textbox(label="Enter your feedback:")
feedback_output = gr.HTML(label="Top 2 Labels with Scores:")

gr.Interface(
    fn=classify_feedback,
    inputs=feedback_textbox,
    outputs=feedback_output,
    title="Feedback Classifier",
    description="Enter your feedback and get the top 2 associated labels with scores."
).launch()