NSect BraydenMoore commited on
Commit
8a41586
·
0 Parent(s):

Duplicate from BraydenMoore/a-random-unsecured-camera

Browse files

Co-authored-by: Brayden Moore <[email protected]>

.gitattributes ADDED
@@ -0,0 +1,36 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
12
+ *.model filter=lfs diff=lfs merge=lfs -text
13
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
14
+ *.npy filter=lfs diff=lfs merge=lfs -text
15
+ *.npz filter=lfs diff=lfs merge=lfs -text
16
+ *.onnx filter=lfs diff=lfs merge=lfs -text
17
+ *.ot filter=lfs diff=lfs merge=lfs -text
18
+ *.parquet filter=lfs diff=lfs merge=lfs -text
19
+ *.pb filter=lfs diff=lfs merge=lfs -text
20
+ *.pickle filter=lfs diff=lfs merge=lfs -text
21
+ *.pkl filter=lfs diff=lfs merge=lfs -text
22
+ *.pt filter=lfs diff=lfs merge=lfs -text
23
+ *.pth filter=lfs diff=lfs merge=lfs -text
24
+ *.rar filter=lfs diff=lfs merge=lfs -text
25
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
26
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
27
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
28
+ *.tar filter=lfs diff=lfs merge=lfs -text
29
+ *.tflite filter=lfs diff=lfs merge=lfs -text
30
+ *.tgz filter=lfs diff=lfs merge=lfs -text
31
+ *.wasm filter=lfs diff=lfs merge=lfs -text
32
+ *.xz filter=lfs diff=lfs merge=lfs -text
33
+ *.zip filter=lfs diff=lfs merge=lfs -text
34
+ *.zst filter=lfs diff=lfs merge=lfs -text
35
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ static/loading.gif filter=lfs diff=lfs merge=lfs -text
Dockerfile ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ # Use the official lightweight Python image.
3
+ # https://hub.docker.com/_/python
4
+ FROM python:3.11-slim
5
+
6
+ # Allow statements and log messages to immediately appear in the logs
7
+ ENV PYTHONUNBUFFERED True
8
+
9
+ # Copy local code to the container image.
10
+ ENV APP_HOME /app
11
+ WORKDIR $APP_HOME
12
+ COPY . ./
13
+
14
+ # Install production dependencies.
15
+ RUN pip install --no-cache-dir -r requirements.txt
16
+
17
+ RUN useradd -m -u 1000 user
18
+ USER user
19
+ ENV HOME=/home/user \
20
+ PATH=/home/user/.local/bin:$PATH
21
+
22
+ WORKDIR $APP_HOME
23
+
24
+ COPY --chown=user . $HOME/app
25
+
26
+ # Run the web service on container startup. Here we use the gunicorn
27
+ # webserver, with one worker process and 8 threads.
28
+ # For environments with multiple CPU cores, increase the number of workers
29
+ # to be equal to the cores available.
30
+ # Timeout is set to 0 to disable the timeouts of the workers to allow Cloud Run to handle instance scaling.
31
+ CMD exec gunicorn --bind 0.0.0.0:7860 --workers 1 --threads 8 --timeout 0 main:app
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: A Random Unsecured Camera
3
+ emoji: 🐠
4
+ colorFrom: green
5
+ colorTo: purple
6
+ sdk: docker
7
+ pinned: false
8
+ license: mit
9
+ duplicated_from: BraydenMoore/a-random-unsecured-camera
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
active_urls.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:5bacc7efc4d40e09c2b302a17b45c342ede99857815220deafef04211c3c3834
3
+ size 165686
exceptions.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4a5a4d1e82c4e697c58e08f06d7afdffbb51c99e1c0752c0882f29a53e8cd02b
3
+ size 104
live_urls.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:ae1528d518b1bfc92d39e2a691af9f454728e6e4ad535d88865198019b5251d4
3
+ size 144335
main.py ADDED
@@ -0,0 +1,113 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from flask import Flask, Response, render_template, send_file, stream_with_context, request, session, redirect, url_for
2
+ import requests
3
+ import random
4
+ import pickle as pkl
5
+ import pycountry
6
+ import datetime as dt
7
+ import pytz
8
+ from io import BytesIO
9
+ import logging
10
+
11
+ logging.basicConfig(level=logging.INFO)
12
+
13
+ app = Flask(__name__)
14
+ app.secret_key = 'green-flounder'
15
+
16
+ with open('video_dict.pkl', 'rb') as f:
17
+ feed_dict = pkl.load(f)
18
+
19
+ with open('live_urls.pkl', 'rb') as f:
20
+ live_urls = pkl.load(f)
21
+
22
+ with open('active_urls.pkl', 'rb') as f:
23
+ live_urls = pkl.load(f)
24
+
25
+ def get_ip_info(ip_address):
26
+ try:
27
+ response = requests.get(f"http://ipinfo.io/{ip_address}/json")
28
+ data = response.json()
29
+ return data
30
+ except Exception as e:
31
+ return {"error": str(e)}
32
+
33
+ def latlon_to_pixel(loc):
34
+ latitude = float(loc.split(',')[0])
35
+ longitude = float(loc.split(',')[1])
36
+
37
+ y = ((90-latitude)/180)
38
+ x = ((longitude+180)/360)
39
+ return x*100, y*100
40
+
41
+ from urllib.parse import urlparse, parse_qs
42
+
43
+ @app.route('/proxy/<path:url>')
44
+ def proxy(url):
45
+
46
+ headers = {
47
+ 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7',
48
+ 'Accept-Encoding': 'gzip, deflate',
49
+ 'Accept-Language': 'en-US,en;q=0.9',
50
+ 'Cache-Control': 'max-age=0',
51
+ 'Connection': 'keep-alive',
52
+ 'Dnt': '1',
53
+ 'Upgrade-Insecure-Requests': '1',
54
+ 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/116.0.0.0 Safari/537.36'
55
+ }
56
+
57
+ clean_url = url.replace('proxy/', '')
58
+ print('Cleaned URL:', clean_url)
59
+
60
+ try:
61
+ if '.jpg' in clean_url and 'stream' not in clean_url:
62
+ req = requests.get(clean_url, headers=headers, timeout=3)
63
+ logging.info(f"Status Code: {req.status_code}, Response Headers: {req.headers}")
64
+ return Response(req.content, content_type=req.headers['content-type'])
65
+ else:
66
+ req = requests.get(clean_url, headers=headers, stream=True, timeout=10)
67
+ logging.info(f"Status Code: {req.status_code}, Response Headers: {req.headers}")
68
+ return Response(req.iter_content(chunk_size=512), content_type=req.headers['content-type'])
69
+ except requests.exceptions.RequestException as e:
70
+ logging.error(f"Error in proxy: {e}")
71
+ return send_file('static/error.png', mimetype='image/png')
72
+
73
+
74
+ @app.route('/')
75
+ def index():
76
+
77
+ if 'current_feed' in session and request.args.get('new', 'false') == 'false':
78
+ feed = session['current_feed']
79
+ else:
80
+ feed = random.randint(0, len(live_urls) - 1)
81
+ session['current_feed'] = feed
82
+
83
+ #url = feed_dict[feed]['url']
84
+ url = live_urls[feed]
85
+ ip = ''.join(url.split('//')[-1]).split(':')[0]
86
+ info = get_ip_info(ip)
87
+ country = (pycountry.countries.get(alpha_2=info['country']).name).lower()
88
+ name = (info['city'] + ", " + info['region'] + ", " + country).lower()
89
+ org = info['org'].lower()
90
+ timezone = pytz.timezone(info['timezone'])
91
+ time = dt.datetime.now(timezone)
92
+ loc = info['loc']
93
+ X, Y = latlon_to_pixel(info['loc'])
94
+ proxy_url = 'proxy/' + url
95
+
96
+ loc_link = f"https://www.google.com/maps/search/{loc}"
97
+ ip_link = url
98
+ return render_template('index.html',
99
+ name=name,
100
+ url=proxy_url,
101
+ info=info,
102
+ country=country,
103
+ time=time,
104
+ ip=ip,
105
+ ip_link=ip_link,
106
+ org=org,
107
+ loc=loc,
108
+ loc_link=loc_link,
109
+ X=X,
110
+ Y=Y)
111
+
112
+ if __name__ == '__main__':
113
+ app.run(host='0.0.0.0', port='7860', debug=True)
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ Flask==2.2.5
2
+ pycountry==22.3.5
3
+ pytz==2023.3
4
+ requests==2.31.0
5
+ gunicorn==20.1.0
static/error.png ADDED
static/loading.gif ADDED

