Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
!pip install transformers-interpret
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification, pipeline
|
| 3 |
+
from transformers_interpret import SequenceClassificationExplainer
|
| 4 |
+
model = AutoModelForSequenceClassification.from_pretrained("indobertweet-fine-tuned/pytorch_model.bin")
|
| 5 |
+
tokenizer = AutoTokenizer.from_pretrained("indolem/indobertweet-base-uncased")
|
| 6 |
+
classifier = pipeline('text-classification', model=model, tokenizer=tokenizer)
|
| 7 |
+
|
| 8 |
+
def classify(text):
|
| 9 |
+
text = text.strip().lower()
|
| 10 |
+
result = classifier(text)
|
| 11 |
+
yhat = result[0]['label']
|
| 12 |
+
return result
|
| 13 |
+
!pip install gradio
|
| 14 |
+
|
| 15 |
+
import gradio as gr
|
| 16 |
+
|
| 17 |
+
iface = gr.Interface(
|
| 18 |
+
fn=classify,
|
| 19 |
+
inputs=[
|
| 20 |
+
gr.Textbox(placeholder="Lewandowski bermain buruk sekali, Xavi benar-benar marah kepadanya", label="Enter text to classify emotions", lines=5)
|
| 21 |
+
],
|
| 22 |
+
outputs=gr.Textbox(label="Classification Result"),
|
| 23 |
+
title="🔮 Emotion Classification",
|
| 24 |
+
description="Enter a text and classify its emotions."
|
| 25 |
+
)
|
| 26 |
+
iface.launch()
|