Update app.py
Browse files
app.py
CHANGED
|
@@ -1,3 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
from transformers import AutoModelForSequenceClassification
|
| 4 |
+
from transformers import TextClassificationPipeline
|
| 5 |
+
from transformers import AutoTokenizer
|
| 6 |
+
|
| 7 |
+
model_name = "nebiyu29/finetunned_version_2"
|
| 8 |
+
|
| 9 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 10 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name)
|
| 11 |
+
|
| 12 |
+
classifier = TextClassificationPipeline(model=model, tokenizer=tokenizer)
|
| 13 |
+
|
| 14 |
+
def classify(text):
|
| 15 |
+
result = classifier(text)[0] # Access the first result
|
| 16 |
+
return {"label": result["label"], "score": result["score"]}
|
| 17 |
+
|
| 18 |
+
iface = gr.Interface(
|
| 19 |
+
fn=classify,
|
| 20 |
+
inputs=[gr.Textbox(lines=2, placeholder="Enter text to classify")],
|
| 21 |
+
outputs=gr.JSON(label="Classification"),
|
| 22 |
+
title="Text Classification",
|
| 23 |
+
live=True, # Enable live prediction
|
| 24 |
+
)
|
| 25 |
+
|
| 26 |
+
iface.launch()
|