Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,28 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from flask import Flask, Response, send_file, jsonify, request, make_response
|
| 2 |
+
import io
|
| 3 |
+
import requests
|
| 4 |
+
import os
|
| 5 |
+
import json
|
| 6 |
+
|
| 7 |
+
app = Flask(__name__)
|
| 8 |
+
|
| 9 |
+
@app.route('/map/<int:z>/<string:x>/<string:y>.png')
|
| 10 |
+
def get_tile(z, x, y):
|
| 11 |
+
url = 'https://tile.openstreetmap.org/{}/{}-{}.png'.format(z, x, y)
|
| 12 |
+
resp = requests.get(url)
|
| 13 |
+
img_byte_arr = bytearray(resp.content)
|
| 14 |
+
img_io = io.BytesIO(img_byte_arr)
|
| 15 |
+
return make_response(img_io.read(), mimetype='image/png')
|
| 16 |
+
|
| 17 |
+
if __name__ == "__main__":
|
| 18 |
+
app.run()
|
| 19 |
+
|
| 20 |
+
import gradio as gr
|
| 21 |
+
|
| 22 |
+
iface = gr.Interface(fn=None, # Not used here since the routing happens within Flask
|
| 23 |
+
title="OpenStreetMap Viewer",
|
| 24 |
+
description="A simple web app demonstrating rendering map tiles based on input coordinates.",
|
| 25 |
+
allow_flagging="never")
|
| 26 |
+
|
| 27 |
+
iface.load("http://localhost:5000", port=8001)
|
| 28 |
+
iface.queue().launch()
|