Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import torch
|
3 |
+
from transformers import AutoModelForSequenceClassification, AutoTokenizer
|
4 |
+
|
5 |
+
# Load pre-trained model & tokenizer (Example: XLM-R for multilingual text classification)
|
6 |
+
model_name = "xlm-roberta-base"
|
7 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
8 |
+
model = AutoModelForSequenceClassification.from_pretrained(model_name, num_labels=2)
|
9 |
+
|
10 |
+
# Define prediction function
|
11 |
+
def classify_text(text):
|
12 |
+
inputs = tokenizer(text, return_tensors="pt")
|
13 |
+
with torch.no_grad():
|
14 |
+
output = model(**inputs)
|
15 |
+
label = torch.argmax(output.logits, dim=1).item()
|
16 |
+
return "Correct" if label == 1 else "Incorrect"
|
17 |
+
|
18 |
+
# Gradio UI
|
19 |
+
gradio_app = gr.Interface(
|
20 |
+
fn=classify_text,
|
21 |
+
inputs=gr.Textbox(label="Enter Text"),
|
22 |
+
outputs="text",
|
23 |
+
title="Multi-Language RL Model"
|
24 |
+
)
|
25 |
+
|
26 |
+
gradio_app.launch()
|