Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,24 +3,24 @@ from google import genai
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
def ground_truth_audit(past_img, present_img):
|
|
|
|
| 6 |
api_key = os.environ.get("GOOGLE_API_KEY")
|
| 7 |
if not api_key:
|
| 8 |
-
return "## Error
|
| 9 |
|
| 10 |
client = genai.Client(api_key=api_key)
|
| 11 |
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
prompt = """
|
| 14 |
Perform a structural audit comparing these two images.
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
3. Exterior: Check paint and siding condition.
|
| 18 |
-
|
| 19 |
-
Conclude with a 'Maintenance Trajectory': IMPROVING, STABLE, or DECLINING.
|
| 20 |
"""
|
| 21 |
|
| 22 |
try:
|
| 23 |
-
#
|
| 24 |
response = client.models.generate_content(
|
| 25 |
model="gemini-robotics-er-1.5-preview",
|
| 26 |
contents=[prompt, past_img, present_img]
|
|
@@ -29,18 +29,24 @@ def ground_truth_audit(past_img, present_img):
|
|
| 29 |
except Exception as e:
|
| 30 |
return f"## Analysis Failed\n{str(e)}"
|
| 31 |
|
| 32 |
-
#
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
-
|
| 46 |
-
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
def ground_truth_audit(past_img, present_img):
|
| 6 |
+
"""Explicitly mapped backend function for GroundTruth."""
|
| 7 |
api_key = os.environ.get("GOOGLE_API_KEY")
|
| 8 |
if not api_key:
|
| 9 |
+
return "## Error\nAPI Key not found. Please add GOOGLE_API_KEY to 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 |
prompt = """
|
| 17 |
Perform a structural audit comparing these two images.
|
| 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-ER 1.5 for spatial/temporal analysis
|
| 24 |
response = client.models.generate_content(
|
| 25 |
model="gemini-robotics-er-1.5-preview",
|
| 26 |
contents=[prompt, past_img, present_img]
|
|
|
|
| 29 |
except Exception as e:
|
| 30 |
return f"## Analysis Failed\n{str(e)}"
|
| 31 |
|
| 32 |
+
# Explicitly defining the UI blocks to fix the 'No API found' error
|
| 33 |
+
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 34 |
+
gr.Markdown("# 🏠 GroundTruth AI")
|
| 35 |
+
gr.Markdown("Temporal Property Sentinel powered by Gemini Robotics-ER 1.5")
|
| 36 |
+
|
| 37 |
+
with gr.Row():
|
| 38 |
+
with gr.Column():
|
| 39 |
+
past = gr.Image(label="Past Condition", type="pil")
|
| 40 |
+
present = gr.Image(label="Present Condition", type="pil")
|
| 41 |
+
# Explicitly naming the trigger button
|
| 42 |
+
btn = gr.Button("Analyze Structural Trajectory", variant="primary")
|
| 43 |
+
|
| 44 |
+
with gr.Column():
|
| 45 |
+
# Explicitly naming the output container
|
| 46 |
+
out = gr.Markdown(label="Audit Report")
|
| 47 |
+
|
| 48 |
+
# Manually mapping the click to the API function
|
| 49 |
+
btn.click(fn=ground_truth_audit, inputs=[past, present], outputs=out)
|
| 50 |
|
| 51 |
+
# Mandatory for Gradio 5+ to handle background API processing
|
| 52 |
+
demo.queue().launch()
|