GMCTech commited on
Commit
3d8b7aa
·
verified ·
1 Parent(s): 906b416

Update app.py. App description

Browse files
Files changed (1) hide show
  1. app.py +14 -17
app.py CHANGED
@@ -2,26 +2,22 @@ import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import torch
4
 
5
- model_name = "GMCTech/LexCAT"
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
 
9
  def predict_sentiment(text):
10
  if not text.strip():
11
  return "Please enter text."
12
-
13
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128)
14
  outputs = model(**inputs)
15
  predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
16
  predicted_class = torch.argmax(predictions, dim=1).item()
17
-
18
- sentiment_map = {0: "❌ Negative", 1: "➖ Neutral", 2: "✅ Positive"}
19
  confidence = predictions[0][predicted_class].item()
20
-
21
- result = f"**Predicted Sentiment**: {sentiment_map[predicted_class]}\n"
22
- result += f"**Confidence**: {confidence:.3f}\n"
23
- result += f"\n**Raw Probabilities**:\nNegative: {predictions[0][0]:.3f}\nNeutral: {predictions[0][1]:.3f}\nPositive: {predictions[0][2]:.3f}"
24
-
25
  return result
26
 
27
  demo = gr.Interface(
@@ -29,19 +25,21 @@ demo = gr.Interface(
29
  inputs=gr.Textbox(
30
  placeholder="Type a Taglish sentence, e.g., 'Maganda pero expensive tlga'",
31
  label="Input Tagalog–English (Taglish) Text",
32
- lines=10, # ← Increased input height
33
- max_lines=20 # ← Allows expansion if needed
34
  ),
35
  outputs=gr.Textbox(
36
  label="Sentiment Prediction",
37
- lines=15, # ← Increased output height for full visibility
38
- max_lines=30 # ← Prevents forced scroll
39
  ),
40
  title="🔍 LexCAT: Taglish Sentiment Analysis",
41
  description="""
42
- **LexCAT** is a lexicon-enhanced transformer model for sentiment analysis of **Tagalog–English code-switched text (Taglish)**.
43
- Developed by Glenn Marcus D. Cinco for his BS/MS thesis at Mapúa University.
44
- Trained on FiReCS dataset, enhanced with **LexiLiksik** lexicon for intra-sentential shift detection (e.g., “Maganda pero expensive” → ❌ Negative).
 
 
45
  """,
46
  examples=[
47
  ["sobrang lambot ng burger pero expensive tlga"],
@@ -54,6 +52,5 @@ demo = gr.Interface(
54
  allow_flagging="never"
55
  )
56
 
57
- # Launch app
58
  if __name__ == "__main__":
59
  demo.launch()
 
2
  from transformers import AutoTokenizer, AutoModelForSequenceClassification
3
  import torch
4
 
5
+ model_name = "GMCTech/LexCAT"
6
  tokenizer = AutoTokenizer.from_pretrained(model_name)
7
  model = AutoModelForSequenceClassification.from_pretrained(model_name)
8
 
9
  def predict_sentiment(text):
10
  if not text.strip():
11
  return "Please enter text."
 
12
  inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=128)
13
  outputs = model(**inputs)
14
  predictions = torch.nn.functional.softmax(outputs.logits, dim=-1)
15
  predicted_class = torch.argmax(predictions, dim=1).item()
16
+ sentiment_map = {0: "NEGATIVE", 1: "NEUTRAL", 2: "POSITIVE"}
 
17
  confidence = predictions[0][predicted_class].item()
18
+ result = f"Predicted Sentiment: \n{sentiment_map[predicted_class]}\n"
19
+ result += f"Confidence: \n{confidence:.3f}\n"
20
+ result += f"\nRaw Probabilities:\nNegative: {predictions[0][0]:.3f}\nNeutral: {predictions[0][1]:.3f}\nPositive: {predictions[0][2]:.3f}"
 
 
21
  return result
22
 
23
  demo = gr.Interface(
 
25
  inputs=gr.Textbox(
26
  placeholder="Type a Taglish sentence, e.g., 'Maganda pero expensive tlga'",
27
  label="Input Tagalog–English (Taglish) Text",
28
+ lines=10,
29
+ max_lines=20
30
  ),
31
  outputs=gr.Textbox(
32
  label="Sentiment Prediction",
33
+ lines=15,
34
+ max_lines=30
35
  ),
36
  title="🔍 LexCAT: Taglish Sentiment Analysis",
37
  description="""
38
+ LexCAT is a lexicon-enhanced transformer model for sentiment analysis of Tagalog–English code-switched text (Taglish).
39
+
40
+ Developed by Glenn Marcus D. Cinco for his BS/MS thesis at Mapúa University.
41
+ • Trained on the FiReCS dataset.
42
+ • Enhanced with LexiLiksik to detect intra-sentential shifts (e.g., “Maganda pero expensive” → ❌ Negative).
43
  """,
44
  examples=[
45
  ["sobrang lambot ng burger pero expensive tlga"],
 
52
  allow_flagging="never"
53
  )
54
 
 
55
  if __name__ == "__main__":
56
  demo.launch()