Spaces:
Runtime error
Runtime error
File size: 1,883 Bytes
bd7036e b6a86d3 09501ec bd7036e 3498231 b63ce0a 09501ec bd7036e 09501ec bd7036e b6a86d3 09501ec 03cdd3b b63ce0a 09501ec bd7036e de3e019 46f328c de3e019 bd7036e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
import gradio as gr
from transformers import pipeline
import os
import neattext.functions as nfx
import re
model = pipeline("text-classification", model="i0xs0/Emotion_Detection", tokenizer="i0xs0/Emotion_Detection")
def clean_text(text):
if not isinstance(text, str):
return text
text = nfx.remove_userhandles(text) # Remove user handles (@username)
text = nfx.remove_punctuations(text) # Remove punctuation marks (!, ?, .)
text = nfx.remove_accents(text) # Remove accents from characters (e.g., é -> e)
text = nfx.remove_urls(text) # Remove URLs (e.g., https://example.com)
text = nfx.remove_emojis(text) # Remove emojis (e.g., 😊, 🚀)
text = nfx.remove_emails(text) # Remove email addresses (e.g., user@example.com)
text = nfx.remove_phone_numbers(text) # Remove phone numbers (e.g., +1234567890)
text = nfx.remove_html_tags(text) # Remove HTML tags (<div>, <p>)
text=re.sub(r"[^a-zA-Z0-9\s']", "", text) # Remove special characters
text = nfx.remove_multiple_spaces(text) # Remove multiple spaces and reduce them to a single space
text = nfx.remove_md5sha(text) # Remove MD5 or SHA-like hash strings
return text
def predict_emotion(text):
cleaned_text = clean_text(text)
#print("Processed Text:", cleaned_text)
results = model(cleaned_text)
return {item["label"]: item["score"] for item in results}
#theme = gr.themes.Ocean()
#theme = gr.themes.Glass()
theme = gr.themes.Soft()
demo = gr.Interface(
fn=predict_emotion,
inputs=gr.Textbox(label="Input Text"),
outputs=gr.Label(label="Emotion"),
title="Emotion Classifier",
description="Enter a text to classify its emotion.",
allow_flagging="never",
theme=theme
)
demo.launch()
|