ilahaG commited on
Commit
37f6af0
·
verified ·
1 Parent(s): bceab12
README.md CHANGED
@@ -1,12 +1,16 @@
1
- ---
2
- title: EmotionsApp
3
- emoji: 🏢
4
- colorFrom: yellow
5
- colorTo: pink
6
- sdk: gradio
7
- sdk_version: 5.30.0
8
- app_file: app.py
9
- pinned: false
10
- ---
11
-
12
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
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