abdulmatinomotoso commited on
Commit
0a6e2ba
1 Parent(s): 4633861

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -21
app.py CHANGED
@@ -2,8 +2,8 @@
2
  from transformers import BertTokenizer, BertForSequenceClassification
3
  from transformers import pipeline
4
  import gradio as gr
 
5
  import re
6
- from gradio.mix import Parallel
7
  import spacy
8
  import pandas as pd
9
 
@@ -47,30 +47,20 @@ def show_org(text):
47
  org.append(ent.text)
48
  None
49
 
50
- df = pd.DataFrame()
51
- org = org
52
- df['Organization'] = org
53
- return df
54
 
 
 
 
 
55
 
56
  sentiment_analysis = gr.Interface(
57
- fn=return_sentiment,
58
  inputs = gr.inputs.Textbox(label="Input your news article here", optional=False),
59
- outputs=gr.outputs.Textbox(label="Sentiment Analysis"),
 
60
  )
61
 
62
- named_organization = gr.Interface(
63
- fn=show_org,
64
- inputs = gr.inputs.Textbox(label="Input your news article here", optional=False),
65
- outputs=gr.outputs.Dataframe(label="Named organizations"),
66
- )
67
 
68
- Parallel(
69
- sentiment_analysis,
70
- named_organization,
71
- title="Sentiment Analysis of stock news",
72
- inputs=gr.inputs.Textbox(
73
- label="Input your article here",
74
- ),
75
- theme="darkhuggingface",
76
- ).launch(enable_queue=True, debug=True)
 
2
  from transformers import BertTokenizer, BertForSequenceClassification
3
  from transformers import pipeline
4
  import gradio as gr
5
+ from collections import Counter
6
  import re
 
7
  import spacy
8
  import pandas as pd
9
 
 
47
  org.append(ent.text)
48
  None
49
 
50
+ final = (Counter(org).most_common(1)[0][0])
 
 
 
51
 
52
+ return (f'Organization: {final}')
53
+
54
+ def final_output(text):
55
+ return return_sentiment(text), show_org(text)
56
 
57
  sentiment_analysis = gr.Interface(
58
+ final_output,
59
  inputs = gr.inputs.Textbox(label="Input your news article here", optional=False),
60
+ outputs=[gr.outputs.Textbox(label="Sentiment Analysis"),
61
+ gr.outputs.Textbox(label="Named Organization")]
62
  )
63
 
 
 
 
 
 
64
 
65
+ if __name__ == "__main__":
66
+ sentiment_analysis.launch(debug=True)