Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,48 +3,44 @@ from google import genai
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
def ground_truth_engine(past_img, present_img, audit_level, progress=gr.Progress()):
|
| 6 |
-
progress(0, desc="
|
| 7 |
|
| 8 |
api_key = os.environ.get("GOOGLE_API_KEY")
|
| 9 |
if not api_key:
|
| 10 |
-
return "ERROR: Set GOOGLE_API_KEY in
|
| 11 |
|
| 12 |
client = genai.Client(api_key=api_key)
|
| 13 |
if past_img is None or present_img is None:
|
| 14 |
return "Please upload both images."
|
| 15 |
|
| 16 |
-
#
|
| 17 |
audit_directives = {
|
| 18 |
-
"
|
| 19 |
-
"Standard Audit": "Compare roofing, landscaping, and exterior siding.",
|
| 20 |
"Deep Forensic": """Perform an exhaustive spatial audit.
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
Identify subtle shingle wear, foundation cracks, and biological encroachment."""
|
| 24 |
}
|
| 25 |
|
| 26 |
-
|
| 27 |
-
progress(0.2, desc=f"
|
| 28 |
|
| 29 |
prompt = f"""
|
| 30 |
-
SYSTEM INSTRUCTION: You are a
|
| 31 |
-
DIRECTIVE: {
|
| 32 |
|
| 33 |
-
TASK: Compare
|
| 34 |
-
|
| 35 |
-
2. Provide the [y, x] coordinates for points of interest if in Deep Forensic mode.
|
| 36 |
-
3. Conclude with 'Maintenance Trajectory': IMPROVING, STABLE, or DECLINING.
|
| 37 |
"""
|
| 38 |
|
| 39 |
try:
|
| 40 |
-
progress(0.5, desc="Robotics-ER is
|
| 41 |
|
| 42 |
response = client.models.generate_content(
|
| 43 |
model="gemini-robotics-er-1.5-preview",
|
| 44 |
contents=[prompt, past_img, present_img]
|
| 45 |
)
|
| 46 |
|
| 47 |
-
progress(1.0, desc="Audit
|
| 48 |
return response.text
|
| 49 |
except Exception as e:
|
| 50 |
return f"Analysis Failed: {str(e)}"
|
|
@@ -56,19 +52,21 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 56 |
with gr.Column():
|
| 57 |
p_img = gr.Image(label="Past Condition", type="pil")
|
| 58 |
c_img = gr.Image(label="Current Condition", type="pil")
|
| 59 |
-
|
| 60 |
-
|
|
|
|
|
|
|
| 61 |
value="Standard Audit",
|
| 62 |
-
label="Audit
|
| 63 |
)
|
| 64 |
-
submit = gr.Button("Analyze
|
| 65 |
|
| 66 |
with gr.Column():
|
| 67 |
-
output = gr.Markdown(label="Forensic
|
| 68 |
|
| 69 |
submit.click(
|
| 70 |
fn=ground_truth_engine,
|
| 71 |
-
inputs=[p_img, c_img,
|
| 72 |
outputs=output,
|
| 73 |
show_progress="full"
|
| 74 |
)
|
|
|
|
| 3 |
import os
|
| 4 |
|
| 5 |
def ground_truth_engine(past_img, present_img, audit_level, progress=gr.Progress()):
|
| 6 |
+
progress(0, desc="Waking Spatial Sentinel...")
|
| 7 |
|
| 8 |
api_key = os.environ.get("GOOGLE_API_KEY")
|
| 9 |
if not api_key:
|
| 10 |
+
return "ERROR: Set GOOGLE_API_KEY in Secrets."
|
| 11 |
|
| 12 |
client = genai.Client(api_key=api_key)
|
| 13 |
if past_img is None or present_img is None:
|
| 14 |
return "Please upload both images."
|
| 15 |
|
| 16 |
+
# Simplified Directives
|
| 17 |
audit_directives = {
|
| 18 |
+
"Standard Audit": "Perform a structural comparison of roofing, siding, and landscaping.",
|
|
|
|
| 19 |
"Deep Forensic": """Perform an exhaustive spatial audit.
|
| 20 |
+
Identify subtle wear (shingles, foundation, paint) and biological encroachment.
|
| 21 |
+
MANDATORY: Return center points for top 3 changes as [y, x] normalized coordinates (0-1000)."""
|
|
|
|
| 22 |
}
|
| 23 |
|
| 24 |
+
directive = audit_directives.get(audit_level)
|
| 25 |
+
progress(0.2, desc=f"Running {audit_level}...")
|
| 26 |
|
| 27 |
prompt = f"""
|
| 28 |
+
SYSTEM INSTRUCTION: You are a structural forensic agent.
|
| 29 |
+
DIRECTIVE: {directive}
|
| 30 |
|
| 31 |
+
TASK: Compare 'Past Condition' vs 'Current Condition'.
|
| 32 |
+
Return a structured report with a 'Maintenance Trajectory' (IMPROVING/STABLE/DECLINING).
|
|
|
|
|
|
|
| 33 |
"""
|
| 34 |
|
| 35 |
try:
|
| 36 |
+
progress(0.5, desc="Robotics-ER is scanning for spatial anomalies...")
|
| 37 |
|
| 38 |
response = client.models.generate_content(
|
| 39 |
model="gemini-robotics-er-1.5-preview",
|
| 40 |
contents=[prompt, past_img, present_img]
|
| 41 |
)
|
| 42 |
|
| 43 |
+
progress(1.0, desc="Audit Finalized.")
|
| 44 |
return response.text
|
| 45 |
except Exception as e:
|
| 46 |
return f"Analysis Failed: {str(e)}"
|
|
|
|
| 52 |
with gr.Column():
|
| 53 |
p_img = gr.Image(label="Past Condition", type="pil")
|
| 54 |
c_img = gr.Image(label="Current Condition", type="pil")
|
| 55 |
+
|
| 56 |
+
# Simplified UI to two logical choices
|
| 57 |
+
audit_mode = gr.Radio(
|
| 58 |
+
choices=["Standard Audit", "Deep Forensic"],
|
| 59 |
value="Standard Audit",
|
| 60 |
+
label="Select Audit Precision"
|
| 61 |
)
|
| 62 |
+
submit = gr.Button("Analyze Property Trajectory", variant="primary")
|
| 63 |
|
| 64 |
with gr.Column():
|
| 65 |
+
output = gr.Markdown(label="Forensic Report")
|
| 66 |
|
| 67 |
submit.click(
|
| 68 |
fn=ground_truth_engine,
|
| 69 |
+
inputs=[p_img, c_img, audit_mode],
|
| 70 |
outputs=output,
|
| 71 |
show_progress="full"
|
| 72 |
)
|