Spaces:
Runtime error
Runtime error
sayem ahmed shayeed commited on
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,14 +1,26 @@
|
|
|
|
|
| 1 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 2 |
|
|
|
|
| 3 |
model_name = "shayeedahmed/psyche-bert-emotion-classifier"
|
| 4 |
-
|
| 5 |
-
# Load tokenizer and model
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
-
#
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
#
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 3 |
|
| 4 |
+
# Load model
|
| 5 |
model_name = "shayeedahmed/psyche-bert-emotion-classifier"
|
|
|
|
|
|
|
| 6 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 7 |
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 8 |
+
nlp = pipeline("text-classification", model=model, tokenizer=tokenizer)
|
| 9 |
+
|
| 10 |
+
# Define inference function
|
| 11 |
+
def classify_text(text):
|
| 12 |
+
result = nlp(text)
|
| 13 |
+
return result
|
| 14 |
|
| 15 |
+
# Gradio interface
|
| 16 |
+
iface = gr.Interface(
|
| 17 |
+
fn=classify_text,
|
| 18 |
+
inputs=gr.Textbox(label="Enter text here"),
|
| 19 |
+
outputs=gr.JSON(label="Prediction"),
|
| 20 |
+
title="Emotion Classifier",
|
| 21 |
+
description="Classifies text into emotions"
|
| 22 |
+
)
|
| 23 |
|
| 24 |
+
# Launch the app (this is mandatory!)
|
| 25 |
+
if __name__ == "__main__":
|
| 26 |
+
iface.launch()
|