File size: 944 Bytes
060541a 244b584 56cb03d 060541a 56cb03d 060541a 6f74060 060541a c480dfd 060541a 56cb03d 244b584 060541a 6f74060 060541a 6f74060 244b584 |
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 29 30 31 |
import torch
from transformers import pipeline
import gradio as gr
import pandas as pd
from datasets import Dataset
# Enable SafeTensors if available
if torch.__version__ >= "1.10":
torch.set_safety_enabled(True)
# Load the model
model_nm = 'microsoft/deberta-v3-small'
classifier = pipeline("text-classification", model=model_nm)
# Read and preprocess data
df = pd.read_csv("path/to/train.csv") # Replace "path/to/train.csv" with the actual path
df.describe(include='object')
df['input'] = 'TEXT1: ' + df.context + '; TEXT2: ' + df.target + '; ANC1: ' + df.anchor
ds = Dataset.from_pandas(df)
# Define prediction function
def predict_text(input_text):
prediction = classifier(input_text)
return prediction
# Define Gradio interface
text_input = gr.inputs.Textbox(lines=7, label="Unesite tekst")
output_text = gr.outputs.Textbox(label="Predikcija")
gr.Interface(predict_text, inputs=text_input, outputs=output_text).launch()
|