Spaces:
Runtime error
Runtime error
| from flask import Flask, jsonify, render_template, request, stream_with_context, Response | |
| from flask_cors import CORS | |
| import requests | |
| app = Flask(__name__) | |
| CORS(app) | |
| def index(): | |
| return render_template("index.html") | |
| # this proxies any api request from flask to jupyter gateway running on localhost:10000 | |
| # ref https://gist.github.com/ShinJJang/5769c3d2202d5f478549395969bc67f4 | |
| def proxy(path): | |
| url = f'http://localhost:10000/api/{path}' | |
| http_method = requests.post if request.method == 'POST' else requests.get | |
| if request.json: | |
| data = request.json | |
| print(f'{http_method.__name__} json: {data}') | |
| req = http_method(url, json=data) | |
| if request.form: | |
| data = request.form.to_dict() | |
| print(f'{http_method.__name__} form: {data}') | |
| req = http_method(url, data=data) | |
| return Response(stream_with_context(req.iter_content()), content_type=request.content_type) | |
| if __name__ == "__main__": | |
| app.run(host="0.0.0.0", port=7860) | |