skmdud commited on
Commit
bc2b1b2
·
verified ·
1 Parent(s): 0a110c3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -25
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
- # Load Hugging Face models (public & documented)
7
  emotion_model = pipeline(
8
  "text-classification",
9
  model="vashuag/HindiEmotion",
10
- top_k=None
11
  )
12
 
 
13
  sentiment_model = pipeline(
14
  "text-classification",
15
- model="madhav112/hindi-sentiment-analysis",
16
- top_k=None
17
  )
18
 
19
- # Transliteration: Hinglish -> Hindi
20
  def hinglish_to_hindi(text):
21
  return transliterate(text, sanscript.ITRANS, sanscript.DEVANAGARI)
22
 
23
- # Core pipeline
24
  def analyze_text(hinglish_text):
25
- # Step 1: Convert Hinglish -> Raw Hindi
26
  raw_hindi = hinglish_to_hindi(hinglish_text)
 
27
 
28
- # Step 2: Clean Hindi (here = same, but could add preprocessing later)
29
- clean_hindi = raw_hindi
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
- "Clean Hindi": clean_hindi,
40
- "Emotion Scores": {e['label']: round(e['score'], 3) for e in emotion_scores},
41
- "Sentiment Scores": {s['label']: round(s['score'], 3) for s in sentiment_scores}
42
  }
43
 
44
- # Gradio UI
45
- demo = gr.Interface(
46
  fn=analyze_text,
47
  inputs=gr.Textbox(label="Enter Hinglish Text"),
48
  outputs="json",
49
- title="Hinglish → Hindi Emotion + Sentiment Analysis",
50
  description=(
51
- "This app converts Hinglish text into Hindi and analyzes it using two **trusted models**:\n"
52
- "- vashuag/HindiEmotion (emotions)\n"
53
- "- madhav112/hindi-sentiment-analysis (sentiment polarity)\n\n"
54
- "Both models are public, documented, and trained on reliable datasets."
55
  )
56
  )
57
 
58
  if __name__ == "__main__":
59
- demo.launch()
 
 
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
+