Luciferalive commited on
Commit
25ba03e
1 Parent(s): 4297311

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -15
app.py CHANGED
@@ -11,30 +11,26 @@ def classify_feedback(feedback_text):
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 and their scores
15
  top_labels = result["labels"][:2]
16
  scores = result["scores"][:2]
17
 
18
- # Prepare the outputs to display both labels and their corresponding meters
19
- outputs = []
20
- for label, score in zip(top_labels, scores):
21
- label_with_score = f"{label}: {score:.2f}"
22
- outputs.append(gr.Label(label_with_score))
23
- outputs.append(gr.Meter(value=score))
24
 
25
- return outputs
26
 
27
  # Create Gradio interface
28
  feedback_textbox = gr.Textbox(label="Enter your feedback:")
29
- feedback_output = [gr.Label(), gr.Meter(), gr.Label(), gr.Meter()] # Output placeholders for two labels and meters
30
 
31
- iface = 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
- layout="vertical"
38
- )
39
-
40
- iface.launch()
 
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 = result["labels"][:2]
16
  scores = result["scores"][:2]
17
 
18
+ # Generate HTML content for displaying the scores as meters/progress bars
19
+ html_content = ""
20
+ for i in range(len(top_labels)):
21
+ score_percentage = scores[i] * 100 # Convert score to percentage
22
+ 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>"
 
23
 
24
+ return html_content
25
 
26
  # Create Gradio interface
27
  feedback_textbox = gr.Textbox(label="Enter your feedback:")
28
+ feedback_output = gr.HTML(label="Top 2 Labels with Scores:")
29
 
30
+ gr.Interface(
31
  fn=classify_feedback,
32
  inputs=feedback_textbox,
33
  outputs=feedback_output,
34
  title="Feedback Classifier",
35
+ description="Enter your feedback and get the top 2 associated labels with scores."
36
+ ).launch()