-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.py
More file actions
23 lines (20 loc) · 757 Bytes
/
app.py
File metadata and controls
23 lines (20 loc) · 757 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from flask import Flask, request, render_template, redirect, url_for
from PIL import Image
import prediction
app = Flask(__name__)
@app.route('/', methods=['GET', 'POST'])
def index():
if request.method == 'POST':
if 'file' not in request.files:
return redirect(request.url)
file = request.files['file']
if file.filename == '':
return redirect(request.url)
if file:
file_path = f'static/media/{file.filename}'
file.save(file_path)
caption = prediction.predict_caption(file_path)
return render_template('index.html', file_path=file_path, caption=caption)
return render_template('index.html')
if __name__ == '__main__':
app.run(debug=True)