grixelle commited on
Commit
b949118
·
verified ·
1 Parent(s): d74e040

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +37 -34
app.py CHANGED
@@ -1,61 +1,64 @@
1
  import gradio as gr
2
  import google.generativeai as genai
3
  import os
4
- from PIL import Image
5
 
6
- # --- Configuration ---
7
- # You'll set this 'GOOGLE_API_KEY' secret in the Settings tab later
8
- api_key = os.environ.get("GOOGLE_API_KEY")
9
- if api_key:
10
- genai.configure(api_key=api_key)
11
-
12
- def analyze_property(past_img, present_img):
13
  if not api_key:
14
- return "## Error\nAPI Key not configured. Please add GOOGLE_API_KEY to your Space Secrets."
 
 
15
 
16
  if past_img is None or present_img is None:
17
- return "Please upload both images to begin the analysis."
 
18
 
19
- # Initialize the Robotics-ER 1.5 model for spatial/temporal reasoning
 
20
  model = genai.GenerativeModel("gemini-robotics-er-1.5-preview")
21
 
22
  prompt = """
23
- You are an expert structural analyst. Compare these two images of the same property.
24
- Focus on:
25
- 1. Roofing & Gutters (wear, replacement, sagging)
26
- 2. Landscaping (maturity, maintenance, overgrowth)
27
- 3. Exterior Envelope (paint condition, siding, updated fixtures)
28
-
29
- Determine the Maintenance Trajectory: IMPROVING, DECLINING, or STABLE.
30
  """
31
-
32
- # Send both images to the VLM for temporal reasoning
33
- response = model.generate_content([prompt, past_img, present_img])
34
- return response.text
35
 
36
- # --- Custom UI Layout ---
 
 
 
 
 
 
 
 
 
 
 
37
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
38
  gr.Markdown("# 🏠 GroundTruth: Temporal Property Sentinel")
39
- gr.Markdown("### Powered by Google Gemini Robotics-ER 1.5")
40
- gr.Markdown("Identify 'Pride of Ownership' and structural changes across time using advanced spatial AI.")
41
 
42
  with gr.Row():
43
  with gr.Column():
44
- past_input = gr.Image(label="Past Condition (e.g., 2020)", type="pil")
45
- present_input = gr.Image(label="Present Condition (e.g., 2026)", type="pil")
 
46
  submit_btn = gr.Button("Analyze Structural Trajectory", variant="primary")
47
 
48
  with gr.Column():
49
- output_text = gr.Markdown(label="Analysis Results")
50
 
 
51
  submit_btn.click(
52
  fn=analyze_property,
53
  inputs=[past_input, present_input],
54
- outputs=output_text
 
55
  )
56
 
57
- gr.Markdown("---")
58
- gr.Markdown("*Licensed under Apache 2.0. Built for Real Estate Professionals.*")
59
-
60
- if __name__ == "__main__":
61
- demo.launch()
 
1
  import gradio as gr
2
  import google.generativeai as genai
3
  import os
4
+ import time
5
 
6
+ def analyze_property(past_img, present_img, progress=gr.Progress()):
7
+ # 1. Immediate Visual Feedback
8
+ gr.Info("GroundTruth is initializing the Robotics-ER engine...")
9
+ progress(0, desc="Authenticating API...")
10
+
11
+ api_key = os.environ.get("GOOGLE_API_KEY")
 
12
  if not api_key:
13
+ raise gr.Error("API Key missing! Add it to 'Secrets' in Settings.")
14
+
15
+ genai.configure(api_key=api_key)
16
 
17
  if past_img is None or present_img is None:
18
+ gr.Warning("Both images are required for temporal analysis.")
19
+ return "Please upload both images."
20
 
21
+ # 2. Update Progress Bar
22
+ progress(0.2, desc="Uploading images to Google Robotics-ER 1.5...")
23
  model = genai.GenerativeModel("gemini-robotics-er-1.5-preview")
24
 
25
  prompt = """
26
+ Perform a high-fidelity structural audit comparing these two images.
27
+ Identify changes in roofing, landscaping, and exterior condition.
28
+ Provide a 'Maintenance Trajectory' (IMPROVING/STABLE/DECLINING).
 
 
 
 
29
  """
 
 
 
 
30
 
31
+ try:
32
+ progress(0.5, desc="AI is reasoning spatially... (10-20 seconds typical)")
33
+ # The model call is synchronous and waits here
34
+ response = model.generate_content([prompt, past_img, present_img])
35
+
36
+ progress(1.0, desc="Analysis complete!")
37
+ return response.text
38
+
39
+ except Exception as e:
40
+ raise gr.Error(f"Analysis failed: {str(e)}")
41
+
42
+ # --- UI Setup ---
43
  with gr.Blocks(theme=gr.themes.Soft()) as demo:
44
  gr.Markdown("# 🏠 GroundTruth: Temporal Property Sentinel")
 
 
45
 
46
  with gr.Row():
47
  with gr.Column():
48
+ past_input = gr.Image(label="Past Condition", type="pil")
49
+ present_input = gr.Image(label="Present Condition", type="pil")
50
+ # show_progress="full" ensures the spinner stays visible
51
  submit_btn = gr.Button("Analyze Structural Trajectory", variant="primary")
52
 
53
  with gr.Column():
54
+ output_text = gr.Markdown(label="Structural Audit Report")
55
 
56
+ # Important: .queue() is required for gr.Progress to work
57
  submit_btn.click(
58
  fn=analyze_property,
59
  inputs=[past_input, present_input],
60
+ outputs=output_text,
61
+ show_progress="full"
62
  )
63
 
64
+ demo.queue().launch()