Spaces:
Paused
Paused
Cornelius
commited on
Commit
Β·
a4ee801
1
Parent(s):
a52f96d
Update Gradio to 4.44.0 to fix security vulnerabilities
Browse files- Updated gradio from 4.0.0 to >=4.44.0 in requirements files
- Updated sdk_version from 4.0.0 to 4.44.0 in README.md
- Fixed indentation error in app.py
- README.md +1 -1
- README_HF_SPACE.md +1 -1
- app.py +57 -30
- requirements.txt +1 -1
- requirements_hf.txt +2 -2
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: π
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: purple
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 4.
|
| 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.0
|
| 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.
|
| 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.0
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
app.py
CHANGED
|
@@ -6,6 +6,7 @@ Deployed on Hugging Face Spaces with GPU support
|
|
| 6 |
import gradio as gr
|
| 7 |
import sys
|
| 8 |
import os
|
|
|
|
| 9 |
from pathlib import Path
|
| 10 |
|
| 11 |
# Add project paths
|
|
@@ -13,7 +14,7 @@ sys.path.insert(0, str(Path(__file__).parent))
|
|
| 13 |
sys.path.insert(0, str(Path(__file__).parent / "teacher_agent_dev"))
|
| 14 |
sys.path.insert(0, str(Path(__file__).parent / "student_agent_dev"))
|
| 15 |
|
| 16 |
-
def run_comparison(iterations: int, seed: int, use_deterministic: bool, device: str, progress=gr.Progress()):
|
| 17 |
"""
|
| 18 |
Run strategy comparison with LM Student.
|
| 19 |
|
|
@@ -24,22 +25,25 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
|
|
| 24 |
device: 'cpu' or 'cuda' (GPU)
|
| 25 |
progress: Gradio progress tracker
|
| 26 |
"""
|
| 27 |
-
import subprocess
|
| 28 |
-
import io
|
| 29 |
-
from contextlib import redirect_stdout, redirect_stderr
|
| 30 |
|
| 31 |
-
# Set device environment variable
|
|
|
|
| 32 |
if device == "cuda":
|
| 33 |
-
# Check if CUDA is actually available
|
| 34 |
try:
|
| 35 |
import torch
|
| 36 |
if not torch.cuda.is_available():
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
|
| 44 |
# Prepare command
|
| 45 |
cmd = [
|
|
@@ -54,34 +58,57 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
|
|
| 54 |
cmd.extend(["--seed", str(int(seed))])
|
| 55 |
|
| 56 |
try:
|
| 57 |
-
progress
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 58 |
|
| 59 |
result = subprocess.run(
|
| 60 |
cmd,
|
| 61 |
cwd=str(Path(__file__).parent),
|
|
|
|
| 62 |
capture_output=True,
|
| 63 |
text=True,
|
| 64 |
timeout=3600 # 1 hour timeout
|
| 65 |
)
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
|
|
|
| 73 |
progress(0.9, desc="Processing results...")
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 81 |
progress(1.0, desc="Complete!")
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
except subprocess.TimeoutExpired:
|
| 87 |
return "β Timeout: Comparison took longer than 1 hour", None
|
|
|
|
| 6 |
import gradio as gr
|
| 7 |
import sys
|
| 8 |
import os
|
| 9 |
+
import subprocess
|
| 10 |
from pathlib import Path
|
| 11 |
|
| 12 |
# Add project paths
|
|
|
|
| 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=gr.Progress(track_tqdm=True)):
|
| 18 |
"""
|
| 19 |
Run strategy comparison with LM Student.
|
| 20 |
|
|
|
|
| 25 |
device: 'cpu' or 'cuda' (GPU)
|
| 26 |
progress: Gradio progress tracker
|
| 27 |
"""
|
|
|
|
|
|
|
|
|
|
| 28 |
|
| 29 |
+
# Set device environment variable for subprocess
|
| 30 |
+
# Check if CUDA is actually available before using
|
| 31 |
if device == "cuda":
|
|
|
|
| 32 |
try:
|
| 33 |
import torch
|
| 34 |
if not torch.cuda.is_available():
|
| 35 |
+
device = "cpu"
|
| 36 |
+
if progress:
|
| 37 |
+
progress(0.0, desc="β οΈ GPU not available, using CPU...")
|
| 38 |
+
except ImportError:
|
| 39 |
+
device = "cpu"
|
| 40 |
+
if progress:
|
| 41 |
+
progress(0.0, desc="β οΈ PyTorch not available, using CPU...")
|
| 42 |
+
except Exception:
|
| 43 |
+
device = "cpu"
|
| 44 |
+
|
| 45 |
+
# Set environment variable for subprocess to pick up
|
| 46 |
+
os.environ["CUDA_DEVICE"] = device
|
| 47 |
|
| 48 |
# Prepare command
|
| 49 |
cmd = [
|
|
|
|
| 58 |
cmd.extend(["--seed", str(int(seed))])
|
| 59 |
|
| 60 |
try:
|
| 61 |
+
if progress:
|
| 62 |
+
progress(0.1, desc="Starting comparison...")
|
| 63 |
+
|
| 64 |
+
# Ensure environment variables are passed to subprocess
|
| 65 |
+
env = os.environ.copy()
|
| 66 |
+
env["CUDA_DEVICE"] = os.environ.get("CUDA_DEVICE", device)
|
| 67 |
|
| 68 |
result = subprocess.run(
|
| 69 |
cmd,
|
| 70 |
cwd=str(Path(__file__).parent),
|
| 71 |
+
env=env, # Pass environment variables
|
| 72 |
capture_output=True,
|
| 73 |
text=True,
|
| 74 |
timeout=3600 # 1 hour timeout
|
| 75 |
)
|
| 76 |
+
|
| 77 |
+
stdout_text = result.stdout
|
| 78 |
+
stderr_text = result.stderr
|
| 79 |
+
|
| 80 |
+
# Combine outputs
|
| 81 |
+
full_output = f"=== STDOUT ===\n{stdout_text}\n\n=== STDERR ===\n{stderr_text}"
|
| 82 |
+
|
| 83 |
+
if progress:
|
| 84 |
progress(0.9, desc="Processing results...")
|
| 85 |
+
|
| 86 |
+
if result.returncode != 0:
|
| 87 |
+
return f"β Error occurred:\n{full_output}", None
|
| 88 |
+
|
| 89 |
+
# Find output plot (check multiple possible locations)
|
| 90 |
+
plot_paths = [
|
| 91 |
+
Path(__file__).parent / "teacher_agent_dev" / "comparison_all_strategies.png",
|
| 92 |
+
Path(__file__).parent / "comparison_all_strategies.png",
|
| 93 |
+
Path.cwd() / "teacher_agent_dev" / "comparison_all_strategies.png",
|
| 94 |
+
]
|
| 95 |
+
|
| 96 |
+
plot_path = None
|
| 97 |
+
for path in plot_paths:
|
| 98 |
+
if path.exists():
|
| 99 |
+
plot_path = path
|
| 100 |
+
break
|
| 101 |
+
|
| 102 |
+
if plot_path:
|
| 103 |
+
if progress:
|
| 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)
|
| 108 |
+
error_msg = f"β οΈ Plot not found at expected locations.\n"
|
| 109 |
+
error_msg += f"Checked: {[str(p) for p in plot_paths]}\n\n"
|
| 110 |
+
error_msg += f"Output:\n{full_output}"
|
| 111 |
+
return error_msg, None
|
| 112 |
|
| 113 |
except subprocess.TimeoutExpired:
|
| 114 |
return "β Timeout: Comparison took longer than 1 hour", None
|
requirements.txt
CHANGED
|
@@ -16,7 +16,7 @@ seaborn>=0.12.0
|
|
| 16 |
tqdm>=4.65.0
|
| 17 |
|
| 18 |
# Gradio for web interface
|
| 19 |
-
gradio>=4.
|
| 20 |
|
| 21 |
# Additional utilities
|
| 22 |
scipy>=1.10.0
|
|
|
|
| 16 |
tqdm>=4.65.0
|
| 17 |
|
| 18 |
# Gradio for web interface
|
| 19 |
+
gradio>=4.44.0
|
| 20 |
|
| 21 |
# Additional utilities
|
| 22 |
scipy>=1.10.0
|
requirements_hf.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.
|
| 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.0
|
| 20 |
|
| 21 |
# Additional utilities
|
| 22 |
scipy>=1.10.0
|