Spaces:
Runtime error
Runtime error
added
Browse files- Dockerfile +16 -0
- main.py +110 -0
- requirements.txt +2 -0
Dockerfile
ADDED
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
2 |
+
# you will also find guides on how best to write your Dockerfile
|
3 |
+
|
4 |
+
FROM python:3.9
|
5 |
+
|
6 |
+
RUN useradd -m -u 1000 user
|
7 |
+
USER user
|
8 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
9 |
+
|
10 |
+
WORKDIR /app
|
11 |
+
|
12 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
13 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
14 |
+
|
15 |
+
COPY --chown=user . /app
|
16 |
+
CMD ["gunicorn", "-b", "0.0.0.0:7860", "main:app"]
|
main.py
ADDED
@@ -0,0 +1,110 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from flask import Flask, request, render_template_string
|
2 |
+
|
3 |
+
app = Flask(__name__)
|
4 |
+
|
5 |
+
# HTML template to get device GPS location
|
6 |
+
html_template = """
|
7 |
+
<!DOCTYPE html>
|
8 |
+
<html lang="en">
|
9 |
+
<head>
|
10 |
+
<meta charset="UTF-8">
|
11 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
12 |
+
<title>Device GPS Location Finder</title>
|
13 |
+
<style>
|
14 |
+
body {
|
15 |
+
font-family: Arial, sans-serif;
|
16 |
+
background-color: #f9f9f9;
|
17 |
+
text-align: center;
|
18 |
+
padding: 50px;
|
19 |
+
}
|
20 |
+
h1 {
|
21 |
+
color: #333;
|
22 |
+
}
|
23 |
+
button {
|
24 |
+
background-color: #4CAF50;
|
25 |
+
color: white;
|
26 |
+
border: none;
|
27 |
+
padding: 15px 32px;
|
28 |
+
text-align: center;
|
29 |
+
font-size: 16px;
|
30 |
+
border-radius: 5px;
|
31 |
+
cursor: pointer;
|
32 |
+
transition: background-color 0.3s;
|
33 |
+
}
|
34 |
+
button:hover {
|
35 |
+
background-color: #45a049;
|
36 |
+
}
|
37 |
+
#result {
|
38 |
+
margin-top: 20px;
|
39 |
+
font-weight: bold;
|
40 |
+
color: #555;
|
41 |
+
}
|
42 |
+
</style>
|
43 |
+
</head>
|
44 |
+
<body>
|
45 |
+
|
46 |
+
<h1>Get Your GPS Location</h1>
|
47 |
+
<p>Click the button below to get your GPS location.</p>
|
48 |
+
<button onclick="getLocation()">Get GPS Location</button>
|
49 |
+
|
50 |
+
<p id="result"></p>
|
51 |
+
|
52 |
+
<script>
|
53 |
+
function getLocation() {
|
54 |
+
if (navigator.geolocation) {
|
55 |
+
navigator.geolocation.getCurrentPosition(showPosition, showError);
|
56 |
+
} else {
|
57 |
+
document.getElementById("result").innerText = "Geolocation is not supported by this browser.";
|
58 |
+
}
|
59 |
+
}
|
60 |
+
|
61 |
+
function showPosition(position) {
|
62 |
+
const latitude = position.coords.latitude;
|
63 |
+
const longitude = position.coords.longitude;
|
64 |
+
document.getElementById("result").innerText = "Latitude: " + latitude + ", Longitude: " + longitude;
|
65 |
+
|
66 |
+
// Sending data to the Flask server (optional)
|
67 |
+
fetch("/location", {
|
68 |
+
method: "POST",
|
69 |
+
headers: {
|
70 |
+
"Content-Type": "application/json"
|
71 |
+
},
|
72 |
+
body: JSON.stringify({ latitude: latitude, longitude: longitude })
|
73 |
+
});
|
74 |
+
}
|
75 |
+
|
76 |
+
function showError(error) {
|
77 |
+
switch (error.code) {
|
78 |
+
case error.PERMISSION_DENIED:
|
79 |
+
document.getElementById("result").innerText = "User denied the request for Geolocation.";
|
80 |
+
break;
|
81 |
+
case error.POSITION_UNAVAILABLE:
|
82 |
+
document.getElementById("result").innerText = "Location information is unavailable.";
|
83 |
+
break;
|
84 |
+
case error.TIMEOUT:
|
85 |
+
document.getElementById("result").innerText = "The request to get user location timed out.";
|
86 |
+
break;
|
87 |
+
case error.UNKNOWN_ERROR:
|
88 |
+
document.getElementById("result").innerText = "An unknown error occurred.";
|
89 |
+
break;
|
90 |
+
}
|
91 |
+
}
|
92 |
+
</script>
|
93 |
+
|
94 |
+
</body>
|
95 |
+
</html>
|
96 |
+
"""
|
97 |
+
|
98 |
+
@app.route("/", methods=["GET"])
|
99 |
+
def index():
|
100 |
+
return render_template_string(html_template)
|
101 |
+
|
102 |
+
@app.route("/location", methods=["POST"])
|
103 |
+
def location():
|
104 |
+
data = request.get_json()
|
105 |
+
latitude = data.get("latitude")
|
106 |
+
longitude = data.get("longitude")
|
107 |
+
return f"Received Latitude: {latitude}, Longitude: {longitude}", 200
|
108 |
+
|
109 |
+
if __name__ == "__main__":
|
110 |
+
app.run(debug=True)
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
flask
|
2 |
+
gunicorn
|