Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,15 +1,36 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
import os
|
|
|
|
|
|
|
| 4 |
|
| 5 |
model = pipeline("text-classification", model="i0xs0/Emotion_Detection", tokenizer="i0xs0/Emotion_Detection")
|
| 6 |
|
|
|
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
def predict_emotion(text):
|
| 10 |
|
|
|
|
|
|
|
| 11 |
|
| 12 |
-
results = model(
|
| 13 |
return {item["label"]: item["score"] for item in results}
|
| 14 |
|
| 15 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import pipeline
|
| 3 |
import os
|
| 4 |
+
import neattext.functions as nfx
|
| 5 |
+
import re
|
| 6 |
|
| 7 |
model = pipeline("text-classification", model="i0xs0/Emotion_Detection", tokenizer="i0xs0/Emotion_Detection")
|
| 8 |
|
| 9 |
+
def clean_text(text):
|
| 10 |
|
| 11 |
+
if not isinstance(text, str):
|
| 12 |
+
return text
|
| 13 |
+
|
| 14 |
+
text = nfx.remove_userhandles(text) # Remove user handles (@username)
|
| 15 |
+
text = nfx.remove_punctuations(text) # Remove punctuation marks (!, ?, .)
|
| 16 |
+
text = nfx.remove_accents(text) # Remove accents from characters (e.g., é -> e)
|
| 17 |
+
text = nfx.remove_urls(text) # Remove URLs (e.g., https://example.com)
|
| 18 |
+
text = nfx.remove_emojis(text) # Remove emojis (e.g., 😊, 🚀)
|
| 19 |
+
text = nfx.remove_emails(text) # Remove email addresses (e.g., user@example.com)
|
| 20 |
+
text = nfx.remove_phone_numbers(text) # Remove phone numbers (e.g., +1234567890)
|
| 21 |
+
text = nfx.remove_html_tags(text) # Remove HTML tags (<div>, <p>)
|
| 22 |
+
text=re.sub(r"[^a-zA-Z0-9\s']", "", text) # Remove special characters
|
| 23 |
+
text = nfx.remove_multiple_spaces(text) # Remove multiple spaces and reduce them to a single space
|
| 24 |
+
text = nfx.remove_md5sha(text) # Remove MD5 or SHA-like hash strings
|
| 25 |
+
|
| 26 |
+
return text
|
| 27 |
|
| 28 |
def predict_emotion(text):
|
| 29 |
|
| 30 |
+
cleaned_text = clean_text(text)
|
| 31 |
+
print("Processed Text:", cleaned_text)
|
| 32 |
|
| 33 |
+
results = model(cleaned_text)
|
| 34 |
return {item["label"]: item["score"] for item in results}
|
| 35 |
|
| 36 |
|