HamidBekam's picture
Create app.py
1d68b97
raw
history blame contribute delete
919 Bytes
import gradio as gr
from transformers import pipeline, AutoModelForSequenceClassification, AutoTokenizer
# Load model and tokenizer
model_name = "nlptown/bert-base-multilingual-uncased-sentiment"
model = AutoModelForSequenceClassification.from_pretrained(model_name)
tokenizer = AutoTokenizer.from_pretrained(model_name)
# Define pipeline for sentiment analysis
classifier = pipeline('text-classification', model=model, tokenizer=tokenizer)
# Define Gradio interface
def predict_sentiment(text):
result = classifier(text)[0]
label = result['label']
score = result['score']
return f"Prediction: {label} with confidence {score}"
iface = gr.Interface(fn=predict_sentiment, inputs="text", outputs="text",
title="Sentiment Analysis with Hugging Face and Gradio",
description="Enter text to get sentiment prediction.")
# Launch Gradio interface
iface.launch()