File size: 855 Bytes
5423fc0
 
 
 
74060fd
87b51f6
5423fc0
 
 
ff14db7
 
 
5423fc0
ff14db7
 
 
5423fc0
bccfe08
cc06c7b
74060fd
 
 
 
5423fc0
bccfe08
 
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
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# Load model
model_id = "Rerandaka/Cild_safety_bigbird"
tokenizer = AutoTokenizer.from_pretrained(model_id, use_fast=False)
model = AutoModelForSequenceClassification.from_pretrained(model_id)

# Inference function
def classify(text):
    inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True, max_length=512)
    with torch.no_grad():
        logits = model(**inputs).logits
        predicted_class = torch.argmax(logits, dim=1).item()
    return str(predicted_class)

# Create Gradio interface
with gr.Blocks() as demo:
    txt_in = gr.Textbox(label="Enter text")
    txt_out = gr.Textbox(label="Prediction")
    btn = gr.Button("Classify")
    btn.click(classify, txt_in, txt_out)

# Launch with API enabled
demo.launch()