runaksh commited on
Commit
57424b1
1 Parent(s): 2fea6ff

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio
2
+ from transformers import pipeline
3
+
4
+ username = "yrajm1997"
5
+ repo_name = "finetuned-sentiment-model"
6
+ repo_path = username+ '/' + repo_name
7
+ sentiment_model = pipeline(model= repo_path)
8
+
9
+ # Function for response generation
10
+ def 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 user
18
+ in_prompt = gradio.components.Textbox(lines=10, placeholder=None, label='Enter review text')
19
+
20
+ # Output response
21
+ out_response = gradio.components.Textbox(type="text", label='Sentiment')
22
+
23
+ # Gradio interface to generate UI link
24
+ title = "Sentiment Classification"
25
+ description = "Analyse sentiment of the given review"
26
+
27
+ iface = gradio.Interface(fn = predict_sentiment,
28
+ inputs = [in_prompt],
29
+ outputs = [out_response],
30
+ title = title,
31
+ description = description)
32
+
33
+ iface.launch(server_name = "0.0.0.0", server_port = 8001) # Ref. for parameters: https://www.gradio.app/docs/interface