kkastr commited on
Commit
62984a8
1 Parent(s): a0489ac

mirroring change from main. added wordcloud

Browse files
Files changed (2) hide show
  1. README.md +1 -1
  2. app.py +16 -3
README.md CHANGED
@@ -4,7 +4,7 @@ colorFrom: green
4
  colorTo: blue
5
  sdk: gradio
6
  sdk_version: 3.19.1
7
- python_version: 3.11.0
8
  app_file: app.py
9
  pinned: false
10
  ---
 
4
  colorTo: blue
5
  sdk: gradio
6
  sdk_version: 3.19.1
7
+ python_version: 3.10.4
8
  app_file: app.py
9
  pinned: false
10
  ---
app.py CHANGED
@@ -6,6 +6,8 @@ import praw
6
  import gradio as gr
7
  import pandas as pd
8
  import praw.exceptions
 
 
9
  from transformers import pipeline
10
 
11
 
@@ -119,9 +121,18 @@ def summarizer(url: str) -> str:
119
  # pushshift.io submission comments api doesn't work so have to use praw
120
  df = getComments(url=url)
121
  chunked_df = preprocessData(df)
122
-
123
  submission_title = df.submission_title.unique()[0]
124
 
 
 
 
 
 
 
 
 
 
 
125
  lst_summaries = []
126
 
127
  nlp = pipeline('summarization', model="sshleifer/distilbart-cnn-12-6")
@@ -151,11 +162,13 @@ if __name__ == "__main__":
151
 
152
  with gr.Row():
153
  short_summary = gr.Textbox(label='Short Summary')
154
- long_summary = gr.Textbox(label='Long Summary')
 
 
155
 
156
  sub_btn.click(fn=summarizer,
157
  inputs=[submission_url],
158
- outputs=[short_summary, long_summary])
159
 
160
  try:
161
  demo.launch()
 
6
  import gradio as gr
7
  import pandas as pd
8
  import praw.exceptions
9
+ import matplotlib.pyplot as plt
10
+ from wordcloud import WordCloud
11
  from transformers import pipeline
12
 
13
 
 
121
  # pushshift.io submission comments api doesn't work so have to use praw
122
  df = getComments(url=url)
123
  chunked_df = preprocessData(df)
 
124
  submission_title = df.submission_title.unique()[0]
125
 
126
+ text = ' '.join(chunked_df)
127
+ # transparent bg: background_color=None, mode='RGBA'
128
+ wc_opts = dict(collocations=False, width=1920, height=1080)
129
+ wcloud = WordCloud(**wc_opts).generate(text)
130
+
131
+ fig = plt.figure(figsize=(12, 7))
132
+ fig.patch.set_alpha(0.0)
133
+ plt.imshow(wcloud)
134
+ plt.axis("off")
135
+ plt.tight_layout()
136
  lst_summaries = []
137
 
138
  nlp = pipeline('summarization', model="sshleifer/distilbart-cnn-12-6")
 
162
 
163
  with gr.Row():
164
  short_summary = gr.Textbox(label='Short Summary')
165
+ thread_cloud = gr.Plot(label='Word Cloud')
166
+
167
+ long_summary = gr.Textbox(label='Long Summary')
168
 
169
  sub_btn.click(fn=summarizer,
170
  inputs=[submission_url],
171
+ outputs=[short_summary, long_summary, thread_cloud])
172
 
173
  try:
174
  demo.launch()