Spaces:
Sleeping
Sleeping
update app.py
Browse files
app.py
CHANGED
|
@@ -16,7 +16,7 @@ def predict_sentiment(text):
|
|
| 16 |
encoding = tokenizer_sentiment(text, return_tensors='pt', truncation=True, padding=True, max_length=128)
|
| 17 |
output = model_sentiment(**encoding)
|
| 18 |
pred = torch.argmax(output.logits, dim=1).item()
|
| 19 |
-
sentiment_labels = ["
|
| 20 |
return sentiment_labels[pred] # Trả về nhãn cảm xúc
|
| 21 |
|
| 22 |
def predict_topic(text):
|
|
@@ -25,28 +25,23 @@ def predict_topic(text):
|
|
| 25 |
encoding = tokenizer_topic(text, return_tensors='pt', truncation=True, padding=True, max_length=128)
|
| 26 |
output = model_topic(**encoding)
|
| 27 |
pred = torch.argmax(output.logits, dim=1).item()
|
| 28 |
-
topic_labels = ["
|
| 29 |
return topic_labels[pred] # Trả về nhãn chủ đề
|
| 30 |
|
| 31 |
-
#
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
title="Sentiment Classifier",
|
| 37 |
-
description="Classify sentiment as Positive, Neutral, or Negative."
|
| 38 |
-
)
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
|
|
|
| 46 |
)
|
| 47 |
|
| 48 |
-
# Create Tabbed Interface
|
| 49 |
-
tabbed_interface = gr.TabbedInterface([iface_sentiment, iface_topic], ["Sentiment", "Topic"])
|
| 50 |
-
|
| 51 |
# Launch the app
|
| 52 |
-
|
|
|
|
| 16 |
encoding = tokenizer_sentiment(text, return_tensors='pt', truncation=True, padding=True, max_length=128)
|
| 17 |
output = model_sentiment(**encoding)
|
| 18 |
pred = torch.argmax(output.logits, dim=1).item()
|
| 19 |
+
sentiment_labels = ["Tiêu cực", "Trung lập", "Tích cực"]
|
| 20 |
return sentiment_labels[pred] # Trả về nhãn cảm xúc
|
| 21 |
|
| 22 |
def predict_topic(text):
|
|
|
|
| 25 |
encoding = tokenizer_topic(text, return_tensors='pt', truncation=True, padding=True, max_length=128)
|
| 26 |
output = model_topic(**encoding)
|
| 27 |
pred = torch.argmax(output.logits, dim=1).item()
|
| 28 |
+
topic_labels = ["Giảng viên", "Chương trình đào tạo", "Cơ sở vật chất", "Khác"]
|
| 29 |
return topic_labels[pred] # Trả về nhãn chủ đề
|
| 30 |
|
| 31 |
+
# Define a function to handle both predictions at once
|
| 32 |
+
def classify_sentiment_and_topic(text):
|
| 33 |
+
sentiment = predict_sentiment(text)
|
| 34 |
+
topic = predict_topic(text)
|
| 35 |
+
return sentiment, topic
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
# Create Gradio Interface
|
| 38 |
+
iface = gr.Interface(
|
| 39 |
+
fn=classify_sentiment_and_topic,
|
| 40 |
+
inputs=gr.Textbox(label="Enter text for Classification", placeholder="Type your text here..."),
|
| 41 |
+
outputs=[gr.Textbox(label="Sentiment Output"), gr.Textbox(label="Topic Output")],
|
| 42 |
+
title="Vietnamese students Feedback Corpus Classifier",
|
| 43 |
+
description="Classify the sentiment and topic of a given text into separate outputs."
|
| 44 |
)
|
| 45 |
|
|
|
|
|
|
|
|
|
|
| 46 |
# Launch the app
|
| 47 |
+
iface.launch()
|