Spaces:
Paused
Paused
Cornelius
commited on
Commit
Β·
ec32884
1
Parent(s):
81e0b33
Fix Gradio 4.44.0 bugs - upgrade to 4.44.1 and fix launch
Browse files- README.md +1 -1
- README_HF_SPACE.md +1 -1
- app.py +28 -21
- requirements.txt +2 -2
- requirements_hf.txt +1 -1
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: π
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 4.44.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
README_HF_SPACE.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: π
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 4.44.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
|
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 4.44.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
app.py
CHANGED
|
@@ -14,7 +14,7 @@ sys.path.insert(0, str(Path(__file__).parent))
|
|
| 14 |
sys.path.insert(0, str(Path(__file__).parent / "teacher_agent_dev"))
|
| 15 |
sys.path.insert(0, str(Path(__file__).parent / "student_agent_dev"))
|
| 16 |
|
| 17 |
-
def run_comparison(iterations: int, seed: int, use_deterministic: bool, device: str, progress=
|
| 18 |
"""
|
| 19 |
Run strategy comparison with LM Student.
|
| 20 |
|
|
@@ -33,16 +33,18 @@ 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 |
try:
|
| 37 |
-
progress(0.0, desc="β οΈ
|
| 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 |
|
|
@@ -63,10 +65,11 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
|
|
| 63 |
|
| 64 |
try:
|
| 65 |
# Safe progress update - wrap in try/except for Gradio compatibility
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 70 |
|
| 71 |
# Ensure environment variables are passed to subprocess
|
| 72 |
env = os.environ.copy()
|
|
@@ -88,10 +91,11 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
|
|
| 88 |
full_output = f"=== STDOUT ===\n{stdout_text}\n\n=== STDERR ===\n{stderr_text}"
|
| 89 |
|
| 90 |
# Safe progress update
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
|
|
|
| 95 |
|
| 96 |
if result.returncode != 0:
|
| 97 |
return f"β Error occurred:\n{full_output}", None
|
|
@@ -110,10 +114,11 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
|
|
| 110 |
break
|
| 111 |
|
| 112 |
if plot_path:
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
|
|
|
| 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)
|
|
@@ -238,5 +243,7 @@ with gr.Blocks(title="MentorFlow - Strategy Comparison") as demo:
|
|
| 238 |
""")
|
| 239 |
|
| 240 |
if __name__ == "__main__":
|
| 241 |
-
|
|
|
|
|
|
|
| 242 |
|
|
|
|
| 14 |
sys.path.insert(0, str(Path(__file__).parent / "teacher_agent_dev"))
|
| 15 |
sys.path.insert(0, str(Path(__file__).parent / "student_agent_dev"))
|
| 16 |
|
| 17 |
+
def run_comparison(iterations: int, seed: int, use_deterministic: bool, device: str, progress=None):
|
| 18 |
"""
|
| 19 |
Run strategy comparison with LM Student.
|
| 20 |
|
|
|
|
| 33 |
import torch
|
| 34 |
if not torch.cuda.is_available():
|
| 35 |
device = "cpu"
|
| 36 |
+
if progress is not None:
|
| 37 |
+
try:
|
| 38 |
+
progress(0.0, desc="β οΈ GPU not available, using CPU...")
|
| 39 |
+
except (AttributeError, IndexError, TypeError):
|
| 40 |
+
pass
|
| 41 |
+
except ImportError:
|
| 42 |
+
device = "cpu"
|
| 43 |
+
if progress is not None:
|
| 44 |
try:
|
| 45 |
+
progress(0.0, desc="β οΈ PyTorch not available, using CPU...")
|
| 46 |
except (AttributeError, IndexError, TypeError):
|
| 47 |
pass
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
except Exception:
|
| 49 |
device = "cpu"
|
| 50 |
|
|
|
|
| 65 |
|
| 66 |
try:
|
| 67 |
# Safe progress update - wrap in try/except for Gradio compatibility
|
| 68 |
+
if progress is not None:
|
| 69 |
+
try:
|
| 70 |
+
progress(0.1, desc="Starting comparison...")
|
| 71 |
+
except (AttributeError, IndexError, TypeError):
|
| 72 |
+
pass
|
| 73 |
|
| 74 |
# Ensure environment variables are passed to subprocess
|
| 75 |
env = os.environ.copy()
|
|
|
|
| 91 |
full_output = f"=== STDOUT ===\n{stdout_text}\n\n=== STDERR ===\n{stderr_text}"
|
| 92 |
|
| 93 |
# Safe progress update
|
| 94 |
+
if progress is not None:
|
| 95 |
+
try:
|
| 96 |
+
progress(0.9, desc="Processing results...")
|
| 97 |
+
except (AttributeError, IndexError, TypeError):
|
| 98 |
+
pass
|
| 99 |
|
| 100 |
if result.returncode != 0:
|
| 101 |
return f"β Error occurred:\n{full_output}", None
|
|
|
|
| 114 |
break
|
| 115 |
|
| 116 |
if plot_path:
|
| 117 |
+
if progress is not None:
|
| 118 |
+
try:
|
| 119 |
+
progress(1.0, desc="Complete!")
|
| 120 |
+
except (AttributeError, IndexError, TypeError):
|
| 121 |
+
pass
|
| 122 |
return f"β
Comparison complete!\n\n{stdout_text}", str(plot_path)
|
| 123 |
else:
|
| 124 |
# Return output even if plot not found (might still be useful)
|
|
|
|
| 243 |
""")
|
| 244 |
|
| 245 |
if __name__ == "__main__":
|
| 246 |
+
# For Hugging Face Spaces, Gradio auto-detects the environment
|
| 247 |
+
# No need to set share or server_name/port explicitly
|
| 248 |
+
demo.launch()
|
| 249 |
|
requirements.txt
CHANGED
|
@@ -15,8 +15,8 @@ seaborn>=0.12.0
|
|
| 15 |
# Progress bars
|
| 16 |
tqdm>=4.65.0
|
| 17 |
|
| 18 |
-
# Gradio for web interface
|
| 19 |
-
gradio>=4.44.
|
| 20 |
|
| 21 |
# Additional utilities
|
| 22 |
scipy>=1.10.0
|
|
|
|
| 15 |
# Progress bars
|
| 16 |
tqdm>=4.65.0
|
| 17 |
|
| 18 |
+
# Gradio for web interface (updated for security fixes)
|
| 19 |
+
gradio>=4.44.1
|
| 20 |
|
| 21 |
# Additional utilities
|
| 22 |
scipy>=1.10.0
|
requirements_hf.txt
CHANGED
|
@@ -16,7 +16,7 @@ seaborn>=0.12.0
|
|
| 16 |
tqdm>=4.65.0
|
| 17 |
|
| 18 |
# Gradio for web interface (updated for security fixes)
|
| 19 |
-
gradio>=4.44.
|
| 20 |
|
| 21 |
# Additional utilities
|
| 22 |
scipy>=1.10.0
|
|
|
|
| 16 |
tqdm>=4.65.0
|
| 17 |
|
| 18 |
# Gradio for web interface (updated for security fixes)
|
| 19 |
+
gradio>=4.44.1
|
| 20 |
|
| 21 |
# Additional utilities
|
| 22 |
scipy>=1.10.0
|