-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #11 from ninabina921/master
Add Wordcloud and Table for Demo Output UI
- Loading branch information
Showing
12 changed files
with
155 additions
and
95 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
__pycache__/app.cpython-38.pyc | ||
app.py | ||
predict_tweets/__pycache__/predictedData.cpython-38.pyc | ||
twint_integrate/__pycache__/twint_search.cpython-38.pyc | ||
twint_wordcloud/__pycache__/wordcloud_html.cpython-38.pyc | ||
twint_integrate/__pycache__/__init__.cpython-38.pyc | ||
predict_tweets/__pycache__/model.cpython-38.pyc | ||
__pycache__/app.cpython-38.pyc | ||
userTweets.csv | ||
.gitignore | ||
predictedTweets.csv |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
FROM python:3.8-slim-buster | ||
# Set the working directory to /app | ||
WORKDIR /app | ||
|
||
# copy the requirements file used for dependencies | ||
COPY requirements.txt . | ||
|
||
# Install any needed packages specified in requirements.txt | ||
RUN pip install --trusted-host pypi.python.org -r requirements.txt | ||
|
||
# Copy the rest of the working directory contents into the container at /app | ||
COPY . . | ||
|
||
# Run app.py when the container launches | ||
ENTRYPOINT ["python", "app.py"] | ||
# WORKDIR /python-docker | ||
|
||
# COPY requirements.txt requirements.txt | ||
# RUN pip3 install -r requirements.txt | ||
# COPY . . | ||
|
||
# CMD [ "python3", "-m" , "flask", "run", "--host=0.0.0.0"] |
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# importing pandas as pd | ||
import pandas as pd | ||
|
||
def predictedTweets(csv): | ||
with open(csv, encoding="utf8", errors='ignore') as f: | ||
df = pd.read_csv(f) | ||
# Get Values for Prediction Results | ||
print("Shape", df.shape) | ||
cols = ["username", "tweet", "label"] | ||
df_small = df[cols] | ||
df_small = df_small[df_small["label"] == 1] | ||
|
||
# Misinformation Dict for Data | ||
prediction_data = {} | ||
|
||
prediction_data['misinfo'] = df_small.shape[0] | ||
prediction_data['handle'] = df["username"][0] | ||
|
||
# print(df_small) | ||
|
||
return prediction_data, df_small |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Flask==2.0.2 | ||
matplotlib==3.5.1 | ||
numpy==1.22.2 | ||
pandas==1.4.1 | ||
Pillow==9.0.1 | ||
scikit_learn==1.0.2 | ||
torch==1.10.2 | ||
transformers==4.17.0 | ||
wordcloud==1.8.1 | ||
git+https://github.com/twintproject/twint.git@origin/master#egg=twint | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from sqlite3 import Row | ||
from wordcloud import WordCloud | ||
import pandas as pd | ||
from PIL import Image | ||
import matplotlib.pyplot as plt | ||
import io | ||
import urllib | ||
import base64 | ||
import re | ||
|
||
def word_cloud(csv): | ||
with open(csv, encoding="utf8", errors='ignore') as f: | ||
df = pd.read_csv(f) | ||
if df.shape[0] == 0: | ||
return '../static/img/404.png' | ||
else: | ||
df['content'] = df['tweet'].apply(lambda x: re.split('https:\/\/.*', str(x))[0]) | ||
row_count = df.shape[0] | ||
txt = ' '.join(df['content']) | ||
wc = WordCloud(width = 400, height = 200, random_state=1, background_color='black', colormap='Pastel1', collocations=False).generate(txt) | ||
buffer = io.BytesIO() | ||
wc.to_image().save(buffer, 'png') | ||
b64 = base64.b64encode(buffer.getvalue()) | ||
image_64 = 'data:image/png;base64,' + urllib.parse.quote(b64) | ||
return image_64, row_count |