maldons77 commited on
Commit
666fb88
Β·
verified Β·
1 Parent(s): a1597f1

Upload 5 files

Browse files
Files changed (5) hide show
  1. LICENSE +22 -0
  2. README.md +29 -0
  3. app.py +40 -0
  4. requirements.txt +3 -0
  5. runtime.txt +1 -0
LICENSE ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ MIT License
3
+
4
+ Copyright (c) 2025 Eric Maldon
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
README.md ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ ---
3
+ title: Emoji Mood Classifier
4
+ emoji: 🎭
5
+ colorFrom: yellow
6
+ colorTo: pink
7
+ sdk: gradio
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ # Emoji Mood Classifier
13
+
14
+ ## Overview
15
+ A lightweight and fun Hugging Face Space that performs sentiment analysis on text and returns a sequence of emojis matching the detected mood. Built using the `transformers` library and a pre-trained sentiment model, it provides a creative and unique way to visualize text sentiment.
16
+
17
+ ## Key Features
18
+ - Returns emoji sequences instead of boring labels.
19
+ - Works entirely on CPU with a lightweight model.
20
+ - Handles Positive, Negative, and Neutral moods.
21
+
22
+ ## How to Run Locally
23
+ ```bash
24
+ pip install -r requirements.txt
25
+ python app.py
26
+ ```
27
+
28
+ ## Acceptable Use
29
+ This project is for educational, research, and entertainment purposes only. Do not use it for harmful, illegal, or unethical purposes. It follows Hugging Face and model license policies.
app.py ADDED
@@ -0,0 +1,40 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ # Load a lightweight sentiment model (CPU-friendly)
5
+ classifier = pipeline("sentiment-analysis")
6
+
7
+ # Map model labels to emoji sets
8
+ EMOJI_MAP = {
9
+ "POSITIVE": ["😊", "🌟", "πŸ’–", "πŸ”₯", "πŸŽ‰"],
10
+ "NEGATIVE": ["😞", "πŸ’”", "😑", "😭", "πŸ‘Ž"],
11
+ "NEUTRAL": ["😐", "πŸ€”", "πŸ“˜", "πŸ’¬", "πŸ”"],
12
+ }
13
+
14
+ def analyze_mood(text: str) -> str:
15
+ if not text or not text.strip():
16
+ return "❌ Please enter some text."
17
+ result = classifier(text)[0]
18
+ label = result["label"].upper()
19
+ score = float(result["score"])
20
+
21
+ # Low confidence β†’ treat as neutral to avoid overclaiming
22
+ if score < 0.60:
23
+ label = "NEUTRAL"
24
+
25
+ emojis = " ".join(EMOJI_MAP.get(label, ["πŸ€·β€β™‚οΈ"]))
26
+ return f"{emojis} (Confidence: {score:.2f})"
27
+
28
+ with gr.Blocks(title="Emoji Mood Classifier") as demo:
29
+ gr.Markdown(
30
+ "# Emoji Mood Classifier\n"
31
+ "A fun twist on sentiment analysis β€” returns emojis matching your text's mood."
32
+ )
33
+ inp = gr.Textbox(label="Enter text", placeholder="Type a sentence here...", lines=3)
34
+ out = gr.Textbox(label="Emoji Mood", lines=2)
35
+ btn = gr.Button("Analyze")
36
+ btn.click(analyze_mood, inputs=inp, outputs=out)
37
+
38
+ # Expose a top-level `demo` for Spaces
39
+ if __name__ == "__main__":
40
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ gradio>=4.36.1
2
+ transformers>=4.41.0
3
+ torch
runtime.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ python-3.10