pragnakalp commited on
Commit
db40a0b
·
1 Parent(s): aebc3f2

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +54 -0
app.py ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from __future__ import absolute_import, division, print_function, unicode_literals
2
+
3
+ import os
4
+ import gc
5
+ import gradio as gr
6
+ import pandas as pd
7
+ from transformers import pipeline
8
+
9
+ def huggingface_result_page(paragraph):
10
+ if article.strip():
11
+ model_base = pipeline('sentiment-analysis')
12
+
13
+ sen_list = paragraph
14
+ sen_list = sen_list.split('\n')
15
+ sen_list_temp = sen_list[0:]
16
+ results = []
17
+ temp_result_dict = []
18
+
19
+ for sen in sen_list_temp:
20
+ sen = sen.strip()
21
+
22
+ if sen:
23
+ cur_result = model_base(sen)[0]
24
+ temp_result_dict.append(sen)
25
+ results.append(cur_result['label'])
26
+
27
+ result = {
28
+ 'Input': sen_list, 'Sentiment': results
29
+ }
30
+ print("LENGTH of results ====> ",str(len(results)))
31
+ print("LENGTH of sen_list ====> ",str(len(temp_result_dict)))
32
+
33
+ return pd.DataFrame(result)
34
+ else:
35
+ raise gr.Error("Please enter text in inputbox!!!!")
36
+
37
+
38
+ inputs = gr.Textbox(lines=10, label="Paragraph")
39
+ outputs = gr.Dataframe(row_count = (3, "dynamic"), col_count=(2, "fixed"), label="Here is the Result", headers=["Input","Sentiment"],wrap=True)
40
+
41
+ demo = gr.Interface(
42
+ huggingface_result_page,
43
+ inputs,
44
+ outputs,
45
+ title="Huggingface Sentiment Analysis",
46
+ css=".gradio-container {background-color: lightgray}",
47
+ article = """Provide us your feedback on this demo and feel free to contact us at <a href="mailto:[email protected]" target="_blank">[email protected]</a>
48
+ if you want to have your own sentiment analysis system. We will be happy to serve you for your sentiment analysis requirement.
49
+ And don't forget to check out more interesting <a href="https://www.pragnakalp.com/services/natural-language-processing-services/" target="_blank">NLP services</a>
50
+ we are offering.
51
+ <p style='text-align: center;'>Developed by :<a href="https://www.pragnakalp.com" target="_blank"> Pragnakalp Techlabs</a></p>"""
52
+ )
53
+
54
+ demo.launch()