|
import gradio as gr |
|
import transformers |
|
from transformers import AutoModelForSequenceClassification, AutoTokenizer |
|
import torch |
|
|
|
|
|
model = AutoModelForSequenceClassification.from_pretrained("preetidav/sentomodel") |
|
tokenizer = AutoTokenizer.from_pretrained("preetidav/sentomodel") |
|
|
|
|
|
def predict_sentiment(text): |
|
|
|
inputs = tokenizer(text, return_tensors="pt", padding=True, truncation=True) |
|
|
|
outputs = model(**inputs) |
|
|
|
prediction = torch.argmax(outputs.logits, dim=1).item() |
|
|
|
return "positive" if prediction == 1 else "negative" |
|
|
|
|
|
iface = gr.Interface( |
|
fn=predict_sentiment, |
|
inputs=gr.Textbox(label="Input Text"), |
|
outputs=gr.Textbox(label="Sentiment"), |
|
title="Sentiment Analysis Model", |
|
description="This model predicts whether a given text has positive or negative sentiment.", |
|
) |
|
|
|
|
|
iface.launch() |
|
|