File size: 825 Bytes
38f7c66
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch
from transformers import AutoModelForSequenceClassification, AutoTokenizer

# Load pre-trained model & tokenizer (Example: XLM-R for multilingual text classification)
model_name = "xlm-roberta-base"
tokenizer = AutoTokenizer.from_pretrained(model_name)
model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=2)

# Define prediction function
def classify_text(text):
    inputs = tokenizer(text, return_tensors="pt")
    with torch.no_grad():
        output = model(**inputs)
    label = torch.argmax(output.logits, dim=1).item()
    return "Correct" if label == 1 else "Incorrect"

# Gradio UI
gradio_app = gr.Interface(
    fn=classify_text,
    inputs=gr.Textbox(label="Enter Text"),
    outputs="text",
    title="Multi-Language RL Model"
)

gradio_app.launch()