Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,61 +1,64 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import google.generativeai as genai
|
| 3 |
import os
|
| 4 |
-
|
| 5 |
|
| 6 |
-
|
| 7 |
-
#
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def analyze_property(past_img, present_img):
|
| 13 |
if not api_key:
|
| 14 |
-
|
|
|
|
|
|
|
| 15 |
|
| 16 |
if past_img is None or present_img is None:
|
| 17 |
-
|
|
|
|
| 18 |
|
| 19 |
-
#
|
|
|
|
| 20 |
model = genai.GenerativeModel("gemini-robotics-er-1.5-preview")
|
| 21 |
|
| 22 |
prompt = """
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 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 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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
|
| 45 |
-
present_input = gr.Image(label="Present Condition
|
|
|
|
| 46 |
submit_btn = gr.Button("Analyze Structural Trajectory", variant="primary")
|
| 47 |
|
| 48 |
with gr.Column():
|
| 49 |
-
output_text = gr.Markdown(label="
|
| 50 |
|
|
|
|
| 51 |
submit_btn.click(
|
| 52 |
fn=analyze_property,
|
| 53 |
inputs=[past_input, present_input],
|
| 54 |
-
outputs=output_text
|
|
|
|
| 55 |
)
|
| 56 |
|
| 57 |
-
|
| 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()
|
|
|
|
|
|
|
|
|
|
|
|