|
|
|
|
|
|
|
|
|
import gradio as gr |
|
from transformers import RobertaTokenizer, RobertaForSequenceClassification |
|
import torch |
|
|
|
|
|
model_name = "AnkitAI/reviews-roberta-base-sentiment-analysis" |
|
model = RobertaForSequenceClassification.from_pretrained(model_name) |
|
tokenizer = RobertaTokenizer.from_pretrained(model_name) |
|
|
|
|
|
def predict_sentiment(text): |
|
inputs = tokenizer(text, return_tensors="pt") |
|
outputs = model(**inputs) |
|
logits = outputs.logits |
|
predicted_class_id = torch.argmax(logits, dim=1).item() |
|
|
|
|
|
labels = ["Negative", "Positive"] |
|
return labels[predicted_class_id] |
|
|
|
|
|
interface = gr.Interface( |
|
fn=predict_sentiment, |
|
inputs=gr.inputs.Textbox(lines=2, placeholder="Enter a review here..."), |
|
outputs="text", |
|
title="Reviews Sentiment Analysis", |
|
description="Enter an Amazon review to see if it is positive or negative." |
|
) |
|
|
|
|
|
interface.launch() |
|
|