Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
  • Loading branch information
aditirao7 authored Sep 26, 2021
1 parent 8fc47a1 commit b73db81
Show file tree
Hide file tree
Showing 15 changed files with 1,097 additions and 0 deletions.
7 changes: 7 additions & 0 deletions shellhacks/Aptfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
libsm6
libxrender1
libfontconfig1
libice6
tesseract-ocr
tesseract-ocr-eng
tesseract-ocr-deu
1 change: 1 addition & 0 deletions shellhacks/Procfile
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
web: gunicorn app:app
Binary file added shellhacks/__pycache__/app.cpython-36.pyc
Binary file not shown.
93 changes: 93 additions & 0 deletions shellhacks/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
import string
import re
import json
import os
from flask import Flask, flash, render_template, redirect, request, session, make_response, session, redirect, url_for, send_from_directory
import requests
import os
import numpy as np
import pandas as pd
import pytesseract
import cv2
from werkzeug.utils import secure_filename
#from autoscraper import AutoScraper

app = Flask(__name__)
app.config['UPLOAD_FOLDER'] = 'static/uploads/'
app.config['MAX_CONTENT_LENGTH'] = 16 * 1024 * 1024
app.secret_key = os.environ.get('APP_SECRET_KEY')

ALLOWED_EXTENSIONS = set(['png', 'jpg', 'jpeg', 'gif'])

sustainable = ['cotton', 'linen', 'silk', 'wool', 'bamboo', 'hemp',
'lyocell', 'nylon', 'rubber', 'cashmere', 'cupro', 'denim']

non_sustainable = ['leather', 'rayon', 'viscose', 'polyester',
'elastane', 'elasthane', 'spandex', 'chiffon', 'acrylic', 'georgette']


def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS


@app.route('/')
def upload_form():
return render_template('upload.html')


@app.route('/about')
def about():
return render_template('about.html')


@app.route('/sustainability')
def why():
return render_template('why.html')


@app.route('/', methods=['POST'])
def upload_image():
website = request.form['text']
'''if website:
scraper = AutoScraper()
sus = scraper.build(website, sustainable)
nsus = scraper.build(website, non_sustainable)
print(sus, nsus)
else:
print(No Info)'''
if 'file' not in request.files:
return render_template('upload.html', flash="No file part")
file = request.files['file']
if file.filename == '':
return render_template('upload.html', flash='No image selected for uploading')
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
path = os.path.join(app.config['UPLOAD_FOLDER'], filename)
file.save(path)
image = cv2.imread(path)
image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
#pytesseract.pytesseract.tesseract_cmd = '/app/.apt/usr/bin/tesseract'
text = pytesseract.image_to_string(image)
os.remove(path)
lst = list(text.lower().strip().split())
s = []
ns = []
for l in lst:
if l in sustainable:
s.append(l)
elif l in non_sustainable:
ns.append(l)
ty = -2
if len(s) > len(ns):
ty = 1
elif len(s) < len(ns):
ty = -1
elif len(s) == len(ns) and len(s) > 0:
ty = 0
return render_template('analysis.html', s=s, ns=ns, type=ty)
else:
return render_template('upload.html', flash='Allowed image types are png, jpg, jpeg, gif')


if __name__ == '__main__':
app.run(debug=True, port=5500)
7 changes: 7 additions & 0 deletions shellhacks/requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
requests==2.25.1
Flask==2.0.1
numpy==1.21.0
pandas==1.3.0
gunicorn==20.1.0
opencv-python-headless==4.5.3.56
pytesseract==0.3.8
Loading

0 comments on commit b73db81

Please sign in to comment.