grixelle commited on
Commit
d346d55
·
verified ·
1 Parent(s): 92d5279

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -24
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="Initializing Spatial Engine...")
7
 
8
  api_key = os.environ.get("GOOGLE_API_KEY")
9
  if not api_key:
10
- return "ERROR: Set GOOGLE_API_KEY in Space 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
- # Directives updated to request normalized coordinates (0-1000)
17
  audit_directives = {
18
- "Quick Scan": "Perform a rapid structural overview.",
19
- "Standard Audit": "Compare roofing, landscaping, and exterior siding.",
20
  "Deep Forensic": """Perform an exhaustive spatial audit.
21
- For the 3 most significant structural changes, identify their center points
22
- using normalized [y, x] coordinates (0-1000).
23
- Identify subtle shingle wear, foundation cracks, and biological encroachment."""
24
  }
25
 
26
- selected_directive = audit_directives.get(audit_level, audit_directives["Standard Audit"])
27
- progress(0.2, desc=f"Mode: {audit_level}")
28
 
29
  prompt = f"""
30
- SYSTEM INSTRUCTION: You are a forensic structural appraiser using spatial grounding.
31
- DIRECTIVE: {selected_directive}
32
 
33
- TASK: Compare these images.
34
- 1. List the structural findings.
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 calculating spatial points...")
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 Complete!")
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
- audit_slider = gr.Radio(
60
- choices=["Quick Scan", "Standard Audit", "Deep Forensic"],
 
 
61
  value="Standard Audit",
62
- label="Audit Depth"
63
  )
64
- submit = gr.Button("Analyze Structural Trajectory", variant="primary")
65
 
66
  with gr.Column():
67
- output = gr.Markdown(label="Forensic Audit Report")
68
 
69
  submit.click(
70
  fn=ground_truth_engine,
71
- inputs=[p_img, c_img, audit_slider],
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
  )