Spaces:
Sleeping
Sleeping
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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()
|