File size: 1,104 Bytes
621f795
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import gradio
from transformers import pipeline

username = "runaksh"
repo_name = "finetuned-sentiment-model"
repo_path = username+ '/' + repo_name
sentiment_model = pipeline(model= repo_path)

# Function for response generation
def predict_sentiment(text):
    result = sentiment_model(text)
    if result[0]['label'].endswith('0'):
        return 'Negative'
    else:
        return 'Positive'

# Input from user
in_prompt = gradio.components.Textbox(lines=10, placeholder=None, label='Enter review text')

# Output response
out_response = gradio.components.Textbox(type="text", label='Sentiment')

# Gradio interface to generate UI link
title = "Sentiment Classification"
description = "Analyse sentiment of the given review"

iface = gradio.Interface(fn = predict_sentiment,
                         inputs = [in_prompt],
                         outputs = [out_response],
                         title = title,
                         description = description)

iface.launch(debug = True)#, server_name = "0.0.0.0", server_port = 8001) # Ref. for parameters: https://www.gradio.app/docs/interface