Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -30,29 +30,46 @@ with gr.Blocks() as demo:
|
|
| 30 |
|
| 31 |
# ===== HTML + JS ส่ง GPS + QR text ไป Google Form =====
|
| 32 |
gr.HTML("""
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
.catch(err => alert("❌ Error: " + err));
|
| 52 |
-
});
|
| 53 |
}
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
|
| 58 |
demo.launch()
|
|
|
|
| 30 |
|
| 31 |
# ===== HTML + JS ส่ง GPS + QR text ไป Google Form =====
|
| 32 |
gr.HTML("""
|
| 33 |
+
<div style='margin-top:20px;'>
|
| 34 |
+
<button id="sendBtn" style="
|
| 35 |
+
background:#4CAF50;
|
| 36 |
+
color:white;
|
| 37 |
+
padding:10px 20px;
|
| 38 |
+
border:none;
|
| 39 |
+
border-radius:5px;
|
| 40 |
+
font-size:16px;
|
| 41 |
+
">Send QR + GPS to Google Form</button>
|
| 42 |
+
</div>
|
| 43 |
+
|
| 44 |
+
<script>
|
| 45 |
+
document.getElementById("sendBtn").addEventListener("click", function() {
|
| 46 |
+
|
| 47 |
+
const qrText = document.querySelector('textarea[aria-label="QR Code Text"]').value;
|
| 48 |
+
if (!qrText) {
|
| 49 |
+
alert("Please scan QR code first");
|
| 50 |
+
return;
|
|
|
|
|
|
|
| 51 |
}
|
| 52 |
+
|
| 53 |
+
navigator.geolocation.getCurrentPosition(function(position) {
|
| 54 |
+
|
| 55 |
+
const lat = position.coords.latitude;
|
| 56 |
+
const lng = position.coords.longitude;
|
| 57 |
+
|
| 58 |
+
const formUrl = "https://docs.google.com/forms/u/1/d/e/YOUR_FORM_ID/formResponse";
|
| 59 |
+
|
| 60 |
+
const data = new FormData();
|
| 61 |
+
data.append("entry.2013313277", qrText);
|
| 62 |
+
data.append("entry.286817265", lat);
|
| 63 |
+
data.append("entry.518488535", lng);
|
| 64 |
+
|
| 65 |
+
fetch(formUrl, { method: "POST", body: data })
|
| 66 |
+
.then(() => alert("✅ QR + GPS sent to Google Form"))
|
| 67 |
+
.catch((e) => alert("❌ Error: " + e));
|
| 68 |
+
});
|
| 69 |
+
|
| 70 |
+
});
|
| 71 |
+
</script>
|
| 72 |
+
""")
|
| 73 |
+
|
| 74 |
|
| 75 |
demo.launch()
|