Maryam-1 commited on
Commit
321e2dc
·
1 Parent(s): a837fe7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -1
app.py CHANGED
@@ -1,3 +1,27 @@
 
1
  import gradio as gr
 
2
 
3
- gr.Interface.load("models/SamLowe/roberta-base-go_emotions").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
  import gradio as gr
3
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
4
 
5
+ # Load the model from Hugging Face Model Hub
6
+ model_name = "SamLowe/roberta-base-go_emotions"
7
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
8
+ model = AutoModelForSequenceClassification.from_pretrained(model_name)
9
+
10
+ def predict_emotion(text):
11
+ inputs = tokenizer(text, return_tensors="pt")
12
+ outputs = model(**inputs)
13
+ logits = outputs.logits
14
+ predicted_class = logits.argmax().item()
15
+
16
+ return {"emotion_label": predicted_class}
17
+
18
+ iface = gr.Interface(
19
+ fn=predict_emotion,
20
+ inputs=gr.Textbox(),
21
+ outputs="label",
22
+ live=True,
23
+ title="Emotion Prediction",
24
+ description="Enter a sentence for emotion prediction.",
25
+ )
26
+
27
+ iface.launch()