Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,62 +1,46 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from google import genai
|
| 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 "##
|
| 14 |
|
| 15 |
-
# Initialize the new SDK client
|
| 16 |
client = genai.Client(api_key=api_key)
|
| 17 |
|
| 18 |
-
|
| 19 |
-
return "Error: Please upload both 'Past' and 'Present' images."
|
| 20 |
-
|
| 21 |
-
# Robotics-specific prompt for spatial reasoning
|
| 22 |
prompt = """
|
| 23 |
-
Perform a
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
3. Exterior Envelope (paint, siding, window fixtures)
|
| 28 |
|
| 29 |
-
|
| 30 |
-
Include specific physical evidence for your conclusion.
|
| 31 |
"""
|
| 32 |
|
| 33 |
try:
|
| 34 |
-
#
|
| 35 |
response = client.models.generate_content(
|
| 36 |
model="gemini-robotics-er-1.5-preview",
|
| 37 |
contents=[prompt, past_img, present_img]
|
| 38 |
)
|
| 39 |
-
|
| 40 |
return response.text
|
| 41 |
-
|
| 42 |
except Exception as e:
|
| 43 |
return f"## Analysis Failed\n{str(e)}"
|
| 44 |
|
| 45 |
-
#
|
| 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
|
| 51 |
-
gr.Image(label="Present Condition
|
| 52 |
],
|
| 53 |
outputs=gr.Markdown(),
|
| 54 |
-
title="
|
| 55 |
-
description="
|
| 56 |
-
theme="
|
| 57 |
-
allow_flagging="never"
|
| 58 |
)
|
| 59 |
|
| 60 |
if __name__ == "__main__":
|
| 61 |
-
|
| 62 |
-
demo.queue().launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
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: GOOGLE_API_KEY not found in Space Secrets."
|
| 9 |
|
|
|
|
| 10 |
client = genai.Client(api_key=api_key)
|
| 11 |
|
| 12 |
+
# Robotics-ER 1.5 requires precise prompts for spatial reasoning
|
|
|
|
|
|
|
|
|
|
| 13 |
prompt = """
|
| 14 |
+
Perform a structural audit comparing these two images.
|
| 15 |
+
1. Roofing & Gutters: Look for shingle wear or replacement.
|
| 16 |
+
2. Landscaping: Identify maturity or neglect.
|
| 17 |
+
3. Exterior: Check paint and siding condition.
|
|
|
|
| 18 |
|
| 19 |
+
Conclude with a 'Maintenance Trajectory': IMPROVING, STABLE, or DECLINING.
|
|
|
|
| 20 |
"""
|
| 21 |
|
| 22 |
try:
|
| 23 |
+
# Call the Robotics-ER 1.5 preview model
|
| 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"## Analysis Failed\n{str(e)}"
|
| 31 |
|
| 32 |
+
# The Interface class is the 'Architectural Safe Mode' for Gradio
|
|
|
|
| 33 |
demo = gr.Interface(
|
| 34 |
fn=ground_truth_audit,
|
| 35 |
inputs=[
|
| 36 |
+
gr.Image(label="Past Condition", type="pil"),
|
| 37 |
+
gr.Image(label="Present Condition", type="pil")
|
| 38 |
],
|
| 39 |
outputs=gr.Markdown(),
|
| 40 |
+
title="GroundTruth AI",
|
| 41 |
+
description="Spatial Property Analysis via Gemini Robotics-ER 1.5",
|
| 42 |
+
theme="default"
|
|
|
|
| 43 |
)
|
| 44 |
|
| 45 |
if __name__ == "__main__":
|
| 46 |
+
demo.launch()
|
|
|