grixelle commited on
Commit
6dffb88
·
verified ·
1 Parent(s): 5f83972

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -22
app.py CHANGED
@@ -1,38 +1,42 @@
1
  import gradio as gr
2
  from google import genai
3
  import os
4
- import time
5
 
6
- # We add 'progress=gr.Progress()' as an argument to enable the status bar
7
- def ground_truth_engine(past_img, present_img, progress=gr.Progress()):
8
- # 1. Immediate Visual Feedback
9
  progress(0, desc="Initializing Spatial Engine...")
10
 
11
  api_key = os.environ.get("GOOGLE_API_KEY")
12
  if not api_key:
13
- return "ERROR: GOOGLE_API_KEY not found in Space Secrets."
14
 
15
  client = genai.Client(api_key=api_key)
16
-
17
  if past_img is None or present_img is None:
18
  return "Please upload both images."
19
 
20
- # 2. Update status before the heavy lifting
21
- progress(0.3, desc="Uploading Images to Gemini...")
 
 
22
 
23
- prompt = """
24
- Perform a high-fidelity structural audit comparing these two images.
25
- Focus on changes in roofing, landscaping, and exterior condition.
26
- Conclude with a 'Maintenance Trajectory': IMPROVING, STABLE, or DECLINING.
 
 
 
27
  """
28
 
29
  try:
30
- # 3. Setting expectation for the 'Thinking' phase
31
- progress(0.6, desc="Reasoning Spatially (This takes ~20-30s)...")
32
 
 
33
  response = client.models.generate_content(
34
  model="gemini-robotics-er-1.5-preview",
35
- contents=[prompt, past_img, present_img]
 
 
 
36
  )
37
 
38
  progress(1.0, desc="Audit Complete!")
@@ -40,27 +44,32 @@ def ground_truth_engine(past_img, present_img, progress=gr.Progress()):
40
  except Exception as e:
41
  return f"Analysis Failed: {str(e)}"
42
 
43
- # --- UI Setup ---
44
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
45
- gr.Markdown("# 🏠 GroundTruth AI (Stable Build)")
46
 
47
  with gr.Row():
48
  with gr.Column():
49
  p_img = gr.Image(label="Past Condition", type="pil")
50
  c_img = gr.Image(label="Current Condition", type="pil")
51
- submit = gr.Button("Analyze Trajectory", variant="primary")
 
 
 
 
 
 
 
 
52
 
53
  with gr.Column():
54
  output = gr.Markdown(label="Audit Report")
55
 
56
- # Important: show_progress="full" ensures the spinner stays visible
57
  submit.click(
58
  fn=ground_truth_engine,
59
- inputs=[p_img, c_img],
60
  outputs=output,
61
  show_progress="full"
62
  )
63
 
64
  if __name__ == "__main__":
65
- # Ensure queue is enabled for progress bar to update
66
- demo.queue().launch(server_name="0.0.0.0", server_port=7860)
 
1
  import gradio as gr
2
  from google import genai
3
  import os
 
4
 
5
+ def ground_truth_engine(past_img, present_img, audit_level, progress=gr.Progress()):
 
 
6
  progress(0, desc="Initializing Spatial Engine...")
7
 
8
  api_key = os.environ.get("GOOGLE_API_KEY")
9
  if not api_key:
10
+ return "ERROR: Set GOOGLE_API_KEY in Space Secrets."
11
 
12
  client = genai.Client(api_key=api_key)
 
13
  if past_img is None or present_img is None:
14
  return "Please upload both images."
15
 
16
+ # Map Slider to API 'thinking_budget'
17
+ # Quick = Low budget, Forensic = High budget
18
+ budget_map = {"Quick Scan": 100, "Standard Audit": 400, "Deep Forensic": 1000}
19
+ selected_budget = budget_map.get(audit_level, 400)
20
 
21
+ progress(0.2, desc=f"Level: {audit_level} (Budget: {selected_budget})")
22
+
23
+ prompt = f"""
24
+ Perform a {audit_level} structural audit.
25
+ Compare roofing, landscaping, and exterior condition.
26
+ Provide precise physical evidence for changes.
27
+ Conclude with 'Maintenance Trajectory': IMPROVING, STABLE, or DECLINING.
28
  """
29
 
30
  try:
31
+ progress(0.5, desc="Robotics-ER is reasoning spatially...")
 
32
 
33
+ # We pass the audit level intent into the generation config
34
  response = client.models.generate_content(
35
  model="gemini-robotics-er-1.5-preview",
36
+ contents=[prompt, past_img, present_img],
37
+ config={
38
+ "thinking_budget": selected_budget
39
+ }
40
  )
41
 
42
  progress(1.0, desc="Audit Complete!")
 
44
  except Exception as e:
45
  return f"Analysis Failed: {str(e)}"
46
 
 
47
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
48
+ gr.Markdown("# 🏠 GroundTruth AI: Spatial Property Sentinel")
49
 
50
  with gr.Row():
51
  with gr.Column():
52
  p_img = gr.Image(label="Past Condition", type="pil")
53
  c_img = gr.Image(label="Current Condition", type="pil")
54
+
55
+ # New UI Element: Audit Level Slider
56
+ audit_slider = gr.Radio(
57
+ choices=["Quick Scan", "Standard Audit", "Deep Forensic"],
58
+ value="Standard Audit",
59
+ label="Audit Depth (Robotics Reasoning Level)"
60
+ )
61
+
62
+ submit = gr.Button("Analyze Structural Trajectory", variant="primary")
63
 
64
  with gr.Column():
65
  output = gr.Markdown(label="Audit Report")
66
 
 
67
  submit.click(
68
  fn=ground_truth_engine,
69
+ inputs=[p_img, c_img, audit_slider],
70
  outputs=output,
71
  show_progress="full"
72
  )
73
 
74
  if __name__ == "__main__":
75
+ demo.launch(server_name="0.0.0.0", server_port=7860)