Git LFS Details

  • SHA256: 03f4382e20ae59382e9a56478dc25add51760bf72c1f3df0b770c7138071a98c
  • Pointer size: 132 Bytes
  • Size of remote file: 3.28 MB
static/map.png ADDED
static/map_populated.png ADDED
templates/index.html ADDED
@@ -0,0 +1,204 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
4
+ <head>
5
+ <link rel="icon" type="image/png" href="https://images.squarespace-cdn.com/content/v1/64790f5777b5d772678cce83/6d71eaee-f825-4324-be9b-2def32469eac/Untitled+drawing+%2811%29.png?format=100w">
6
+ <title>a random unsecured camera</title>
7
+ <style>
8
+ body {
9
+ transition: 0.3s;
10
+ justify-content: left;
11
+ background-color: black;
12
+ padding-top: 3%;
13
+ margin-left: 5vw;
14
+ }
15
+
16
+ .pulse {
17
+ width: 40px;
18
+ height: 40px;
19
+ border-radius: 50%;
20
+ position: absolute;
21
+ background-color: yellow;
22
+ opacity: 0.5;
23
+ animation: pulse-animation 5s infinite;
24
+ margin-left: -20px;
25
+ margin-top: -20px;
26
+ }
27
+
28
+ .dot {
29
+ border-style: solid;
30
+ border-width: 2px;
31
+ border-color: black;
32
+ width: 5px;
33
+ height: 5px;
34
+ border-radius: 50%;
35
+ position: absolute;
36
+ background-color: yellow;
37
+ margin-left: -4.5px;
38
+ margin-top: -4.5px;
39
+ }
40
+
41
+ @keyframes pulse-animation {
42
+ 0% { transform: scale(0.1); opacity: 0.4; }
43
+ 100% { transform: scale(3); opacity: 0; }
44
+ }
45
+
46
+ .flex-container {
47
+ display: flex;
48
+ justify-content: left;
49
+ align-items: top;
50
+ }
51
+
52
+ .outer-container {
53
+ margin-left: 2%;
54
+ justify-content: left;
55
+ align-items: left;
56
+ max-width: 70vw;
57
+ }
58
+
59
+ .feed {
60
+ padding: 1%;
61
+ border-style: solid;
62
+ border-width: 1px;
63
+ border-color: yellow;
64
+ margin-right: 3%;
65
+ margin-bottom: 3%;
66
+ min-width: 50%;
67
+ height: 65vh;
68
+ }
69
+
70
+ .map-div {
71
+ padding: 1%;
72
+ position: relative;
73
+ width: 100%;
74
+ height: 50%;
75
+ margin-top: 3%;
76
+ margin-bottom: 3%;
77
+ box-sizing: border-box;
78
+ }
79
+
80
+ .map {
81
+ width: 100%;
82
+ height: 100%;
83
+ object-fit: cover;
84
+ margin: auto;
85
+ }
86
+
87
+ .info {
88
+ display: flex;
89
+ flex-direction: column;
90
+ align-items: flex-start;
91
+ }
92
+
93
+ a:hover {
94
+ background-color: yellow;
95
+ color: black;
96
+ transition: 0.5s ease-in-out;
97
+ }
98
+
99
+ a {
100
+ color:rgb(83, 83, 83);
101
+ }
102
+
103
+ @media only screen and (orientation: portrait) {
104
+ body {
105
+ margin-left: auto;
106
+ }
107
+
108
+ .h1 {
109
+ margin-bottom: 2%;
110
+ }
111
+
112
+ .flex-container {
113
+ flex-direction: column;
114
+ align-items: left;
115
+ }
116
+
117
+ .feed {
118
+ width: 90vw;
119
+ max-height: 45vh;
120
+ margin-right: 0;
121
+ }
122
+ .info {
123
+ width: 90vw;
124
+ height: 65vh;
125
+ }
126
+ }
127
+
128
+ </style>
129
+ </head>
130
+
131
+ <body style="background-color: black;">
132
+ <div class="outer-container">
133
+ <p style="color:rgb(83, 83, 83); font-family: 'Helvetica'; font-weight: 50;"> a random unsecured camera in</p>
134
+ <h1 style="color:rgb(83, 83, 83); font-family: 'Helvetica'; font-weight: 50; margin-bottom: 3%;"> {{ country }}</h1>
135
+ <div class="flex-container">
136
+ <img id="feed" class="feed" src="{{ url_for('proxy', url=url) }}" />
137
+ <div class="info">
138
+
139
+ <h3 style="border-bottom: 1px solid yellow; color:rgb(83, 83, 83); font-family: 'Helvetica'; font-weight: 50;">{{ name }}</h3>
140
+
141
+ <div style="display: flex; margin-top: 3%; margin-bottom: 3%;">
142
+ <a href="?new=true" style="margin-right: 10px; display: inline-block;">
143
+ <button class="hoverButton" style="border: 1px solid yellow; background-color: transparent; color: rgb(83, 83, 83); padding: 10px;">
144
+ another
145
+ </button>
146
+ </a>
147
+ <a href="?new=false" id="refreshSameFeedButton" style="display: inline-block;">
148
+ <button class="hoverButton" style="border: 1px solid rgb(83, 83, 83); background-color: transparent; color: rgb(83, 83, 83); padding: 10px;">
149
+ refresh
150
+ </button>
151
+ </a>
152
+ </div>
153
+
154
+ <p style="color:rgb(83, 83, 83); font-family: 'Helvetica'; font-weight: 50;">
155
+ <a href="{{ ip_link }}" target="_blank">raw data: {{ ip }}</a> <br>
156
+ lat, lon: {{ loc }}<br>
157
+ owner: {{ org }}<br>
158
+ time: {{ time }}
159
+ </p>
160
+
161
+
162
+ <div class="map-div">
163
+ <img id="map" src="{{ url_for('static', filename='map_populated.png') }}" style="width: 100%; height: 100%;" />
164
+ <div class="dot" style="left: {{ X }}%; top: {{ Y }}%;"></div>
165
+ <div class="pulse" style="left: {{ X }}%; top: {{ Y }}%;"></div>
166
+ </div>
167
+
168
+ <p style="color:rgb(83, 83, 83); font-family: 'Helvetica'; font-weight: 50; margin-top: 3%;">
169
+ a brayden moore website
170
+ </p>
171
+
172
+ </div>
173
+ </div>
174
+ </div>
175
+
176
+
177
+ <script>
178
+ // document.addEventListener("DOMContentLoaded", function() {
179
+ // const feed = document.getElementById("feed");
180
+ // feed.src = "{{ url_for('static', filename='loading.gif') }}"
181
+ // setTimeout(function() {
182
+ // const newUrl = "{{ url }}";
183
+ // feed.src = newUrl;
184
+ // });
185
+ // });
186
+
187
+
188
+ document.addEventListener("DOMContentLoaded", function() {
189
+ const feed = document.getElementById("feed");
190
+ feed.src = "{{ url_for('static', filename='loading.gif') }}";
191
+
192
+ const newUrl = "{{ url }}";
193
+
194
+ const img = new Image();
195
+ img.onload = function() {
196
+ feed.src = this.src;
197
+ };
198
+ img.src = newUrl;
199
+ });
200
+
201
+ </script>
202
+ </body>
203
+
204
+ </html>
video_dict.pkl ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:f4ec8ec38d1aec5adec11fce5a185d87b53eba7302080761c100998498474a65
3
+ size 291669