sileod commited on
Commit
68c3408
·
verified ·
1 Parent(s): 8230311

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -12
app.py CHANGED
@@ -11,17 +11,16 @@ def zeroShotClassification(text_input, candidate_labels):
11
  # Get predictions
12
  prediction = classifier(text_input, labels)
13
 
14
- # Format results as percentage with 2 decimal places
15
- results = {label: f"{score*100:.2f}%"
16
- for label, score in zip(prediction['labels'], prediction['scores'])}
17
 
18
- # Create markdown output for detailed view
19
  markdown_output = "### Results Breakdown:\n\n"
20
- for label, score in sorted(results.items(), key=lambda x: float(x[1].rstrip('%')), reverse=True):
21
- # Create confidence bar using Unicode blocks
22
- score_num = float(score.rstrip('%'))
23
- blocks = "█" * int(score_num/5) + "░" * (20 - int(score_num/5))
24
- markdown_output += f"**{label}**: {blocks} {score}\n\n"
25
 
26
  return results, markdown_output
27
 
@@ -66,7 +65,7 @@ demo = gr.Interface(
66
  ["The team scored in the final minute to win the championship", "sports, victory, competition, excitement"],
67
  ["The painting uses vibrant colors to express deep emotions", "art, emotion, creativity, analysis"]
68
  ],
69
- cache_examples=False, # Disable caching to prevent the error
70
  css="""
71
  footer {display:none !important}
72
  .output-markdown{display:none !important}
@@ -113,8 +112,7 @@ demo = gr.Interface(
113
  font-family: 'Inter', sans-serif !important;
114
  color: #11142D !important;
115
  }
116
- """,
117
- theme=gr.themes.Soft()
118
  )
119
 
120
  # Launch the app
 
11
  # Get predictions
12
  prediction = classifier(text_input, labels)
13
 
14
+ # For Label component: Return raw scores (not percentage strings)
15
+ results = {label: score for label, score in zip(prediction['labels'], prediction['scores'])}
 
16
 
17
+ # For Markdown: Create detailed view with percentage formatting
18
  markdown_output = "### Results Breakdown:\n\n"
19
+ for label, score in sorted(results.items(), key=lambda x: x[1], reverse=True):
20
+ # Convert to percentage for display
21
+ percentage = score * 100
22
+ blocks = "█" * int(percentage/5) + "░" * (20 - int(percentage/5))
23
+ markdown_output += f"**{label}**: {blocks} {percentage:.2f}%\n\n"
24
 
25
  return results, markdown_output
26
 
 
65
  ["The team scored in the final minute to win the championship", "sports, victory, competition, excitement"],
66
  ["The painting uses vibrant colors to express deep emotions", "art, emotion, creativity, analysis"]
67
  ],
68
+ cache_examples=False,
69
  css="""
70
  footer {display:none !important}
71
  .output-markdown{display:none !important}
 
112
  font-family: 'Inter', sans-serif !important;
113
  color: #11142D !important;
114
  }
115
+ """
 
116
  )
117
 
118
  # Launch the app