cirimus commited on
Commit
8ed0852
·
verified ·
1 Parent(s): f470f4e

Update app.py

Browse files

added support for the large version

Files changed (1) hide show
  1. app.py +22 -12
app.py CHANGED
@@ -1,27 +1,37 @@
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
- # Load the model
5
- model_name = "cirimus/modernbert-base-go-emotions"
6
- classifier = pipeline("text-classification", model=model_name, top_k=None)
 
 
7
 
8
- def classify_text(text):
 
 
9
  predictions = classifier(text)
10
  return {pred["label"]: pred["score"] for pred in predictions[0]}
11
 
12
  # Create the Gradio interface
13
  interface = gr.Interface(
14
  fn=classify_text,
15
- inputs=gr.Textbox(
16
- lines=2,
17
- placeholder="Enter text to analyze emotions...",
18
- value="I am thrilled to be a part of this amazing journey!"
19
- ),
 
 
 
 
 
 
 
20
  outputs=gr.Label(num_top_classes=5),
21
- title="Emotion Classifier",
22
- description="Enter a sentence to see its associated emotions and confidence scores.",
23
  )
24
 
25
-
26
  # Launch the app
27
  interface.launch()
 
1
  import gradio as gr
2
  from transformers import pipeline
3
 
4
+ # Define model names
5
+ models = {
6
+ "ModernBERT Base (Go-Emotions)": "cirimus/modernbert-base-go-emotions",
7
+ "ModernBERT Large (Go-Emotions)": "cirimus/modernbert-large-go-emotions"
8
+ }
9
 
10
+ # Function to load the selected model
11
+ def classify_text(text, model_name):
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(
18
  fn=classify_text,
19
+ inputs=[
20
+ gr.Dropdown(
21
+ list(models.keys()),
22
+ label="Select Model",
23
+ value="ModernBERT Base (Go-Emotions)"
24
+ ),
25
+ gr.Textbox(
26
+ lines=2,
27
+ placeholder="Enter text to analyze emotions...",
28
+ value="I am thrilled to be a part of this amazing journey!"
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
37
  interface.launch()