|
from __future__ import absolute_import, division, print_function, unicode_literals |
|
|
|
import os |
|
import gc |
|
import gradio as gr |
|
import pandas as pd |
|
from transformers import pipeline |
|
|
|
def huggingface_result_page(paragraph): |
|
if article.strip(): |
|
model_base = pipeline('sentiment-analysis') |
|
|
|
sen_list = paragraph |
|
sen_list = sen_list.split('\n') |
|
sen_list_temp = sen_list[0:] |
|
results = [] |
|
temp_result_dict = [] |
|
|
|
for sen in sen_list_temp: |
|
sen = sen.strip() |
|
|
|
if sen: |
|
cur_result = model_base(sen)[0] |
|
temp_result_dict.append(sen) |
|
results.append(cur_result['label']) |
|
|
|
result = { |
|
'Input': sen_list, 'Sentiment': results |
|
} |
|
print("LENGTH of results ====> ",str(len(results))) |
|
print("LENGTH of sen_list ====> ",str(len(temp_result_dict))) |
|
|
|
return pd.DataFrame(result) |
|
else: |
|
raise gr.Error("Please enter text in inputbox!!!!") |
|
|
|
|
|
inputs = gr.Textbox(lines=10, label="Paragraph") |
|
outputs = gr.Dataframe(row_count = (3, "dynamic"), col_count=(2, "fixed"), label="Here is the Result", headers=["Input","Sentiment"],wrap=True) |
|
|
|
demo = gr.Interface( |
|
huggingface_result_page, |
|
inputs, |
|
outputs, |
|
title="Huggingface Sentiment Analysis", |
|
css=".gradio-container {background-color: lightgray}", |
|
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> |
|
if you want to have your own sentiment analysis system. We will be happy to serve you for your sentiment analysis requirement. |
|
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> |
|
we are offering. |
|
<p style='text-align: center;'>Developed by :<a href="https://www.pragnakalp.com" target="_blank"> Pragnakalp Techlabs</a></p>""" |
|
) |
|
|
|
demo.launch() |