Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,64 +1,58 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
|
| 3 |
import os
|
| 4 |
-
import
|
| 5 |
|
| 6 |
-
def analyze_property(past_img, present_img
|
| 7 |
-
#
|
| 8 |
-
gr.Info("GroundTruth is initializing the Robotics-ER engine...")
|
| 9 |
-
progress(0, desc="Authenticating API...")
|
| 10 |
-
|
| 11 |
api_key = os.environ.get("GOOGLE_API_KEY")
|
| 12 |
if not api_key:
|
| 13 |
-
|
| 14 |
|
| 15 |
-
genai
|
|
|
|
| 16 |
|
| 17 |
if past_img is None or present_img is None:
|
| 18 |
-
|
| 19 |
-
return "Please upload both images."
|
| 20 |
|
| 21 |
-
# 2. Update Progress Bar
|
| 22 |
-
progress(0.2, desc="Uploading images to Google Robotics-ER 1.5...")
|
| 23 |
-
model = genai.GenerativeModel("gemini-robotics-er-1.5-preview")
|
| 24 |
-
|
| 25 |
prompt = """
|
| 26 |
Perform a high-fidelity structural audit comparing these two images.
|
| 27 |
Identify changes in roofing, landscaping, and exterior condition.
|
| 28 |
-
|
| 29 |
"""
|
| 30 |
|
| 31 |
try:
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
|
|
|
|
|
|
| 35 |
|
| 36 |
-
progress(1.0, desc="Analysis complete!")
|
| 37 |
return response.text
|
| 38 |
|
| 39 |
except Exception as e:
|
| 40 |
-
|
| 41 |
|
| 42 |
# --- UI Setup ---
|
|
|
|
| 43 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 44 |
gr.Markdown("# 🏠 GroundTruth: Temporal Property Sentinel")
|
|
|
|
| 45 |
|
| 46 |
with gr.Row():
|
| 47 |
with gr.Column():
|
| 48 |
past_input = gr.Image(label="Past Condition", type="pil")
|
| 49 |
present_input = gr.Image(label="Present Condition", type="pil")
|
| 50 |
-
# show_progress="full" ensures the spinner stays visible
|
| 51 |
submit_btn = gr.Button("Analyze Structural Trajectory", variant="primary")
|
| 52 |
|
| 53 |
with gr.Column():
|
| 54 |
output_text = gr.Markdown(label="Structural Audit Report")
|
| 55 |
|
| 56 |
-
# Important: .queue() is required for gr.Progress to work
|
| 57 |
submit_btn.click(
|
| 58 |
fn=analyze_property,
|
| 59 |
inputs=[past_input, present_input],
|
| 60 |
-
outputs=output_text
|
| 61 |
-
show_progress="full"
|
| 62 |
)
|
| 63 |
|
|
|
|
| 64 |
demo.queue().launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from google import genai
|
| 3 |
import os
|
| 4 |
+
from PIL import Image
|
| 5 |
|
| 6 |
+
def analyze_property(past_img, present_img):
|
| 7 |
+
# Retrieve the API Key from Secrets
|
|
|
|
|
|
|
|
|
|
| 8 |
api_key = os.environ.get("GOOGLE_API_KEY")
|
| 9 |
if not api_key:
|
| 10 |
+
return "## Error\nAPI Key missing. Please add GOOGLE_API_KEY to your Space Secrets."
|
| 11 |
|
| 12 |
+
# Initialize the NEW google-genai client
|
| 13 |
+
client = genai.Client(api_key=api_key)
|
| 14 |
|
| 15 |
if past_img is None or present_img is None:
|
| 16 |
+
return "Please upload both images to begin."
|
|
|
|
| 17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
prompt = """
|
| 19 |
Perform a high-fidelity structural audit comparing these two images.
|
| 20 |
Identify changes in roofing, landscaping, and exterior condition.
|
| 21 |
+
Determine the Maintenance Trajectory: IMPROVING, DECLINING, or STABLE.
|
| 22 |
"""
|
| 23 |
|
| 24 |
try:
|
| 25 |
+
# Using the new google-genai SDK format
|
| 26 |
+
response = client.models.generate_content(
|
| 27 |
+
model="gemini-robotics-er-1.5-preview",
|
| 28 |
+
contents=[prompt, past_img, present_img]
|
| 29 |
+
)
|
| 30 |
|
|
|
|
| 31 |
return response.text
|
| 32 |
|
| 33 |
except Exception as e:
|
| 34 |
+
return f"## Analysis Failed\n{str(e)}"
|
| 35 |
|
| 36 |
# --- UI Setup ---
|
| 37 |
+
# Simplifying the Block structure to resolve the Gradio schema error
|
| 38 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 39 |
gr.Markdown("# 🏠 GroundTruth: Temporal Property Sentinel")
|
| 40 |
+
gr.Markdown("Identify 'Pride of Ownership' and structural changes across time.")
|
| 41 |
|
| 42 |
with gr.Row():
|
| 43 |
with gr.Column():
|
| 44 |
past_input = gr.Image(label="Past Condition", type="pil")
|
| 45 |
present_input = gr.Image(label="Present Condition", type="pil")
|
|
|
|
| 46 |
submit_btn = gr.Button("Analyze Structural Trajectory", variant="primary")
|
| 47 |
|
| 48 |
with gr.Column():
|
| 49 |
output_text = gr.Markdown(label="Structural Audit Report")
|
| 50 |
|
|
|
|
| 51 |
submit_btn.click(
|
| 52 |
fn=analyze_property,
|
| 53 |
inputs=[past_input, present_input],
|
| 54 |
+
outputs=output_text
|
|
|
|
| 55 |
)
|
| 56 |
|
| 57 |
+
# The queue is still needed for stable performance on Hugging Face
|
| 58 |
demo.queue().launch()
|