Spaces:
Sleeping
Sleeping
commited
Browse files- README.md +16 -12
- app.py +20 -0
- models/bert-base-goemotions-ekman/README.txt +2 -0
- requirements.txt +3 -0
README.md
CHANGED
|
@@ -1,12 +1,16 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Gradio Emotion Detection App
|
| 2 |
+
|
| 3 |
+
This app uses a fine-tuned BERT model (GoEmotions) to detect emotions in social media text.
|
| 4 |
+
|
| 5 |
+
## Run Locally
|
| 6 |
+
|
| 7 |
+
```bash
|
| 8 |
+
pip install -r requirements.txt
|
| 9 |
+
python app.py
|
| 10 |
+
```
|
| 11 |
+
|
| 12 |
+
## For Hugging Face Spaces
|
| 13 |
+
|
| 14 |
+
1. Upload this project to your new Space.
|
| 15 |
+
2. Make sure you upload the `bert-base-goemotions-ekman` model folder inside `models/`.
|
| 16 |
+
3. Hugging Face will automatically run `app.py`.
|
app.py
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load the model locally (assuming model files are in this folder)
|
| 5 |
+
classifier = pipeline("text-classification", model="./models/bert-base-goemotions-ekman", return_all_scores=True)
|
| 6 |
+
|
| 7 |
+
def detect_emotions(text):
|
| 8 |
+
results = classifier(text)[0]
|
| 9 |
+
sorted_results = sorted(results, key=lambda x: x["score"], reverse=True)
|
| 10 |
+
return {r['label']: round(r['score'], 3) for r in sorted_results}
|
| 11 |
+
|
| 12 |
+
demo = gr.Interface(
|
| 13 |
+
fn=detect_emotions,
|
| 14 |
+
inputs=gr.Textbox(lines=4, placeholder="Enter a tweet or comment..."),
|
| 15 |
+
outputs="label",
|
| 16 |
+
title="Emotion Detection with BERT (GoEmotions)",
|
| 17 |
+
description="Detect joy, sadness, anger, and other emotions from text using a BERT-based model fine-tuned on the GoEmotions dataset."
|
| 18 |
+
)
|
| 19 |
+
|
| 20 |
+
demo.launch()
|
models/bert-base-goemotions-ekman/README.txt
ADDED
|
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
|
|
|
| 1 |
+
Place your downloaded Hugging Face model files here from:
|
| 2 |
+
https://huggingface.co/bhadresh-savani/bert-base-goemotions-ekman
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|