Skip to content

Commit

Permalink
complete wordcloud endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
noah40povis committed Jul 30, 2020
1 parent cb178a1 commit d043dd6
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 5 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@ notebooks/nb_selftext_jl.pkl
notebooks/cleaned_reduced.tsv
notebooks/reduced30k.tsv
notebooks/.ipynb_checkpoints/
reddit0.png
reddit1.png
reddit2.png
16 changes: 11 additions & 5 deletions app/api/viz.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
import pandas as pd
import plotly.express as px
import plotly.graph_objects as go
import stylecloud
from stylecloud import gen_stylecloud
import json
import base64

from .predict import Item, pred
from joblib import load
Expand Down Expand Up @@ -51,22 +53,26 @@ async def viz(postbody: Item):
return fig.to_json()


@router.post('/wordclouds'):
@router.post('/wordclouds')
async def wordclouds(postbody: Item):
"""generate word clouds
"""
df = pd.read_csv('25325_subreddits.csv')
list_in = pred(postbody, model= ns_model)['recommendations']

list_in = pred(postbody)[:3]

icons_list = ["fab fa-reddit-alien","fab fa-reddit-square","fab fa-reddit"]
data = {} #dict of serialized imgs
for i, subreddit in enumerate(list_in):
x = df[df['subreddit']== subreddit]
y = x['text'].str.cat(sep=', ')
filename = f'reddit{i}.png'
stylecloud.gen_stylecloud(text = y,
icon_name='fab fa-reddit-alien',
gen_stylecloud(text = y,
icon_name=icons_list[i],
palette='colorbrewer.diverging.Spectral_11',
background_color='black',
gradient='horizontal',
stopwords = True,
output_name=filename)


Expand Down

0 comments on commit d043dd6

Please sign in to comment.