new update example
Browse files
app.py
CHANGED
@@ -51,26 +51,27 @@ def classify(text):
|
|
51 |
probs_task1 = F.softmax(logits_task1, dim=1).cpu().numpy()[0] # Extract the first batch item
|
52 |
probs_task2 = F.softmax(logits_task2, dim=1).cpu().numpy()[0] # Extract the first batch item
|
53 |
|
54 |
-
#
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
# Format probabilities as percentages
|
59 |
-
probs_task1_str = ", ".join([f"{label}: {prob*100:.2f}%" for label, prob in zip(label_mapping_task1, probs_task1)])
|
60 |
-
probs_task2_str = ", ".join([f"{label}: {prob*100:.2f}%" for label, prob in zip(label_mapping_task2, probs_task2)])
|
61 |
-
|
62 |
-
# Combine label predictions with their probabilities
|
63 |
-
result_task1 = f"{pred_task1} ({probs_task1_str})"
|
64 |
-
result_task2 = f"{pred_task2} ({probs_task2_str})"
|
65 |
|
66 |
return result_task1, result_task2
|
67 |
|
68 |
-
# Gradio Interface
|
69 |
-
iface = gr.Interface(
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
|
76 |
iface.launch()
|
|
|
51 |
probs_task1 = F.softmax(logits_task1, dim=1).cpu().numpy()[0] # Extract the first batch item
|
52 |
probs_task2 = F.softmax(logits_task2, dim=1).cpu().numpy()[0] # Extract the first batch item
|
53 |
|
54 |
+
# Map probabilities to their corresponding labels
|
55 |
+
result_task1 = {label: prob for label, prob in zip(label_mapping_task1, probs_task1)}
|
56 |
+
result_task2 = {label: prob for label, prob in zip(label_mapping_task2, probs_task2)}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
57 |
|
58 |
return result_task1, result_task2
|
59 |
|
60 |
+
# Gradio Interface with percentage bars
|
61 |
+
iface = gr.Interface(
|
62 |
+
fn=classify,
|
63 |
+
inputs="text",
|
64 |
+
outputs=[
|
65 |
+
gr.outputs.Label(label="Fake Review Detection"),
|
66 |
+
gr.outputs.Label(label="Sentiment Classification")
|
67 |
+
],
|
68 |
+
title="Multitask IndoBERT: Fake Review & Sentiment Classification",
|
69 |
+
description="Enter a skincare product review in Indonesian and the model will classify it as fake or trusted, and determine the sentiment.",
|
70 |
+
examples=[
|
71 |
+
["Jokowi sangat kecewa dengan POLRI atas kerusuhan yang terjadi di Malang"],
|
72 |
+
["Lesti marah terhadap perlakuan KDRT yang dilakukan oleh Bilar"],
|
73 |
+
["Ungkapan rasa bahagia diutarakan oleh Coki Pardede karena kebebasannya dari penjara"]
|
74 |
+
]
|
75 |
+
)
|
76 |
|
77 |
iface.launch()
|