YonasMersha commited on
Commit
6b150af
·
verified ·
1 Parent(s): 5600200

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -11
app.py CHANGED
@@ -1,20 +1,27 @@
1
  import gradio as gr
2
- from huggingface_hub import InferenceClient
3
  from transformers import pipeline
4
- import torch
5
-
6
-
7
- # Load your model
8
- classifier = pipeline("text-classification", model="YonasMersha/fine-tuned-distilbert-emotion", tokenizer='YonasMersha/fine_tuned_distilbert_emotion')
9
 
 
 
 
 
 
 
10
 
11
  # Define the prediction function
12
  def classify(text):
13
- return classifier(text)[0]["label"]
 
14
 
15
- # Create the interface
16
- iface = gr.Interface(fn=classify, inputs="text", outputs="label")
17
- iface.launch()
 
 
 
 
 
18
 
 
19
  if __name__ == "__main__":
20
- demo.launch()
 
1
  import gradio as gr
 
2
  from transformers import pipeline
 
 
 
 
 
3
 
4
+ # Load the model and tokenizer from the same repository
5
+ classifier = pipeline(
6
+ "text-classification",
7
+ model="YonasMersha/fine-tuned-distilbert-emotion",
8
+ tokenizer="YonasMersha/fine-tuned-distilbert-emotion"
9
+ )
10
 
11
  # Define the prediction function
12
  def classify(text):
13
+ result = classifier(text)[0]
14
+ return result["label"]
15
 
16
+ # Create the Gradio interface
17
+ iface = gr.Interface(
18
+ fn=classify,
19
+ inputs=gr.Textbox(label="Enter a sentence", placeholder="e.g., I love this!"),
20
+ outputs=gr.Label(label="Predicted Emotion"),
21
+ title="Emotion Classifier",
22
+ description="Enter a sentence to classify its emotion (e.g., joy, sadness, anger)."
23
+ )
24
 
25
+ # Launch the interface
26
  if __name__ == "__main__":
27
+ iface.launch()