-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathwsgi.py
More file actions
executable file
·39 lines (34 loc) · 1.13 KB
/
Copy pathwsgi.py
File metadata and controls
executable file
·39 lines (34 loc) · 1.13 KB
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
import sys
import cloudinary as Cloud
import cloudinary.uploader as cu
import os
from requests import get as rq
from PIL import Image
from io import BytesIO
from flask import Flask, render_template, request, redirect
import caption_gen
app = Flask(__name__)
Cloud.config.update = (
{ 'cloud_name' : os.environ.get('CLOUD_NAME'),
'api_key': os.environ.get('API_KEY'),
'api_secret': os.environ.get('API_SECRET')
})
@app.route('/')
def hello():
return render_template("index.html")
@app.route('/', methods=['POST'])
def marks():
if request.method == 'POST':
file_to_upload = request.files['userfile']
upload_result = cu.upload(file_to_upload)
response = rq(upload_result["url"])
img = Image.open(BytesIO(response.content))
caption = caption_gen.caption_this_image(img)
result_dic = {
'image': upload_result["url"],
'caption': caption
}
return render_template("index.html", your_result=result_dic)
if __name__ == '__main__':
app.debug = True
app.run()