File size: 813 Bytes
d53c98f
 
f402264
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import gradio as gr

from transformers import AutoModelForSequenceClassification
from transformers import TextClassificationPipeline
from transformers import AutoTokenizer

model_name = "nebiyu29/finetunned_version_2"

tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name)

classifier = TextClassificationPipeline(model=model, tokenizer=tokenizer)

def classify(text):
    result = classifier(text)[0]  # Access the first result
    return {"label": result["label"], "score": result["score"]}

iface = gr.Interface(
    fn=classify,
    inputs=[gr.Textbox(lines=2, placeholder="Enter text to classify")],
    outputs=gr.JSON(label="Classification"),
    title="Text Classification",
    live=True,  # Enable live prediction
)

iface.launch()