File size: 811 Bytes
81b935b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import gradio as gr
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch

model_path = "./models/fine_tuned_xlm_roberta_quantized"
model = AutoModelForSequenceClassification.from_pretrained(model_path)
tokenizer = AutoTokenizer.from_pretrained(model_path)

def classify_text(text):
    inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
    outputs = model(**inputs)
    prediction = torch.argmax(outputs.logits, dim=1).item()
    label = "Correct" if prediction == 1 else "Incorrect"
    return label

iface = gr.Interface(fn=classify_text, 
                     inputs="text", 
                     outputs="text",
                     title="Multi-Language RL Text Classifier")

if __name__ == "__main__":
    iface.launch()