Team Ai
Apppublic

runaksh/Sentiment_Classification

sourceHugging Facemitupdated 3y agoView on Hugging Face
0likes
app.py33 linesDownload Raw Back to root
1import gradio2from transformers import pipeline3 4username = "yrajm1997"5repo_name = "finetuned-sentiment-model"6repo_path = username+ '/' + repo_name7sentiment_model = pipeline(model= repo_path)8 9# Function for response generation10def predict_sentiment(text):11    result = sentiment_model(text)12    if result[0]['label'].endswith('0'):13        return 'Negative'14    else:15        return 'Positive'16 17# Input from user18in_prompt = gradio.components.Textbox(lines=10, placeholder=None, label='Enter review text')19 20# Output response21out_response = gradio.components.Textbox(type="text", label='Sentiment')22 23# Gradio interface to generate UI link24title = "Sentiment Classification"25description = "Analyse sentiment of the given review"26 27iface = gradio.Interface(fn = predict_sentiment,28                         inputs = [in_prompt],29                         outputs = [out_response],30                         title = title,31                         description = description)32 33iface.launch(debug = True)#, server_name = "0.0.0.0", server_port = 8001) # Ref. for parameters: https://www.gradio.app/docs/interface