breadlicker45 commited on
Commit
09e7c03
·
verified ·
1 Parent(s): 0f21896

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -4
app.py CHANGED
@@ -11,7 +11,19 @@ models = {
11
  def classify_text(model_name, text):
12
  classifier = pipeline("text-classification", model=models[model_name], top_k=None)
13
  predictions = classifier(text)
14
- return {pred["label"]: pred["score"] for pred in predictions[0]}
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  # Create the Gradio interface
17
  interface = gr.Interface(
@@ -20,7 +32,7 @@ interface = gr.Interface(
20
  gr.Dropdown(
21
  list(models.keys()),
22
  label="Select Model",
23
- value="ModernBERT Base (Go-Emotions)"
24
  ),
25
  gr.Textbox(
26
  lines=2,
@@ -29,8 +41,8 @@ interface = gr.Interface(
29
  )
30
  ],
31
  outputs=gr.Label(num_top_classes=5),
32
- title="🎭 ModernBERT Emotion Classifier",
33
- description="Select a model and enter a sentence to see its associated emotions and confidence scores.",
34
  )
35
 
36
  # Launch the app
 
11
  def classify_text(model_name, text):
12
  classifier = pipeline("text-classification", model=models[model_name], top_k=None)
13
  predictions = classifier(text)
14
+
15
+ # Map the numerical labels to human-readable labels
16
+ label_mapping = {"0": "Male", "1": "Female"}
17
+
18
+ # Construct the output dictionary with human-readable labels
19
+ output_predictions = {}
20
+ for pred in predictions[0]:
21
+ # Ensure the label is treated as a string for dictionary lookup
22
+ numerical_label_str = str(pred["label"])
23
+ human_readable_label = label_mapping.get(numerical_label_str, numerical_label_str) # Use fallback if label not in mapping
24
+ output_predictions[human_readable_label] = pred["score"]
25
+
26
+ return output_predictions
27
 
28
  # Create the Gradio interface
29
  interface = gr.Interface(
 
32
  gr.Dropdown(
33
  list(models.keys()),
34
  label="Select Model",
35
+ value="ModernBERT Large (gender)"
36
  ),
37
  gr.Textbox(
38
  lines=2,
 
41
  )
42
  ],
43
  outputs=gr.Label(num_top_classes=5),
44
+ title="ModernBERT gender Classifier",
45
+ description="Select a model and enter a sentence to see its associated gender and confidence scores.",
46
  )
47
 
48
  # Launch the app