grixelle commited on
Commit
2c9a7b3
·
verified ·
1 Parent(s): 985ee90

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -22
app.py CHANGED
@@ -3,24 +3,24 @@ from google import genai
3
  import os
4
 
5
  def ground_truth_audit(past_img, present_img):
 
6
  api_key = os.environ.get("GOOGLE_API_KEY")
7
  if not api_key:
8
- return "## Error: GOOGLE_API_KEY not found in Space Secrets."
9
 
10
  client = genai.Client(api_key=api_key)
11
 
12
- # Robotics-ER 1.5 requires precise prompts for spatial reasoning
 
 
13
  prompt = """
14
  Perform a structural audit comparing these two images.
15
- 1. Roofing & Gutters: Look for shingle wear or replacement.
16
- 2. Landscaping: Identify maturity or neglect.
17
- 3. Exterior: Check paint and siding condition.
18
-
19
- Conclude with a 'Maintenance Trajectory': IMPROVING, STABLE, or DECLINING.
20
  """
21
 
22
  try:
23
- # Call the Robotics-ER 1.5 preview model
24
  response = client.models.generate_content(
25
  model="gemini-robotics-er-1.5-preview",
26
  contents=[prompt, past_img, present_img]
@@ -29,18 +29,24 @@ def ground_truth_audit(past_img, present_img):
29
  except Exception as e:
30
  return f"## Analysis Failed\n{str(e)}"
31
 
32
- # The Interface class is the 'Architectural Safe Mode' for Gradio
33
- demo = gr.Interface(
34
- fn=ground_truth_audit,
35
- inputs=[
36
- gr.Image(label="Past Condition", type="pil"),
37
- gr.Image(label="Present Condition", type="pil")
38
- ],
39
- outputs=gr.Markdown(),
40
- title="GroundTruth AI",
41
- description="Spatial Property Analysis via Gemini Robotics-ER 1.5",
42
- theme="default"
43
- )
 
 
 
 
 
 
44
 
45
- if __name__ == "__main__":
46
- demo.launch()
 
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]
 
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()