Spaces:
Paused
Paused
Cornelius
commited on
Commit
·
81e0b33
1
Parent(s):
a4ee801
Fix Gradio Progress IndexError in Gradio 4.44.0
Browse files- Removed 'if progress:' checks that cause IndexError
- Wrapped all progress() calls in try/except blocks
- App now gracefully handles progress tracking failures
app.py
CHANGED
|
@@ -33,12 +33,16 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
|
|
| 33 |
import torch
|
| 34 |
if not torch.cuda.is_available():
|
| 35 |
device = "cpu"
|
| 36 |
-
|
| 37 |
progress(0.0, desc="⚠️ GPU not available, using CPU...")
|
|
|
|
|
|
|
| 38 |
except ImportError:
|
| 39 |
device = "cpu"
|
| 40 |
-
|
| 41 |
progress(0.0, desc="⚠️ PyTorch not available, using CPU...")
|
|
|
|
|
|
|
| 42 |
except Exception:
|
| 43 |
device = "cpu"
|
| 44 |
|
|
@@ -58,8 +62,11 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
|
|
| 58 |
cmd.extend(["--seed", str(int(seed))])
|
| 59 |
|
| 60 |
try:
|
| 61 |
-
|
|
|
|
| 62 |
progress(0.1, desc="Starting comparison...")
|
|
|
|
|
|
|
| 63 |
|
| 64 |
# Ensure environment variables are passed to subprocess
|
| 65 |
env = os.environ.copy()
|
|
@@ -80,8 +87,11 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
|
|
| 80 |
# Combine outputs
|
| 81 |
full_output = f"=== STDOUT ===\n{stdout_text}\n\n=== STDERR ===\n{stderr_text}"
|
| 82 |
|
| 83 |
-
|
|
|
|
| 84 |
progress(0.9, desc="Processing results...")
|
|
|
|
|
|
|
| 85 |
|
| 86 |
if result.returncode != 0:
|
| 87 |
return f"❌ Error occurred:\n{full_output}", None
|
|
@@ -100,8 +110,10 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
|
|
| 100 |
break
|
| 101 |
|
| 102 |
if plot_path:
|
| 103 |
-
|
| 104 |
progress(1.0, desc="Complete!")
|
|
|
|
|
|
|
| 105 |
return f"✅ Comparison complete!\n\n{stdout_text}", str(plot_path)
|
| 106 |
else:
|
| 107 |
# Return output even if plot not found (might still be useful)
|
|
|
|
| 33 |
import torch
|
| 34 |
if not torch.cuda.is_available():
|
| 35 |
device = "cpu"
|
| 36 |
+
try:
|
| 37 |
progress(0.0, desc="⚠️ GPU not available, using CPU...")
|
| 38 |
+
except (AttributeError, IndexError, TypeError):
|
| 39 |
+
pass
|
| 40 |
except ImportError:
|
| 41 |
device = "cpu"
|
| 42 |
+
try:
|
| 43 |
progress(0.0, desc="⚠️ PyTorch not available, using CPU...")
|
| 44 |
+
except (AttributeError, IndexError, TypeError):
|
| 45 |
+
pass
|
| 46 |
except Exception:
|
| 47 |
device = "cpu"
|
| 48 |
|
|
|
|
| 62 |
cmd.extend(["--seed", str(int(seed))])
|
| 63 |
|
| 64 |
try:
|
| 65 |
+
# Safe progress update - wrap in try/except for Gradio compatibility
|
| 66 |
+
try:
|
| 67 |
progress(0.1, desc="Starting comparison...")
|
| 68 |
+
except (AttributeError, IndexError, TypeError):
|
| 69 |
+
pass
|
| 70 |
|
| 71 |
# Ensure environment variables are passed to subprocess
|
| 72 |
env = os.environ.copy()
|
|
|
|
| 87 |
# Combine outputs
|
| 88 |
full_output = f"=== STDOUT ===\n{stdout_text}\n\n=== STDERR ===\n{stderr_text}"
|
| 89 |
|
| 90 |
+
# Safe progress update
|
| 91 |
+
try:
|
| 92 |
progress(0.9, desc="Processing results...")
|
| 93 |
+
except (AttributeError, IndexError, TypeError):
|
| 94 |
+
pass
|
| 95 |
|
| 96 |
if result.returncode != 0:
|
| 97 |
return f"❌ Error occurred:\n{full_output}", None
|
|
|
|
| 110 |
break
|
| 111 |
|
| 112 |
if plot_path:
|
| 113 |
+
try:
|
| 114 |
progress(1.0, desc="Complete!")
|
| 115 |
+
except (AttributeError, IndexError, TypeError):
|
| 116 |
+
pass
|
| 117 |
return f"✅ Comparison complete!\n\n{stdout_text}", str(plot_path)
|
| 118 |
else:
|
| 119 |
# Return output even if plot not found (might still be useful)
|