Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,26 +3,35 @@ from google import genai
|
|
| 3 |
import os
|
| 4 |
from PIL import Image
|
| 5 |
|
| 6 |
-
def
|
| 7 |
-
|
|
|
|
|
|
|
|
|
|
| 8 |
api_key = os.environ.get("GOOGLE_API_KEY")
|
| 9 |
if not api_key:
|
| 10 |
-
return "## Error\nAPI Key missing. Please
|
| 11 |
|
| 12 |
-
# Initialize the
|
| 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
|
| 17 |
|
|
|
|
| 18 |
prompt = """
|
| 19 |
Perform a high-fidelity structural audit comparing these two images.
|
| 20 |
-
|
| 21 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 22 |
"""
|
| 23 |
|
| 24 |
try:
|
| 25 |
-
#
|
| 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 |
-
#
|
| 37 |
-
#
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
submit_btn.click(
|
| 52 |
-
fn=analyze_property,
|
| 53 |
-
inputs=[past_input, present_input],
|
| 54 |
-
outputs=output_text
|
| 55 |
-
)
|
| 56 |
|
| 57 |
-
|
| 58 |
-
|
|
|
|
|
|
| 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()
|