Sa-m commited on
Commit
54ed831
1 Parent(s): 034c46e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +104 -10
app.py CHANGED
@@ -197,6 +197,109 @@ def getAnalysis(score):
197
  return 'Neutral'
198
  else:
199
  return 'Positive'
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
200
  '''
201
  url = "http://library.bjp.org/jspui/bitstream/123456789/2988/1/BJP-Election-english-2019.pdf"
202
  path_input = "./Bjp_Manifesto_2019.pdf"
@@ -241,16 +344,7 @@ def analysis(Manifesto,Search):
241
  img2 = Image.open(buf)
242
  plt.clf()
243
 
244
- wordcloud = WordCloud(max_words=2000, background_color="white",mode="RGB").generate(text_Party)
245
- plt.figure(figsize=(4,3))
246
- plt.imshow(wordcloud, interpolation="bilinear")
247
- plt.axis("off")
248
- plt.tight_layout()
249
- buf = BytesIO()
250
- plt.savefig(buf)
251
- buf.seek(0)
252
- img3 = Image.open(buf)
253
- plt.clf()
254
 
255
  fdist_Party=fDistance(text_Party)
256
  img4=fDistancePlot(text_Party)
 
197
  return 'Neutral'
198
  else:
199
  return 'Positive'
200
+ def Original_Image(path):
201
+ img= cv2.imread(path)
202
+ img= cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
203
+ return img
204
+
205
+ def Image_Processed(path):
206
+ '''
207
+ Reading the image file
208
+ '''
209
+ img= cv2.imread(path)
210
+ img= cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
211
+
212
+ #Thresholding
213
+ ret, bw_img = cv2.threshold(img, 124, 255, cv2.THRESH_BINARY)
214
+
215
+ return bw_img
216
+
217
+ def wordCloud(orgIm,mask_img,text_Party_pr,maxWord=2000,colorGener=True,contCol='white',bckColor='white'):
218
+ '''
219
+ Generating word cloud
220
+ '''
221
+
222
+ mask =mask_img
223
+ # Create and generate a word cloud image:
224
+ wordcloud = WordCloud(max_words=maxWord, background_color=bckColor,
225
+ mask=mask,
226
+ colormap='nipy_spectral_r',
227
+ contour_color=contCol,
228
+ width=400, height=500,
229
+ margin=2,
230
+ contour_width=3).generate(text_Party_pr)
231
+
232
+ # create coloring from image
233
+
234
+ plt.figure(figsize=[10,12])
235
+
236
+ if colorGener==True:
237
+ image_colors = ImageColorGenerator(orgIm)
238
+ plt.imshow(wordcloud.recolor(color_func= image_colors),interpolation="bilinear")
239
+
240
+
241
+ else:
242
+ plt.imshow(wordcloud)
243
+
244
+ plt.axis("off")
245
+
246
+ def word_cloud_generator(parsed_text_name):
247
+ parsed=parsed_text_name.lower()
248
+
249
+ if 'bjp' in parsed:
250
+ orgImg=Original_Image('BJPMain.jpg')
251
+ bwImg=Image_Processed('BJPMain.jpg')
252
+ wordCloud(orgImg,bwImg,text_Party,maxWord=3000,colorGener=True,contCol='white',bckColor='black')
253
+ plt.tight_layout()
254
+ buf = BytesIO()
255
+ plt.savefig(buf)
256
+ buf.seek(0)
257
+ img1 = Image.open(buf)
258
+ plt.clf()
259
+ return img1
260
+
261
+
262
+ elif 'congress' in parsed:
263
+ orgImg=Original_Image('congrsMain.jpg')
264
+ bwImg=Image_Processed('congrsMain.jpg')
265
+
266
+ wordCloud(orgImg,bwImg,text_Party,maxWord=3000,colorGener=True)
267
+ plt.tight_layout()
268
+ buf = BytesIO()
269
+ plt.savefig(buf)
270
+ buf.seek(0)
271
+ img2 = Image.open(buf)
272
+ plt.clf()
273
+ return img2
274
+
275
+
276
+ elif 'aap' in parsed:
277
+ orgImg=Original_Image('AAPMain.jpg')
278
+ bwImg=Image_Processed('AAPMain.jpg')
279
+ wordCloud(orgImg,bwImg,text_Party,maxWord=3000,colorGener=False,contCol='black')
280
+ plt.tight_layout()
281
+ buf = BytesIO()
282
+ plt.savefig(buf)
283
+ buf.seek(0)
284
+ img4 = Image.open(buf)
285
+ plt.clf()
286
+ return img3
287
+
288
+ else :
289
+ wordcloud = WordCloud(max_words=2000, background_color="white",mode="RGB").generate(text_Party)
290
+ plt.figure(figsize=(4,3))
291
+ plt.imshow(wordcloud, interpolation="bilinear")
292
+ plt.axis("off")
293
+ plt.tight_layout()
294
+ buf = BytesIO()
295
+ plt.savefig(buf)
296
+ buf.seek(0)
297
+ img4 = Image.open(buf)
298
+ plt.clf()
299
+ return img4
300
+
301
+
302
+
303
  '''
304
  url = "http://library.bjp.org/jspui/bitstream/123456789/2988/1/BJP-Election-english-2019.pdf"
305
  path_input = "./Bjp_Manifesto_2019.pdf"
 
344
  img2 = Image.open(buf)
345
  plt.clf()
346
 
347
+ img3 = word_cloud_generator(Manifesto.name)
 
 
 
 
 
 
 
 
 
348
 
349
  fdist_Party=fDistance(text_Party)
350
  img4=fDistancePlot(text_Party)