|
import gradio as gr
|
|
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
|
|
|
|
|
|
model = AutoModelForSequenceClassification.from_pretrained("MALEKSAHLIA/fine-tuned-sentiment-model-imdb")
|
|
tokenizer = AutoTokenizer.from_pretrained("MALEKSAHLIA/fine-tuned-sentiment-model-imdb")
|
|
|
|
|
|
nlp = pipeline("sentiment-analysis", model=model, tokenizer=tokenizer)
|
|
|
|
def predict_sentiment(sentence):
|
|
result = nlp(sentence)
|
|
sentiment = "Positive" if result[0]['label'] == 'LABEL_1' else "Negative"
|
|
return sentiment
|
|
|
|
iface = gr.Interface(
|
|
fn=predict_sentiment,
|
|
inputs="text",
|
|
outputs="text",
|
|
title="Sentiment Analysis",
|
|
description="Enter a sentence to get the sentiment (Positive or Negative)."
|
|
)
|
|
|
|
iface.launch()
|
|
|