SM737 commited on
Commit
918f71e
·
verified ·
1 Parent(s): 143b78c

Clean Gradio ZeroGPU probe with traceback logging

Browse files
Files changed (1) hide show
  1. app.py +9 -48
app.py CHANGED
@@ -35,7 +35,7 @@ from app.main import app # noqa: E402
35
  try:
36
  import gradio as gr
37
 
38
- @spaces.GPU(duration=60)
39
  def gpu_probe_check(probe_text: str = "health"):
40
  import torch
41
  cuda_avail = torch.cuda.is_available()
@@ -47,31 +47,6 @@ try:
47
  "probe": probe_text,
48
  }
49
 
50
- @spaces.GPU(duration=180)
51
- async def gradio_run_analysis(query: str, image_file):
52
- if not image_file:
53
- return {"error": "Please provide an image file (GeoTIFF, TIFF, PNG, or JPG)."}
54
- from app.services.ingestion import prepare_source
55
- from app.services.integrated_analysis import analyze
56
-
57
- result_id = str(uuid.uuid4())
58
- output_dir = Path("artifacts") / result_id
59
- output_dir.mkdir(parents=True, exist_ok=True)
60
- try:
61
- dest = output_dir / f"input_a{Path(image_file).suffix.lower() or '.tif'}"
62
- shutil.copy(image_file, dest)
63
- prepared = prepare_source(dest, output_dir / "prepared_1").raster_path
64
- response = await analyze(
65
- result_id=result_id,
66
- query=query or "Analyze surface features and land cover",
67
- pair_type="auto",
68
- image_paths=[prepared],
69
- output_dir=output_dir,
70
- )
71
- return response.model_dump(mode="json")
72
- except Exception as exc:
73
- return {"error": str(exc)}
74
-
75
  with gr.Blocks(title="SatQuery GeoProof API") as demo:
76
  gr.Markdown(
77
  "# 🛰️ SatQuery GeoProof - Space Runner\n"
@@ -79,31 +54,17 @@ try:
79
  "- **API Endpoints**: `/api/v1/analyze`, `/health`, `/api/v1/models`\n"
80
  "- **Interactive Swagger Docs**: [`/docs`](/docs)"
81
  )
82
- with gr.Tab("Hardware & Health Status"):
83
- with gr.Row():
84
- probe_in = gr.Textbox(label="Probe Ping", value="ZeroGPU Ready", placeholder="Status check...")
85
- probe_out = gr.JSON(label="Hardware Info")
86
- probe_btn = gr.Button("Test GPU Allocation", variant="primary")
87
- probe_btn.click(fn=gpu_probe_check, inputs=[probe_in], outputs=[probe_out])
88
-
89
- with gr.Tab("Direct Satellite Analysis"):
90
- with gr.Row():
91
- with gr.Column():
92
- img_in = gr.Image(type="filepath", label="Upload Satellite / Aerial Image")
93
- q_in = gr.Textbox(
94
- label="Analysis Query",
95
- value="Detect water bodies and surface land cover",
96
- placeholder="e.g. Detect surface water bodies...",
97
- )
98
- run_btn = gr.Button("Run Analysis (ZeroGPU)", variant="primary")
99
- with gr.Column():
100
- res_out = gr.JSON(label="Analysis Result")
101
- run_btn.click(fn=gradio_run_analysis, inputs=[q_in, img_in], outputs=[res_out])
102
 
103
- demo.queue()
104
  app = gr.mount_gradio_app(app, demo, path="/")
105
  except Exception as exc:
106
- print(f"Gradio setup failed: {exc}")
 
 
107
 
108
 
109
  if __name__ == "__main__":
 
35
  try:
36
  import gradio as gr
37
 
38
+ @spaces.GPU
39
  def gpu_probe_check(probe_text: str = "health"):
40
  import torch
41
  cuda_avail = torch.cuda.is_available()
 
47
  "probe": probe_text,
48
  }
49
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
50
  with gr.Blocks(title="SatQuery GeoProof API") as demo:
51
  gr.Markdown(
52
  "# 🛰️ SatQuery GeoProof - Space Runner\n"
 
54
  "- **API Endpoints**: `/api/v1/analyze`, `/health`, `/api/v1/models`\n"
55
  "- **Interactive Swagger Docs**: [`/docs`](/docs)"
56
  )
57
+ with gr.Row():
58
+ probe_in = gr.Textbox(label="Probe Ping", value="ZeroGPU Ready", placeholder="Status check...")
59
+ probe_out = gr.JSON(label="Hardware Info")
60
+ probe_btn = gr.Button("Test GPU Allocation", variant="primary")
61
+ probe_btn.click(fn=gpu_probe_check, inputs=[probe_in], outputs=[probe_out])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
62
 
 
63
  app = gr.mount_gradio_app(app, demo, path="/")
64
  except Exception as exc:
65
+ import traceback
66
+ print("Gradio setup failed with exception:")
67
+ traceback.print_exc()
68
 
69
 
70
  if __name__ == "__main__":