From 141cd4cb35beda8cf4cd3425e85759c362a404b1 Mon Sep 17 00:00:00 2001 From: Preetham Kamidi Date: Wed, 12 Jun 2019 23:52:09 +0530 Subject: [PATCH 1/5] Update: Dockerization of backend service Signed-off-by: Preetham Kamidi --- .dockerignore | 4 ++++ Dockerfile | 28 ++++++++++++++++++++++++++++ entrypoint.sh | 3 +++ 3 files changed, 35 insertions(+) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100755 entrypoint.sh diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..2932066 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,4 @@ +.vscode +venv +dataset +.DS_Store \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..2f21f21 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,28 @@ +FROM centos:latest +LABEL author "Preetham Kamidi " +ENV PYTHON_VERSION=3.6 \ + PATH=$HOME/.local/bin/:$PATH \ + PYTHONUNBUFFERED=1 \ + PYTHONIOENCODING=UTF-8 \ + LC_ALL=en_US.UTF-8 \ + LANG=en_US.UTF-8 \ + PIP_NO_CACHE_DIR=off +RUN yum-config-manager --add-repo https://download.opensuse.org/repositories/home:/Alexander_Pozdnyakov/CentOS_7/ && \ + rpm --import https://build.opensuse.org/projects/home:Alexander_Pozdnyakov/public_key && \ + INSTALL_PKGS="rh-python36 rh-python36-python-devel rh-python36-python-setuptools \ + rh-python36-python-pip tesseract tesseract-langpack-deu ImageMagick ImageMagick-devel" && \ + yum update -y && \ + yum groupinstall 'Development Tools' -y && \ + yum install -y centos-release-scl && \ + yum -y --setopt=tsflags=nodocs install --enablerepo=centosplus $INSTALL_PKGS && \ + rpm -V $INSTALL_PKGS && \ + yum -y clean all --enablerepo='*' +WORKDIR /app +COPY . . +RUN source scl_source enable rh-python36 && \ + mkdir -p /data/files && \ + virtualenv venv -p python3 && \ + source venv/bin/activate && \ + pip install --upgrade pip && \ + pip install -r requirements.txt +ENTRYPOINT [ "entrypoint.sh" ] \ No newline at end of file diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100755 index 0000000..8f0ce87 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,3 @@ +#!/bin/bash +source venv/bin/activate +python wsgi.py \ No newline at end of file From aed8f2416f790ca8c9b27add88811aff03837e42 Mon Sep 17 00:00:00 2001 From: Preetham Kamidi Date: Thu, 13 Jun 2019 01:18:39 +0530 Subject: [PATCH 2/5] fix: Docker entrypoint Signed-off-by: Preetham Kamidi --- Dockerfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Dockerfile b/Dockerfile index 2f21f21..071561b 100644 --- a/Dockerfile +++ b/Dockerfile @@ -25,4 +25,4 @@ RUN source scl_source enable rh-python36 && \ source venv/bin/activate && \ pip install --upgrade pip && \ pip install -r requirements.txt -ENTRYPOINT [ "entrypoint.sh" ] \ No newline at end of file +ENTRYPOINT ["/app/entrypoint.sh"] \ No newline at end of file From 0e9bcf2791881fe5471ec20f62089b23d7aa1f0c Mon Sep 17 00:00:00 2001 From: Preetham Kamidi Date: Tue, 18 Jun 2019 14:41:55 +0530 Subject: [PATCH 3/5] Update: Change Base Docker image to python Signed-off-by: Preetham Kamidi --- Dockerfile | 27 +++++---------------------- app/config/config.py | 1 + app/router.py | 1 + 3 files changed, 7 insertions(+), 22 deletions(-) diff --git a/Dockerfile b/Dockerfile index 071561b..b35fc61 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,28 +1,11 @@ -FROM centos:latest +FROM python:3.7.3-stretch LABEL author "Preetham Kamidi " -ENV PYTHON_VERSION=3.6 \ - PATH=$HOME/.local/bin/:$PATH \ - PYTHONUNBUFFERED=1 \ - PYTHONIOENCODING=UTF-8 \ - LC_ALL=en_US.UTF-8 \ - LANG=en_US.UTF-8 \ - PIP_NO_CACHE_DIR=off -RUN yum-config-manager --add-repo https://download.opensuse.org/repositories/home:/Alexander_Pozdnyakov/CentOS_7/ && \ - rpm --import https://build.opensuse.org/projects/home:Alexander_Pozdnyakov/public_key && \ - INSTALL_PKGS="rh-python36 rh-python36-python-devel rh-python36-python-setuptools \ - rh-python36-python-pip tesseract tesseract-langpack-deu ImageMagick ImageMagick-devel" && \ - yum update -y && \ - yum groupinstall 'Development Tools' -y && \ - yum install -y centos-release-scl && \ - yum -y --setopt=tsflags=nodocs install --enablerepo=centosplus $INSTALL_PKGS && \ - rpm -V $INSTALL_PKGS && \ - yum -y clean all --enablerepo='*' +RUN apt-get update && apt-get install -y tesseract-ocr libtesseract-dev WORKDIR /app COPY . . -RUN source scl_source enable rh-python36 && \ - mkdir -p /data/files && \ +RUN mkdir -p /data/files && \ + pip install virtualenv && \ virtualenv venv -p python3 && \ - source venv/bin/activate && \ - pip install --upgrade pip && \ + . venv/bin/activate && \ pip install -r requirements.txt ENTRYPOINT ["/app/entrypoint.sh"] \ No newline at end of file diff --git a/app/config/config.py b/app/config/config.py index 59c0173..b1fcf17 100644 --- a/app/config/config.py +++ b/app/config/config.py @@ -9,6 +9,7 @@ class Config(object): APP_HOST = os.getenv('APP_HOST') APP_PORT = os.getenv('APP_PORT') TIMEOUT = os.getenv('TIMEOUT') + MAX_CONTENT_LENGTH = os.getenv('MAX_CONTENT_LENGTH') TESSERACT_PATH = os.getenv('TESSERACT_PATH') IMAGEMAGICK_PATH = os.getenv('IMAGEMAGICK_PATH') UPSCALE_PERCENTAGE = os.getenv('UPSCALE_PERCENTAGE') diff --git a/app/router.py b/app/router.py index e311d17..07e0e6b 100644 --- a/app/router.py +++ b/app/router.py @@ -11,6 +11,7 @@ from app.config.config import app_config app_router = Flask(__name__, static_folder=app_config.FILE_DIRECTORY) +app_router.config['MAX_CONTENT_LENGTH'] = app_config.MAX_CONTENT_LENGTH @app_router.route('/health', methods=['GET']) From d9faca01bc22f444530f0e6b7fc1941fe19ef8fc Mon Sep 17 00:00:00 2001 From: Preetham Kamidi Date: Tue, 18 Jun 2019 15:47:12 +0530 Subject: [PATCH 4/5] Update: README Signed-off-by: Preetham Kamidi --- README.md | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 4b779d8..dfc0a6b 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,17 @@ -# verifytweet -Verify Tweet from Image +# Verify Tweet + +Fake tweet images can be generated using a preset meme template from websites like: [TweetGen](https://www.tweetgen.com/), [Prank Me Not](http://www.prankmenot.com/?twitter_tweet) and [Simitator](http://simitator.com/generator/twitter/tweet) . Verification of such tweets takes a manual work to find the user, scroll through their timeline and matching. A viral fake tweet image can prove crucial at a time. + +A fake tweet screenshot looks very convincing, misleading the general public. For example: + +|Tweet 1 | Tweet 2 | +|:-------------------------:|:-------------------------:| +|![alt text](https://i.imgur.com/gG1RYiR.png "Tweet 1") | ![alt text](https://i.imgur.com/eTKpOFY.png "Tweet 2")| + +Verify Tweet attempts to resolve the problem by letting users upload such tweet screenshots and verify if the user actually tweeted or not. A combination of Image processing, Natural language processing as well as Twitter Search API makes this possible. Due to Twitter API rate limits, currently only tweets from last 7 days can be verified. + +## Future features + +- [ ] Support for Image links +- [ ] Processing Status +- [ ] Support for Tweets with replies \ No newline at end of file From 784ddb97375f2dab34fc0c33bd0d99b972d6e68b Mon Sep 17 00:00:00 2001 From: Preetham Kamidi Date: Thu, 20 Jun 2019 20:13:32 +0530 Subject: [PATCH 5/5] fix: CORS support for APIs Signed-off-by: Preetham Kamidi --- Dockerfile | 10 +++++----- app/config/config.py | 2 +- app/logger/logger.py | 2 +- app/router.py | 2 ++ 4 files changed, 9 insertions(+), 7 deletions(-) diff --git a/Dockerfile b/Dockerfile index b35fc61..f278f9a 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,11 @@ -FROM python:3.7.3-stretch +FROM ubuntu:18.04 LABEL author "Preetham Kamidi " -RUN apt-get update && apt-get install -y tesseract-ocr libtesseract-dev +RUN apt-get update && apt-get install -y python3-dev python3-pip imagemagick tesseract-ocr libtesseract-dev WORKDIR /app COPY . . RUN mkdir -p /data/files && \ - pip install virtualenv && \ - virtualenv venv -p python3 && \ + pip3 install virtualenv && \ + python3 -m virtualenv venv -p python3 && \ . venv/bin/activate && \ pip install -r requirements.txt -ENTRYPOINT ["/app/entrypoint.sh"] \ No newline at end of file +ENTRYPOINT ["/app/entrypoint.sh"] diff --git a/app/config/config.py b/app/config/config.py index b1fcf17..c7c479a 100644 --- a/app/config/config.py +++ b/app/config/config.py @@ -9,7 +9,7 @@ class Config(object): APP_HOST = os.getenv('APP_HOST') APP_PORT = os.getenv('APP_PORT') TIMEOUT = os.getenv('TIMEOUT') - MAX_CONTENT_LENGTH = os.getenv('MAX_CONTENT_LENGTH') + MAX_CONTENT_LENGTH = int(os.getenv('MAX_CONTENT_LENGTH')) TESSERACT_PATH = os.getenv('TESSERACT_PATH') IMAGEMAGICK_PATH = os.getenv('IMAGEMAGICK_PATH') UPSCALE_PERCENTAGE = os.getenv('UPSCALE_PERCENTAGE') diff --git a/app/logger/logger.py b/app/logger/logger.py index 9d3d6fb..c6f11a0 100644 --- a/app/logger/logger.py +++ b/app/logger/logger.py @@ -5,6 +5,6 @@ root.setLevel(logger.DEBUG) handler = logger.StreamHandler(sys.stdout) handler.setLevel(logger.DEBUG) -formatter = logger.Formatter('%(asctime)s -- %(levelname)s -- %(message)s') +formatter = logger.Formatter(u'%(asctime)s -- %(levelname)s -- %(message)s') handler.setFormatter(formatter) root.addHandler(handler) diff --git a/app/router.py b/app/router.py index 07e0e6b..e15557a 100644 --- a/app/router.py +++ b/app/router.py @@ -2,6 +2,7 @@ import traceback from flask import Flask, jsonify, request +from flask_cors import CORS from app.logger.logger import logger from app.services.image import uploader, processor @@ -12,6 +13,7 @@ app_router = Flask(__name__, static_folder=app_config.FILE_DIRECTORY) app_router.config['MAX_CONTENT_LENGTH'] = app_config.MAX_CONTENT_LENGTH +CORS(app_router) @app_router.route('/health', methods=['GET'])