trapezius60 commited on
Commit
160b8cf
·
verified ·
1 Parent(s): c8a04aa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +40 -23
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
- <script>
34
- function sendToForm() {
35
- const qrText = document.querySelector('textarea[aria-label="QR Code Text"]').value;
36
- if (!qrText) { alert("Please scan QR code first"); return; }
37
-
38
- navigator.geolocation.getCurrentPosition(function(position) {
39
- const lat = position.coords.latitude;
40
- const lng = position.coords.longitude;
41
-
42
- const formUrl = "https://docs.google.com/forms/u/1/d/e/1FAIpQLSd87wspuXaH0kcNZ33GOXsnCDVIFqaHQlpZin7FmSdFPJ4Q7Q/formResponse";
43
-
44
- const data = new FormData();
45
- data.append("entry.2013313277", qrText); // QR text
46
- data.append("entry.286817265", lat); // latitude
47
- data.append("entry.518488535", lng); // longitude
48
-
49
- fetch(formUrl, { method: "POST", body: data })
50
- .then(() => alert("✅ QR + GPS sent to Google Form"))
51
- .catch(err => alert("❌ Error: " + err));
52
- });
53
  }
54
- </script>
55
- <button onclick="sendToForm()">Send QR + GPS to Google Form</button>
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()