CatoG commited on
Commit
eef02d9
·
1 Parent(s): 788f59d
Files changed (1) hide show
  1. app.py +40 -28
app.py CHANGED
@@ -757,6 +757,15 @@ with gr.Blocks(title="Provider Multi-Model Agent", theme=gr.themes.Soft()) as de
757
 
758
  chart_output = gr.Image(label="Generated chart", type="filepath")
759
 
 
 
 
 
 
 
 
 
 
760
  with gr.Column(scale=1):
761
  enabled_tools = gr.CheckboxGroup(
762
  choices=TOOL_NAMES,
@@ -775,42 +784,45 @@ with gr.Blocks(title="Provider Multi-Model Agent", theme=gr.themes.Soft()) as de
775
  interactive=False,
776
  )
777
 
778
- # Populated by JavaScript on page load with precise browser coordinates (GPS/WiFi),
779
- # stored as "lat,lon". Falls back to the public IP via ipify if geolocation is denied.
780
  client_ip_box = gr.Textbox(visible=False, value="")
781
 
782
- demo.load(
 
 
 
 
 
 
 
 
783
  fn=None,
784
  inputs=None,
785
- outputs=[client_ip_box],
786
  js="""async () => {
787
  return new Promise((resolve) => {
788
- if (navigator.geolocation) {
789
- navigator.geolocation.getCurrentPosition(
790
- (pos) => resolve(pos.coords.latitude + ',' + pos.coords.longitude),
791
- async () => {
792
- try {
793
- const r = await fetch('https://api.ipify.org?format=json');
794
- const d = await r.json();
795
- resolve('ip:' + d.ip);
796
- } catch(e) { resolve(''); }
797
- },
798
- {timeout: 8000, maximumAge: 60000}
799
- );
800
- } else {
801
- fetch('https://api.ipify.org?format=json')
802
- .then(r => r.json())
803
- .then(d => resolve('ip:' + d.ip))
804
- .catch(() => resolve(''));
805
- }
 
 
806
  });
807
  }""",
808
- )
809
-
810
- model_dropdown.change(
811
- fn=model_status_text,
812
- inputs=[model_dropdown],
813
- outputs=[model_status],
814
  show_api=False,
815
  )
816
 
 
757
 
758
  chart_output = gr.Image(label="Generated chart", type="filepath")
759
 
760
+ with gr.Row():
761
+ location_btn = gr.Button("📍 Share my location", size="sm")
762
+ location_status = gr.Textbox(
763
+ value="Location not set — click the button above before asking 'where am I'",
764
+ label="Location status",
765
+ interactive=False,
766
+ max_lines=1,
767
+ )
768
+
769
  with gr.Column(scale=1):
770
  enabled_tools = gr.CheckboxGroup(
771
  choices=TOOL_NAMES,
 
784
  interactive=False,
785
  )
786
 
787
+ # Hidden: holds "lat,lon" or "ip:<address>" set by the location button
 
788
  client_ip_box = gr.Textbox(visible=False, value="")
789
 
790
+ model_dropdown.change(
791
+ fn=model_status_text,
792
+ inputs=[model_dropdown],
793
+ outputs=[model_status],
794
+ show_api=False,
795
+ )
796
+
797
+ # Geolocation button: JS runs in the browser, result goes to hidden box + status label
798
+ location_btn.click(
799
  fn=None,
800
  inputs=None,
801
+ outputs=[client_ip_box, location_status],
802
  js="""async () => {
803
  return new Promise((resolve) => {
804
+ const fallback = async () => {
805
+ try {
806
+ const r = await fetch('https://api.ipify.org?format=json');
807
+ const d = await r.json();
808
+ resolve(['ip:' + d.ip, 'Location: IP-based fallback (approximate)']);
809
+ } catch(e) {
810
+ resolve(['', 'Location detection failed.']);
811
+ }
812
+ };
813
+ if (!navigator.geolocation) { fallback(); return; }
814
+ navigator.geolocation.getCurrentPosition(
815
+ (pos) => {
816
+ const lat = pos.coords.latitude.toFixed(5);
817
+ const lon = pos.coords.longitude.toFixed(5);
818
+ const acc = Math.round(pos.coords.accuracy);
819
+ resolve([lat + ',' + lon, `\u2705 GPS/WiFi location set (\u00b1${acc}m)`]);
820
+ },
821
+ fallback,
822
+ {timeout: 10000, maximumAge: 60000, enableHighAccuracy: true}
823
+ );
824
  });
825
  }""",
 
 
 
 
 
 
826
  show_api=False,
827
  )
828