Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,51 +2,44 @@ import gradio as gr
|
|
| 2 |
from google import genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
-
def
|
| 6 |
-
"""
|
| 7 |
api_key = os.environ.get("GOOGLE_API_KEY")
|
| 8 |
if not api_key:
|
| 9 |
-
return "
|
| 10 |
|
| 11 |
client = genai.Client(api_key=api_key)
|
| 12 |
|
| 13 |
if past_img is None or present_img is None:
|
| 14 |
return "Please upload both images."
|
| 15 |
|
| 16 |
-
prompt
|
| 17 |
-
|
| 18 |
-
Look for changes in roofing, landscaping, and exterior condition.
|
| 19 |
-
Provide a 'Maintenance Trajectory': IMPROVING, STABLE, or DECLINING.
|
| 20 |
-
"""
|
| 21 |
|
| 22 |
try:
|
| 23 |
-
# Utilizing Robotics
|
| 24 |
response = client.models.generate_content(
|
| 25 |
model="gemini-robotics-er-1.5-preview",
|
| 26 |
contents=[prompt, past_img, present_img]
|
| 27 |
)
|
| 28 |
return response.text
|
| 29 |
except Exception as e:
|
| 30 |
-
return f"
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
with gr.Blocks(
|
| 34 |
-
gr.
|
| 35 |
-
gr.Markdown("Temporal Property Sentinel powered by Gemini Robotics-ER 1.5")
|
| 36 |
|
| 37 |
with gr.Row():
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
with gr.Column():
|
| 45 |
-
# Explicitly naming the output container
|
| 46 |
-
out = gr.Markdown(label="Audit Report")
|
| 47 |
|
| 48 |
-
#
|
| 49 |
-
|
| 50 |
|
| 51 |
-
#
|
| 52 |
demo.queue().launch()
|
|
|
|
| 2 |
from google import genai
|
| 3 |
import os
|
| 4 |
|
| 5 |
+
def audit_engine(past_img, present_img):
|
| 6 |
+
"""Forensic structural audit logic."""
|
| 7 |
api_key = os.environ.get("GOOGLE_API_KEY")
|
| 8 |
if not api_key:
|
| 9 |
+
return "ERROR: GOOGLE_API_KEY not found in Space Secrets."
|
| 10 |
|
| 11 |
client = genai.Client(api_key=api_key)
|
| 12 |
|
| 13 |
if past_img is None or present_img is None:
|
| 14 |
return "Please upload both images."
|
| 15 |
|
| 16 |
+
# Robotics-ER 1.5 prompt for structural grounding
|
| 17 |
+
prompt = "Compare these images for changes in roofing, landscaping, and exterior condition. Output a 'Maintenance Trajectory': IMPROVING, STABLE, or DECLINING."
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
try:
|
| 20 |
+
# Utilizing the Robotics preview model
|
| 21 |
response = client.models.generate_content(
|
| 22 |
model="gemini-robotics-er-1.5-preview",
|
| 23 |
contents=[prompt, past_img, present_img]
|
| 24 |
)
|
| 25 |
return response.text
|
| 26 |
except Exception as e:
|
| 27 |
+
return f"Analysis Failed: {str(e)}"
|
| 28 |
|
| 29 |
+
# Minimalist Blocks to bypass the 'TypeError: bool' schema bug
|
| 30 |
+
with gr.Blocks() as demo:
|
| 31 |
+
gr.HTML("<h1>🏠 GroundTruth AI</h1>")
|
|
|
|
| 32 |
|
| 33 |
with gr.Row():
|
| 34 |
+
p_img = gr.Image(label="Past Image", type="pil")
|
| 35 |
+
c_img = gr.Image(label="Current Image", type="pil")
|
| 36 |
+
|
| 37 |
+
# Textbox is more stable than Markdown in G5 for schema generation
|
| 38 |
+
output = gr.Textbox(label="Structural Audit Report")
|
| 39 |
+
submit = gr.Button("Analyze Trajectory", variant="primary")
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
+
# Explicit event binding
|
| 42 |
+
submit.click(fn=audit_engine, inputs=[p_img, c_img], outputs=output)
|
| 43 |
|
| 44 |
+
# Queue is essential for the 30s latency of the Robotics model
|
| 45 |
demo.queue().launch()
|