Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from google import genai
|
| 3 |
import os
|
|
|
|
| 4 |
|
| 5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
-
# Initialize the new SDK client
|
| 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 high-fidelity structural audit comparing these two images.
|
| 18 |
Focus on changes in roofing, landscaping, and exterior condition.
|
|
@@ -20,18 +27,22 @@ def ground_truth_engine(past_img, present_img):
|
|
| 20 |
"""
|
| 21 |
|
| 22 |
try:
|
|
|
|
|
|
|
|
|
|
| 23 |
response = client.models.generate_content(
|
| 24 |
model="gemini-robotics-er-1.5-preview",
|
| 25 |
contents=[prompt, past_img, present_img]
|
| 26 |
)
|
|
|
|
|
|
|
| 27 |
return response.text
|
| 28 |
except Exception as e:
|
| 29 |
return f"Analysis Failed: {str(e)}"
|
| 30 |
|
| 31 |
-
#
|
| 32 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 33 |
gr.Markdown("# 🏠 GroundTruth AI (Stable Build)")
|
| 34 |
-
gr.Markdown("Temporal Property Sentinel powered by Gemini Robotics-ER 1.5")
|
| 35 |
|
| 36 |
with gr.Row():
|
| 37 |
with gr.Column():
|
|
@@ -42,8 +53,14 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 42 |
with gr.Column():
|
| 43 |
output = gr.Markdown(label="Audit Report")
|
| 44 |
|
| 45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 46 |
|
| 47 |
if __name__ == "__main__":
|
| 48 |
-
#
|
| 49 |
-
demo.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from google import genai
|
| 3 |
import os
|
| 4 |
+
import time
|
| 5 |
|
| 6 |
+
# We add 'progress=gr.Progress()' as an argument to enable the status bar
|
| 7 |
+
def ground_truth_engine(past_img, present_img, progress=gr.Progress()):
|
| 8 |
+
# 1. Immediate Visual Feedback
|
| 9 |
+
progress(0, desc="Initializing Spatial Engine...")
|
| 10 |
+
|
| 11 |
api_key = os.environ.get("GOOGLE_API_KEY")
|
| 12 |
if not api_key:
|
| 13 |
return "ERROR: GOOGLE_API_KEY not found in Space Secrets."
|
| 14 |
|
|
|
|
| 15 |
client = genai.Client(api_key=api_key)
|
| 16 |
|
| 17 |
if past_img is None or present_img is None:
|
| 18 |
return "Please upload both images."
|
| 19 |
|
| 20 |
+
# 2. Update status before the heavy lifting
|
| 21 |
+
progress(0.3, desc="Uploading Images to Gemini...")
|
| 22 |
+
|
| 23 |
prompt = """
|
| 24 |
Perform a high-fidelity structural audit comparing these two images.
|
| 25 |
Focus on changes in roofing, landscaping, and exterior condition.
|
|
|
|
| 27 |
"""
|
| 28 |
|
| 29 |
try:
|
| 30 |
+
# 3. Setting expectation for the 'Thinking' phase
|
| 31 |
+
progress(0.6, desc="Reasoning Spatially (This takes ~20-30s)...")
|
| 32 |
+
|
| 33 |
response = client.models.generate_content(
|
| 34 |
model="gemini-robotics-er-1.5-preview",
|
| 35 |
contents=[prompt, past_img, present_img]
|
| 36 |
)
|
| 37 |
+
|
| 38 |
+
progress(1.0, desc="Audit Complete!")
|
| 39 |
return response.text
|
| 40 |
except Exception as e:
|
| 41 |
return f"Analysis Failed: {str(e)}"
|
| 42 |
|
| 43 |
+
# --- UI Setup ---
|
| 44 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 45 |
gr.Markdown("# 🏠 GroundTruth AI (Stable Build)")
|
|
|
|
| 46 |
|
| 47 |
with gr.Row():
|
| 48 |
with gr.Column():
|
|
|
|
| 53 |
with gr.Column():
|
| 54 |
output = gr.Markdown(label="Audit Report")
|
| 55 |
|
| 56 |
+
# Important: show_progress="full" ensures the spinner stays visible
|
| 57 |
+
submit.click(
|
| 58 |
+
fn=ground_truth_engine,
|
| 59 |
+
inputs=[p_img, c_img],
|
| 60 |
+
outputs=output,
|
| 61 |
+
show_progress="full"
|
| 62 |
+
)
|
| 63 |
|
| 64 |
if __name__ == "__main__":
|
| 65 |
+
# Ensure queue is enabled for progress bar to update
|
| 66 |
+
demo.queue().launch(server_name="0.0.0.0", server_port=7860)
|