-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.py
48 lines (35 loc) · 886 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
import sys
import os
from flask import (
Flask,
flash,
request,
render_template,
redirect
)
import io
from flask_socketio import SocketIO, emit
import requests
app = Flask(__name__)
app.secret_key = os.environ['FLASK_SECRET_KEY']
socketio = SocketIO(app)
@app.route("/")
def index():
return render_template("index.html")
@app.route('/upload', methods=['POST'])
def upload_image():
data = request.files['image']
socketio.emit('new_image', data.read())
return redirect('/')
@app.route('/link', methods=['GET'])
def image_from_link():
try:
response = requests.get(request.args['url'])
socketio.emit('new_image', response.content)
except:
flash("Couldn't get the image from that URL :(")
return redirect('/')
def run_server():
socketio.run(app, port=5000)
if __name__ == '__main__':
run_server()