Delete app.py
Browse files
app.py
DELETED
@@ -1,36 +0,0 @@
|
|
1 |
-
|
2 |
-
import gradio as gr
|
3 |
-
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
4 |
-
import torch
|
5 |
-
|
6 |
-
# Load tokenizer dan model dari Hugging Face Hub
|
7 |
-
model_name = "ElizabethSrgh/customer-service-multitask"
|
8 |
-
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
9 |
-
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
10 |
-
|
11 |
-
# Daftar label sesuai urutan model (ubah jika berbeda)
|
12 |
-
label_map = {
|
13 |
-
0: "Complaint - Negative",
|
14 |
-
1: "Inquiry - Neutral",
|
15 |
-
2: "Request - Positive"
|
16 |
-
}
|
17 |
-
|
18 |
-
def predict(text):
|
19 |
-
inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
|
20 |
-
with torch.no_grad():
|
21 |
-
outputs = model(**inputs)
|
22 |
-
logits = outputs.logits
|
23 |
-
predicted_class_id = torch.argmax(logits, dim=1).item()
|
24 |
-
return label_map.get(predicted_class_id, "Unknown")
|
25 |
-
|
26 |
-
# Gradio UI
|
27 |
-
interface = gr.Interface(
|
28 |
-
fn=predict,
|
29 |
-
inputs=gr.Textbox(lines=4, label="Masukkan Teks Percakapan"),
|
30 |
-
outputs=gr.Textbox(label="Hasil Prediksi"),
|
31 |
-
title="Klasifikasi Layanan Pelanggan",
|
32 |
-
description="Masukkan teks untuk memprediksi topik dan sentimen."
|
33 |
-
)
|
34 |
-
|
35 |
-
if __name__ == "__main__":
|
36 |
-
interface.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|