grixelle commited on
Commit
361c800
·
verified ·
1 Parent(s): 13165d7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -30
app.py CHANGED
@@ -3,26 +3,35 @@ from google import genai
3
  import os
4
  from PIL import Image
5
 
6
- def analyze_property(past_img, present_img):
7
- # Retrieve the API Key from Secrets
 
 
 
8
  api_key = os.environ.get("GOOGLE_API_KEY")
9
  if not api_key:
10
- return "## Error\nAPI Key missing. Please add GOOGLE_API_KEY to your Space Secrets."
11
 
12
- # Initialize the NEW google-genai client
13
  client = genai.Client(api_key=api_key)
14
 
15
  if past_img is None or present_img is None:
16
- return "Please upload both images to begin."
17
 
 
18
  prompt = """
19
  Perform a high-fidelity structural audit comparing these two images.
20
- Identify changes in roofing, landscaping, and exterior condition.
21
- Determine the Maintenance Trajectory: IMPROVING, DECLINING, or STABLE.
 
 
 
 
 
22
  """
23
 
24
  try:
25
- # Using the new google-genai SDK format
26
  response = client.models.generate_content(
27
  model="gemini-robotics-er-1.5-preview",
28
  contents=[prompt, past_img, present_img]
@@ -33,26 +42,21 @@ def analyze_property(past_img, present_img):
33
  except Exception as e:
34
  return f"## Analysis Failed\n{str(e)}"
35
 
36
- # --- UI Setup ---
37
- # Simplifying the Block structure to resolve the Gradio schema error
38
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
39
- gr.Markdown("# 🏠 GroundTruth: Temporal Property Sentinel")
40
- gr.Markdown("Identify 'Pride of Ownership' and structural changes across time.")
41
-
42
- with gr.Row():
43
- with gr.Column():
44
- past_input = gr.Image(label="Past Condition", type="pil")
45
- present_input = gr.Image(label="Present Condition", type="pil")
46
- submit_btn = gr.Button("Analyze Structural Trajectory", variant="primary")
47
-
48
- with gr.Column():
49
- output_text = gr.Markdown(label="Structural Audit Report")
50
-
51
- submit_btn.click(
52
- fn=analyze_property,
53
- inputs=[past_input, present_input],
54
- outputs=output_text
55
- )
56
 
57
- # The queue is still needed for stable performance on Hugging Face
58
- demo.queue().launch()
 
 
3
  import os
4
  from PIL import Image
5
 
6
+ def ground_truth_audit(past_img, present_img):
7
+ """
8
+ Forensic structural audit using Gemini Robotics-ER 1.5.
9
+ Uses the new google-genai SDK for stability.
10
+ """
11
  api_key = os.environ.get("GOOGLE_API_KEY")
12
  if not api_key:
13
+ return "## Configuration Error\nAPI Key missing. Please set GOOGLE_API_KEY in Space Secrets."
14
 
15
+ # Initialize the new SDK client
16
  client = genai.Client(api_key=api_key)
17
 
18
  if past_img is None or present_img is None:
19
+ return "Error: Please upload both 'Past' and 'Present' images."
20
 
21
+ # Robotics-specific prompt for spatial reasoning
22
  prompt = """
23
  Perform a high-fidelity structural audit comparing these two images.
24
+ Focus on:
25
+ 1. Roofing & Gutters (wear, shingle quality, replacement evidence)
26
+ 2. Landscaping (maturity, maintenance, or invasive overgrowth)
27
+ 3. Exterior Envelope (paint, siding, window fixtures)
28
+
29
+ Output a 'Maintenance Trajectory' as: IMPROVING, DECLINING, or STABLE.
30
+ Include specific physical evidence for your conclusion.
31
  """
32
 
33
  try:
34
+ # Generate content using the Robotics-ER preview model
35
  response = client.models.generate_content(
36
  model="gemini-robotics-er-1.5-preview",
37
  contents=[prompt, past_img, present_img]
 
42
  except Exception as e:
43
  return f"## Analysis Failed\n{str(e)}"
44
 
45
+ # Define the Interface for maximum stability
46
+ # gr.Interface handles the side-by-side layout and 'Analyze' button automatically
47
+ demo = gr.Interface(
48
+ fn=ground_truth_audit,
49
+ inputs=[
50
+ gr.Image(label="Past Condition (Historical)", type="pil"),
51
+ gr.Image(label="Present Condition (Current)", type="pil")
52
+ ],
53
+ outputs=gr.Markdown(),
54
+ title="🏠 GroundTruth: Temporal Property Sentinel",
55
+ description="Powered by Gemini Robotics-ER 1.5. A forensic engine for tracking property 'Pride of Ownership' over time.",
56
+ theme="soft",
57
+ allow_flagging="never"
58
+ )
 
 
 
 
 
 
59
 
60
+ if __name__ == "__main__":
61
+ # Enabling queue ensures the server can handle the 10-20s latency
62
+ demo.queue().launch()