Spaces:
Sleeping
Sleeping
Commit
·
03c9b66
1
Parent(s):
5aaa0c8
Initial Gradio app deployment
Browse files- app.py +34 -0
- requirements.txt +3 -0
app.py
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
|
| 4 |
+
# Load models
|
| 5 |
+
emotion_classifier = pipeline(
|
| 6 |
+
"text-classification",
|
| 7 |
+
model="bhadresh-savani/distilbert-base-uncased-emotion"
|
| 8 |
+
)
|
| 9 |
+
hate_speech_classifier = pipeline(
|
| 10 |
+
"text-classification",
|
| 11 |
+
model="Hate-speech-CNERG/dehatebert-mono-english"
|
| 12 |
+
)
|
| 13 |
+
|
| 14 |
+
def analyze_text(text):
|
| 15 |
+
emotion_result = emotion_classifier(text)
|
| 16 |
+
hate_result = hate_speech_classifier(text)
|
| 17 |
+
|
| 18 |
+
emotions = {res['label']: f"{res['score']*100:.2f}%" for res in emotion_result}
|
| 19 |
+
hate_speech = {res['label']: f"{res['score']*100:.2f}%" for res in hate_result}
|
| 20 |
+
|
| 21 |
+
return emotions, hate_speech
|
| 22 |
+
|
| 23 |
+
iface = gr.Interface(
|
| 24 |
+
fn=analyze_text,
|
| 25 |
+
inputs=gr.Textbox(lines=4, placeholder="Enter your text here..."),
|
| 26 |
+
outputs=[
|
| 27 |
+
gr.Label(num_top_classes=6, label="Emotion Detection"),
|
| 28 |
+
gr.Label(num_top_classes=3, label="Hate Speech Detection")
|
| 29 |
+
],
|
| 30 |
+
title="🧠 Emotion & Hate Speech Detector"
|
| 31 |
+
)
|
| 32 |
+
|
| 33 |
+
if __name__ == "__main__":
|
| 34 |
+
iface.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
torch
|