File size: 937 Bytes
1c8f4b1
 
9e84c8b
1c8f4b1
 
 
5423fc0
 
 
9e84c8b
ff14db7
 
5423fc0
ff14db7
9e84c8b
 
5423fc0
9e84c8b
76eebae
 
9e84c8b
 
 
76eebae
5423fc0
1c8f4b1
 
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
28
import gradio as gr
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification

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

# Classification 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
        prediction = torch.argmax(logits, dim=1).item()
    return prediction  # 0 = safe, 1 = unsafe

# βœ… API-compatible Interface with explicit name
demo = gr.Interface(
    fn=classify,
    inputs=gr.Textbox(label="Enter paragraph..."),
    outputs=gr.Number(label="Prediction (0=safe, 1=unsafe)"),
    api_name="/classify"  # πŸ”₯ This only works in gr.Interface (not Blocks)
)

demo.queue()
demo.launch(show_api=True)