-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
52 lines (33 loc) · 1006 Bytes
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from queue import Empty
from turtle import pos
from flask import Flask, render_template, url_for, request, redirect
from caption import *
from jokes import *
from main import jokes_post_process
import warnings
warnings.filterwarnings("ignore")
import PIL
app = Flask(__name__)
@app.route('/')
def hello():
return render_template('index.html')
@app.route('/', methods = ['POST'])
def upload_file():
if request.method == 'POST':
img = request.files['image']
print(img)
print(img.filename)
img.save("static/"+img.filename)
caption = caption_this_image("static/"+img.filename)
jokes = joke_gen(caption)
print("jokes", jokes)
joke = jokes_post_process(caption,jokes, img.filename)
if joke is None:
joke = jokes
result_dic = {
'image' : "static/" + img.filename,
'description' : joke
}
return render_template('index.html', results = result_dic)
if __name__ == '__main__':
app.run(debug = True)