Spaces:
Runtime error
Runtime error
wira.indra
commited on
Commit
·
1df8439
1
Parent(s):
c5f8334
add twitter feature
Browse files
app.py
CHANGED
@@ -36,6 +36,9 @@ def ner(text):
|
|
36 |
output = ner_pipeline(text)
|
37 |
return {"text": text, "entities": output}
|
38 |
|
|
|
|
|
|
|
39 |
def sentiment_df(df):
|
40 |
text_list = list(df["Text"].astype(str).values)
|
41 |
result = [sentiment_analysis(text) for text in text_list]
|
@@ -64,19 +67,29 @@ if __name__ == "__main__":
|
|
64 |
)
|
65 |
|
66 |
with gr.Tab("Single Input"):
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
)
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
# Parallel(
|
82 |
# sentiment_demo, ner_demo,
|
@@ -84,7 +97,7 @@ if __name__ == "__main__":
|
|
84 |
# examples=examples
|
85 |
# )
|
86 |
|
87 |
-
gr.InterfaceList([sentiment_demo, ner_demo])
|
88 |
|
89 |
with gr.Tab("Twitter"):
|
90 |
with gr.Blocks():
|
@@ -92,7 +105,7 @@ if __name__ == "__main__":
|
|
92 |
with gr.Column():
|
93 |
keyword_textbox = gr.Textbox(lines=1, label="Keyword")
|
94 |
max_tweets_component = gr.Number(value=10, label="Total of Tweets to Scrape", precision=0)
|
95 |
-
|
96 |
|
97 |
plot_component = gr.Plot(label="Pie Chart of Sentiments")
|
98 |
dataframe_component = gr.DataFrame(type="pandas",
|
@@ -100,7 +113,7 @@ if __name__ == "__main__":
|
|
100 |
max_rows=(20,'fixed'),
|
101 |
overflow_row_behaviour='paginate',
|
102 |
wrap=True)
|
103 |
-
|
104 |
inputs=[keyword_textbox, max_tweets_component],
|
105 |
outputs=[plot_component, dataframe_component])
|
106 |
|
|
|
36 |
output = ner_pipeline(text)
|
37 |
return {"text": text, "entities": output}
|
38 |
|
39 |
+
def sentiment_ner(text):
|
40 |
+
return(sentiment_analysis(text), ner(text))
|
41 |
+
|
42 |
def sentiment_df(df):
|
43 |
text_list = list(df["Text"].astype(str).values)
|
44 |
result = [sentiment_analysis(text) for text in text_list]
|
|
|
67 |
)
|
68 |
|
69 |
with gr.Tab("Single Input"):
|
70 |
+
with gr.Row():
|
71 |
+
with gr.Column():
|
72 |
+
input_text = gr.TextBox(label="Input Text")
|
73 |
+
analyze_button = gr.Button(label="Analyze")
|
74 |
+
with gr.Column():
|
75 |
+
sent_output = gr.TextBox(label="Sentiment Analysis")
|
76 |
+
ner_output = gr.TextBox(label="Named Entity Recognition")
|
77 |
+
|
78 |
+
analyze_button.click(sentiment_analysis, input_text, [sent_output, ner_output])
|
79 |
+
|
80 |
+
# sentiment_demo = gr.Interface(
|
81 |
+
# fn=sentiment_analysis,
|
82 |
+
# inputs="text",
|
83 |
+
# outputs="label"
|
84 |
+
# )
|
85 |
+
|
86 |
+
# ner_demo = gr.Interface(
|
87 |
+
# ner,
|
88 |
+
# "text",
|
89 |
+
# gr.HighlightedText(),
|
90 |
+
# examples=examples,
|
91 |
+
# allow_flagging='never'
|
92 |
+
# )
|
93 |
|
94 |
# Parallel(
|
95 |
# sentiment_demo, ner_demo,
|
|
|
97 |
# examples=examples
|
98 |
# )
|
99 |
|
100 |
+
# gr.InterfaceList([sentiment_demo, ner_demo])
|
101 |
|
102 |
with gr.Tab("Twitter"):
|
103 |
with gr.Blocks():
|
|
|
105 |
with gr.Column():
|
106 |
keyword_textbox = gr.Textbox(lines=1, label="Keyword")
|
107 |
max_tweets_component = gr.Number(value=10, label="Total of Tweets to Scrape", precision=0)
|
108 |
+
submit_button = gr.Button("Submit")
|
109 |
|
110 |
plot_component = gr.Plot(label="Pie Chart of Sentiments")
|
111 |
dataframe_component = gr.DataFrame(type="pandas",
|
|
|
113 |
max_rows=(20,'fixed'),
|
114 |
overflow_row_behaviour='paginate',
|
115 |
wrap=True)
|
116 |
+
submit_button.click(twitter_analyzer,
|
117 |
inputs=[keyword_textbox, max_tweets_component],
|
118 |
outputs=[plot_component, dataframe_component])
|
119 |
|