trapezius60 commited on
Commit
c83002f
·
verified ·
1 Parent(s): 5776337

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -5
app.py CHANGED
@@ -13,15 +13,14 @@ ENTRY_LNG = "entry.518488535"
13
 
14
  # ===== Function scan QR + send GPS =====
15
  def scan_qr_send_form(image, lat, lng):
16
- # Convert PIL image to OpenCV format
17
- img = cv2.cvtColor(np.array(Image.open(image)), cv2.COLOR_RGB2BGR)
18
 
19
  detector = cv2.QRCodeDetector()
20
  data, bbox, _ = detector.detectAndDecode(img)
21
 
22
  if data:
23
  qr_text = data
24
- # Prepare data for Google Form
25
  payload = {
26
  ENTRY_QR: qr_text,
27
  ENTRY_LAT: lat,
@@ -35,11 +34,12 @@ def scan_qr_send_form(image, lat, lng):
35
  else:
36
  return "❌ No QR code detected"
37
 
 
38
  # ===== Gradio UI =====
39
  with gr.Blocks() as demo:
40
  gr.Markdown("### Scan QR Code & Auto GPS Location → Google Form")
41
 
42
- qr_image = gr.Image(source="webcam", type="filepath", label="Scan QR Code")
43
  lat_input = gr.Textbox(label="Latitude", interactive=False)
44
  lng_input = gr.Textbox(label="Longitude", interactive=False)
45
  output = gr.Textbox(label="Result")
@@ -51,7 +51,6 @@ with gr.Blocks() as demo:
51
  outputs=output
52
  )
53
 
54
- # Custom JS to get GPS from mobile browser
55
  demo.load(
56
  """
57
  <script>
@@ -68,3 +67,4 @@ with gr.Blocks() as demo:
68
  )
69
 
70
  demo.launch()
 
 
13
 
14
  # ===== Function scan QR + send GPS =====
15
  def scan_qr_send_form(image, lat, lng):
16
+ # image จะเป็น PIL.Image ถ้า type="pil"
17
+ img = cv2.cvtColor(np.array(image), cv2.COLOR_RGB2BGR)
18
 
19
  detector = cv2.QRCodeDetector()
20
  data, bbox, _ = detector.detectAndDecode(img)
21
 
22
  if data:
23
  qr_text = data
 
24
  payload = {
25
  ENTRY_QR: qr_text,
26
  ENTRY_LAT: lat,
 
34
  else:
35
  return "❌ No QR code detected"
36
 
37
+
38
  # ===== Gradio UI =====
39
  with gr.Blocks() as demo:
40
  gr.Markdown("### Scan QR Code & Auto GPS Location → Google Form")
41
 
42
+ qr_image = gr.Image(tool="webcam", type="pil", label="Scan QR Code")
43
  lat_input = gr.Textbox(label="Latitude", interactive=False)
44
  lng_input = gr.Textbox(label="Longitude", interactive=False)
45
  output = gr.Textbox(label="Result")
 
51
  outputs=output
52
  )
53
 
 
54
  demo.load(
55
  """
56
  <script>
 
67
  )
68
 
69
  demo.launch()
70
+