Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -3,57 +3,52 @@ from transformers import pipeline
|
|
3 |
from indic_transliteration import sanscript
|
4 |
from indic_transliteration.sanscript import transliterate
|
5 |
|
6 |
-
#
|
7 |
emotion_model = pipeline(
|
8 |
"text-classification",
|
9 |
model="vashuag/HindiEmotion",
|
10 |
-
|
11 |
)
|
12 |
|
|
|
13 |
sentiment_model = pipeline(
|
14 |
"text-classification",
|
15 |
-
model="
|
16 |
-
|
17 |
)
|
18 |
|
19 |
-
#
|
20 |
def hinglish_to_hindi(text):
|
21 |
return transliterate(text, sanscript.ITRANS, sanscript.DEVANAGARI)
|
22 |
|
23 |
-
#
|
24 |
def analyze_text(hinglish_text):
|
25 |
-
# Step 1: Convert Hinglish -> Raw Hindi
|
26 |
raw_hindi = hinglish_to_hindi(hinglish_text)
|
|
|
27 |
|
28 |
-
|
29 |
-
|
30 |
|
31 |
-
# Step 3: Run models
|
32 |
-
emotion_scores = emotion_model(clean_hindi)[0]
|
33 |
-
sentiment_scores = sentiment_model(clean_hindi)[0]
|
34 |
-
|
35 |
-
# Format nicely
|
36 |
return {
|
37 |
"Hinglish Input": hinglish_text,
|
38 |
"Raw Hindi": raw_hindi,
|
39 |
-
"
|
40 |
-
"
|
41 |
-
"Sentiment Scores": {s['label']: round(s['score'], 3) for s in sentiment_scores}
|
42 |
}
|
43 |
|
44 |
-
|
45 |
-
demo = gr.Interface(
|
46 |
fn=analyze_text,
|
47 |
inputs=gr.Textbox(label="Enter Hinglish Text"),
|
48 |
outputs="json",
|
49 |
-
title="Hinglish → Hindi Emotion
|
50 |
description=(
|
51 |
-
"This app
|
52 |
-
"- vashuag/HindiEmotion
|
53 |
-
"-
|
54 |
-
"Both
|
55 |
)
|
56 |
)
|
57 |
|
58 |
if __name__ == "__main__":
|
59 |
-
|
|
|
|
3 |
from indic_transliteration import sanscript
|
4 |
from indic_transliteration.sanscript import transliterate
|
5 |
|
6 |
+
# Emotion Model
|
7 |
emotion_model = pipeline(
|
8 |
"text-classification",
|
9 |
model="vashuag/HindiEmotion",
|
10 |
+
return_all_scores=True
|
11 |
)
|
12 |
|
13 |
+
# Sentiment Model
|
14 |
sentiment_model = pipeline(
|
15 |
"text-classification",
|
16 |
+
model="LondonStory/txlm-roberta-hindi-sentiment",
|
17 |
+
return_all_scores=True
|
18 |
)
|
19 |
|
20 |
+
# Transliterate Hinglish → Hindi
|
21 |
def hinglish_to_hindi(text):
|
22 |
return transliterate(text, sanscript.ITRANS, sanscript.DEVANAGARI)
|
23 |
|
24 |
+
# Full Pipeline
|
25 |
def analyze_text(hinglish_text):
|
|
|
26 |
raw_hindi = hinglish_to_hindi(hinglish_text)
|
27 |
+
clean_hindi = raw_hindi # Can insert normalization if needed
|
28 |
|
29 |
+
emotions = emotion_model(clean_hindi)[0]
|
30 |
+
sentiments = sentiment_model(clean_hindi)[0]
|
31 |
|
|
|
|
|
|
|
|
|
|
|
32 |
return {
|
33 |
"Hinglish Input": hinglish_text,
|
34 |
"Raw Hindi": raw_hindi,
|
35 |
+
"Emotion Scores": {e["label"]: round(e["score"], 3) for e in emotions},
|
36 |
+
"Sentiment Scores": {s["label"]: round(s["score"], 3) for s in sentiments}
|
|
|
37 |
}
|
38 |
|
39 |
+
iface = gr.Interface(
|
|
|
40 |
fn=analyze_text,
|
41 |
inputs=gr.Textbox(label="Enter Hinglish Text"),
|
42 |
outputs="json",
|
43 |
+
title="Hinglish → Hindi Emotion & Sentiment Analyzer",
|
44 |
description=(
|
45 |
+
"This app uses **documented and public models**:\n"
|
46 |
+
"- **vashuag/HindiEmotion** for emotion classification\n"
|
47 |
+
"- **LondonStory/txlm-roberta-hindi-sentiment** for sentiment (3-class)\n"
|
48 |
+
"Both are transparent, reliable, and well-evaluated on Hindi data."
|
49 |
)
|
50 |
)
|
51 |
|
52 |
if __name__ == "__main__":
|
53 |
+
iface.launch()
|
54 |
+
|