Spaces:
Running
Running
BraydenMoore
commited on
Commit
·
6509820
1
Parent(s):
da07ef0
Update main.py
Browse files
main.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from flask import Flask, Response, render_template, send_file
|
2 |
import requests
|
3 |
import random
|
4 |
import pickle as pkl
|
@@ -6,11 +6,11 @@ import pycountry
|
|
6 |
import datetime as dt
|
7 |
import pytz
|
8 |
|
|
|
|
|
9 |
with open('video_dict.pkl', 'rb') as f:
|
10 |
feed_dict = pkl.load(f)
|
11 |
|
12 |
-
app = Flask(__name__)
|
13 |
-
|
14 |
def get_ip_info(ip_address):
|
15 |
try:
|
16 |
response = requests.get(f"http://ipinfo.io/{ip_address}/json")
|
@@ -27,6 +27,14 @@ def latlon_to_pixel(loc):
|
|
27 |
x = ((longitude+180)/360)
|
28 |
return x*100, y*100
|
29 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
30 |
@app.route('/')
|
31 |
def index():
|
32 |
feed = random.randint(0, len(feed_dict) - 1)
|
@@ -40,8 +48,8 @@ def index():
|
|
40 |
loc = info['loc']
|
41 |
print(info)
|
42 |
X, Y = latlon_to_pixel(info['loc'])
|
43 |
-
|
44 |
-
return render_template('index.html', name=name, url=
|
45 |
|
46 |
if __name__ == '__main__':
|
47 |
app.run(host='0.0.0.0', port='7860', debug=True)
|
|
|
1 |
+
from flask import Flask, Response, render_template, send_file, stream_with_context
|
2 |
import requests
|
3 |
import random
|
4 |
import pickle as pkl
|
|
|
6 |
import datetime as dt
|
7 |
import pytz
|
8 |
|
9 |
+
app = Flask(__name__)
|
10 |
+
|
11 |
with open('video_dict.pkl', 'rb') as f:
|
12 |
feed_dict = pkl.load(f)
|
13 |
|
|
|
|
|
14 |
def get_ip_info(ip_address):
|
15 |
try:
|
16 |
response = requests.get(f"http://ipinfo.io/{ip_address}/json")
|
|
|
27 |
x = ((longitude+180)/360)
|
28 |
return x*100, y*100
|
29 |
|
30 |
+
@app.route('/proxy/<path:url>')
|
31 |
+
def proxy(url):
|
32 |
+
req = requests.get('http://' + url, stream=True)
|
33 |
+
def generate():
|
34 |
+
for chunk in req.iter_content(chunk_size=1024):
|
35 |
+
yield chunk
|
36 |
+
return Response(generate(), content_type=req.headers['content-type'])
|
37 |
+
|
38 |
@app.route('/')
|
39 |
def index():
|
40 |
feed = random.randint(0, len(feed_dict) - 1)
|
|
|
48 |
loc = info['loc']
|
49 |
print(info)
|
50 |
X, Y = latlon_to_pixel(info['loc'])
|
51 |
+
proxy_url = 'proxy/' + url.split('http://')[-1]
|
52 |
+
return render_template('index.html', name=name, url=proxy_url, info=info, time=time, ip=ip, org=org, loc=loc, X=X, Y=Y)
|
53 |
|
54 |
if __name__ == '__main__':
|
55 |
app.run(host='0.0.0.0', port='7860', debug=True)
|