Spaces:
Runtime error
Runtime error
Commit
·
1d228e3
1
Parent(s):
b20a69c
Update app.py
Browse files
app.py
CHANGED
@@ -2,7 +2,6 @@ from transformers import T5Tokenizer, T5Model, T5ForConditionalGeneration, pipel
|
|
2 |
import nltk.data
|
3 |
import pandas as pd
|
4 |
import matplotlib.pyplot as plt
|
5 |
-
from googletrans import Translator
|
6 |
from google_trans_new import google_translator
|
7 |
|
8 |
nltk.download('punkt')
|
@@ -59,8 +58,9 @@ def ner(text):
|
|
59 |
return {"text": text, "entities": output}
|
60 |
|
61 |
def sentiment_df(text):
|
62 |
-
df = pd.DataFrame(columns=['Text', 'Label', 'Score'])
|
63 |
text_list = sentence_tokenizer.tokenize(text)
|
|
|
64 |
result = [sentiment_analysis(text) for text in text_list]
|
65 |
labels = []
|
66 |
scores = []
|
@@ -69,6 +69,7 @@ def sentiment_df(text):
|
|
69 |
labels.append(list(pred.keys())[idx])
|
70 |
scores.append(round(list(pred.values())[idx], 3))
|
71 |
df['Text'] = text_list
|
|
|
72 |
df['Label'] = labels
|
73 |
df['Score'] = scores
|
74 |
return df
|
@@ -78,7 +79,8 @@ def run(text):
|
|
78 |
summ_translated = translator.transalate(summ_, lang_src='id',lang_tgt='en')
|
79 |
sent_ = sentiment_analysis(summ_translated )
|
80 |
ner_ = ner(summ_)
|
81 |
-
|
|
|
82 |
|
83 |
if __name__ == "__main__":
|
84 |
with gr.Blocks() as demo:
|
@@ -99,6 +101,12 @@ if __name__ == "__main__":
|
|
99 |
ner_output = gr.HighlightedText(label="NER Summary")
|
100 |
sent_output = gr.Label(label="Sentiment Summary")
|
101 |
|
|
|
|
|
|
|
|
|
|
|
|
|
102 |
|
103 |
analyze_button.click(run, inputs=input_text, outputs=[summ_output, sent_output, ner_output])
|
104 |
demo.launch()
|
|
|
2 |
import nltk.data
|
3 |
import pandas as pd
|
4 |
import matplotlib.pyplot as plt
|
|
|
5 |
from google_trans_new import google_translator
|
6 |
|
7 |
nltk.download('punkt')
|
|
|
58 |
return {"text": text, "entities": output}
|
59 |
|
60 |
def sentiment_df(text):
|
61 |
+
df = pd.DataFrame(columns=['Text', 'Eng', 'Label', 'Score'])
|
62 |
text_list = sentence_tokenizer.tokenize(text)
|
63 |
+
eng_text = [translator.transalate(text, lang_src='id',lang_tgt='en') for text in text_list]
|
64 |
result = [sentiment_analysis(text) for text in text_list]
|
65 |
labels = []
|
66 |
scores = []
|
|
|
69 |
labels.append(list(pred.keys())[idx])
|
70 |
scores.append(round(list(pred.values())[idx], 3))
|
71 |
df['Text'] = text_list
|
72 |
+
df['Eng'] = eng_text
|
73 |
df['Label'] = labels
|
74 |
df['Score'] = scores
|
75 |
return df
|
|
|
79 |
summ_translated = translator.transalate(summ_, lang_src='id',lang_tgt='en')
|
80 |
sent_ = sentiment_analysis(summ_translated )
|
81 |
ner_ = ner(summ_)
|
82 |
+
df_sentiment = sentiment_df(text)
|
83 |
+
return summ_, sent_, ner_, df_sentiment
|
84 |
|
85 |
if __name__ == "__main__":
|
86 |
with gr.Blocks() as demo:
|
|
|
101 |
ner_output = gr.HighlightedText(label="NER Summary")
|
102 |
sent_output = gr.Label(label="Sentiment Summary")
|
103 |
|
104 |
+
dataframe_component = gr.DataFrame(type="pandas",
|
105 |
+
label="Dataframe",
|
106 |
+
max_rows=(20,'fixed'),
|
107 |
+
overflow_row_behaviour='paginate',
|
108 |
+
wrap=True)
|
109 |
+
|
110 |
|
111 |
analyze_button.click(run, inputs=input_text, outputs=[summ_output, sent_output, ner_output])
|
112 |
demo.launch()
|