Cornelius commited on
Commit
b4b1e11
·
1 Parent(s): ec32884

Fix Gradio 4.44.x schema bug by removing progress and disabling API

Browse files
Files changed (1) hide show
  1. app.py +4 -34
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=None):
18
  """
19
  Run strategy comparison with LM Student.
20
 
@@ -23,7 +23,6 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
23
  seed: Random seed (ignored if deterministic)
24
  use_deterministic: Use fixed seed=42
25
  device: 'cpu' or 'cuda' (GPU)
26
- progress: Gradio progress tracker
27
  """
28
 
29
  # Set device environment variable for subprocess
@@ -33,18 +32,8 @@ 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
- 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
 
@@ -64,13 +53,6 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
64
  cmd.extend(["--seed", str(int(seed))])
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()
76
  env["CUDA_DEVICE"] = os.environ.get("CUDA_DEVICE", device)
@@ -90,13 +72,6 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
90
  # Combine outputs
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
102
 
@@ -114,11 +89,6 @@ def run_comparison(iterations: int, seed: int, use_deterministic: bool, device:
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,7 +213,7 @@ with gr.Blocks(title="MentorFlow - Strategy Comparison") as demo:
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
 
 
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):
18
  """
19
  Run strategy comparison with LM Student.
20
 
 
23
  seed: Random seed (ignored if deterministic)
24
  use_deterministic: Use fixed seed=42
25
  device: 'cpu' or 'cuda' (GPU)
 
26
  """
27
 
28
  # Set device environment variable for subprocess
 
32
  import torch
33
  if not torch.cuda.is_available():
34
  device = "cpu"
 
 
 
 
 
35
  except ImportError:
36
  device = "cpu"
 
 
 
 
 
37
  except Exception:
38
  device = "cpu"
39
 
 
53
  cmd.extend(["--seed", str(int(seed))])
54
 
55
  try:
 
 
 
 
 
 
 
56
  # Ensure environment variables are passed to subprocess
57
  env = os.environ.copy()
58
  env["CUDA_DEVICE"] = os.environ.get("CUDA_DEVICE", device)
 
72
  # Combine outputs
73
  full_output = f"=== STDOUT ===\n{stdout_text}\n\n=== STDERR ===\n{stderr_text}"
74
 
 
 
 
 
 
 
 
75
  if result.returncode != 0:
76
  return f"❌ Error occurred:\n{full_output}", None
77
 
 
89
  break
90
 
91
  if plot_path:
 
 
 
 
 
92
  return f"✅ Comparison complete!\n\n{stdout_text}", str(plot_path)
93
  else:
94
  # Return output even if plot not found (might still be useful)
 
213
  """)
214
 
215
  if __name__ == "__main__":
216
+ # Disable API generation to avoid Gradio 4.44.x schema bug
217
+ # This bypasses the TypeError: argument of type 'bool' is not iterable
218
+ demo.launch(show_api=False)
219