grixelle commited on
Commit
7b78a5c
·
verified ·
1 Parent(s): 2c9a7b3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -26
app.py CHANGED
@@ -2,51 +2,44 @@ import gradio as gr
2
  from google import genai
3
  import os
4
 
5
- def ground_truth_audit(past_img, present_img):
6
- """Explicitly mapped backend function for GroundTruth."""
7
  api_key = os.environ.get("GOOGLE_API_KEY")
8
  if not api_key:
9
- return "## Error\nAPI Key not found. Please add GOOGLE_API_KEY to Space Secrets."
10
 
11
  client = genai.Client(api_key=api_key)
12
 
13
  if past_img is None or present_img is None:
14
  return "Please upload both images."
15
 
16
- prompt = """
17
- Perform a structural audit comparing these two images.
18
- Look for changes in roofing, landscaping, and exterior condition.
19
- Provide a 'Maintenance Trajectory': IMPROVING, STABLE, or DECLINING.
20
- """
21
 
22
  try:
23
- # Utilizing Robotics-ER 1.5 for spatial/temporal analysis
24
  response = client.models.generate_content(
25
  model="gemini-robotics-er-1.5-preview",
26
  contents=[prompt, past_img, present_img]
27
  )
28
  return response.text
29
  except Exception as e:
30
- return f"## Analysis Failed\n{str(e)}"
31
 
32
- # Explicitly defining the UI blocks to fix the 'No API found' error
33
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
34
- gr.Markdown("# 🏠 GroundTruth AI")
35
- gr.Markdown("Temporal Property Sentinel powered by Gemini Robotics-ER 1.5")
36
 
37
  with gr.Row():
38
- with gr.Column():
39
- past = gr.Image(label="Past Condition", type="pil")
40
- present = gr.Image(label="Present Condition", type="pil")
41
- # Explicitly naming the trigger button
42
- btn = gr.Button("Analyze Structural Trajectory", variant="primary")
43
-
44
- with gr.Column():
45
- # Explicitly naming the output container
46
- out = gr.Markdown(label="Audit Report")
47
 
48
- # Manually mapping the click to the API function
49
- btn.click(fn=ground_truth_audit, inputs=[past, present], outputs=out)
50
 
51
- # Mandatory for Gradio 5+ to handle background API processing
52
  demo.queue().launch()
 
2
  from google import genai
3
  import os
4
 
5
+ def audit_engine(past_img, present_img):
6
+ """Forensic structural audit logic."""
7
  api_key = os.environ.get("GOOGLE_API_KEY")
8
  if not api_key:
9
+ return "ERROR: GOOGLE_API_KEY not found in Space Secrets."
10
 
11
  client = genai.Client(api_key=api_key)
12
 
13
  if past_img is None or present_img is None:
14
  return "Please upload both images."
15
 
16
+ # Robotics-ER 1.5 prompt for structural grounding
17
+ prompt = "Compare these images for changes in roofing, landscaping, and exterior condition. Output a 'Maintenance Trajectory': IMPROVING, STABLE, or DECLINING."
 
 
 
18
 
19
  try:
20
+ # Utilizing the Robotics preview model
21
  response = client.models.generate_content(
22
  model="gemini-robotics-er-1.5-preview",
23
  contents=[prompt, past_img, present_img]
24
  )
25
  return response.text
26
  except Exception as e:
27
+ return f"Analysis Failed: {str(e)}"
28
 
29
+ # Minimalist Blocks to bypass the 'TypeError: bool' schema bug
30
+ with gr.Blocks() as demo:
31
+ gr.HTML("<h1>🏠 GroundTruth AI</h1>")
 
32
 
33
  with gr.Row():
34
+ p_img = gr.Image(label="Past Image", type="pil")
35
+ c_img = gr.Image(label="Current Image", type="pil")
36
+
37
+ # Textbox is more stable than Markdown in G5 for schema generation
38
+ output = gr.Textbox(label="Structural Audit Report")
39
+ submit = gr.Button("Analyze Trajectory", variant="primary")
 
 
 
40
 
41
+ # Explicit event binding
42
+ submit.click(fn=audit_engine, inputs=[p_img, c_img], outputs=output)
43
 
44
+ # Queue is essential for the 30s latency of the Robotics model
45
  demo.queue().launch()