Maximilian Schuh commited on
Commit
74d2a42
·
1 Parent(s): eff6c08

changed deps

Browse files
Files changed (3) hide show
  1. README.md +3 -3
  2. app.py +16 -7
  3. requirements.txt +4 -1
README.md CHANGED
@@ -37,8 +37,8 @@ Weights:
37
  - If the repos are public on HF LFS, no additional setup is required on Spaces; downloads are automatic and reused on subsequent runs.
38
 
39
  ## ZeroGPU setup (Hugging Face Spaces)
40
- - In the Space settings, choose the **ZeroGPU** hardware tier and Python **3.10** (supported runtimes for ZeroGPU).
41
- - The `run_prediction` handler is decorated with `@spaces.GPU(duration=120)`, so a GPU is provisioned only while a prediction runs.
42
  - Queueing is enabled with a single worker (`demo.queue(concurrency_count=1)`) to match the one-at-a-time ZeroGPU execution model.
43
  - To avoid spending GPU time on downloads, click **Download / refresh models** once after each deployment to prefetch weights on CPU.
44
- - If a prediction might exceed 120 seconds, bump the `duration` parameter in `app.py` to keep the GPU session alive long enough.
 
37
  - If the repos are public on HF LFS, no additional setup is required on Spaces; downloads are automatic and reused on subsequent runs.
38
 
39
  ## ZeroGPU setup (Hugging Face Spaces)
40
+ - In the Space settings, choose the **ZeroGPU** hardware tier and Python **3.10** or **3.12** (both supported on ZeroGPU).
41
+ - The GPU workload is isolated in `_gpu_predict`, decorated with `@spaces.GPU(duration=120)`, so a GPU is provisioned only for the inference step.
42
  - Queueing is enabled with a single worker (`demo.queue(concurrency_count=1)`) to match the one-at-a-time ZeroGPU execution model.
43
  - To avoid spending GPU time on downloads, click **Download / refresh models** once after each deployment to prefetch weights on CPU.
44
+ - If inference ever needs more time, adjust the `duration` parameter in `app.py`, but keep it as low as practical to respect ZeroGPU queue fairness.
app.py CHANGED
@@ -82,13 +82,9 @@ def parse_smiles(smiles_text: str) -> List[str]:
82
  return smiles
83
 
84
 
85
- @spaces.GPU(duration=240)
86
- def run_prediction(smiles_text: str, assay_text: str) -> Tuple[pd.DataFrame, object, str, str]:
87
- assay = assay_text.strip()
88
- if not assay:
89
- raise gr.Error("Please provide a bioassay description.")
90
-
91
- smiles = parse_smiles(smiles_text)
92
  model = get_model()
93
 
94
  try:
@@ -132,6 +128,19 @@ def run_prediction(smiles_text: str, assay_text: str) -> Tuple[pd.DataFrame, obj
132
  return df, fig, csv_file.name, xlsx_file.name
133
 
134
 
 
 
 
 
 
 
 
 
 
 
 
 
 
135
  def build_demo() -> gr.Blocks:
136
  example_smiles = "CC1=CC=C(C=C1)C2=CC(=NC3=NC=NC(=C23)N)C4=CC=C(C=C4)F\nCC(=O)C1=CC=C(C=C1)NC(=O)C2=CC3=C(C=C2)N=C(C(=N3)C4=CC=CO4)C5=CC=CO5\nCC1=C(C=C(C=C1)Cl)NC2=C/C(=N\S(=O)(=O)C3=CC=CS3)/C4=CC=CC=C4C2=O\nCC(C)C1=NC2=CC=CC=C2C(=N1)SCC(=O)N3CCCC3 "
137
  example_assay = "TR-FRET counterscreen for FAK inhibitors: dose-response biochemical high throughput screening assay to identify inhibitors of Proline-rich tyrosine kinase 2 (Pyk2)"
 
82
  return smiles
83
 
84
 
85
+ @spaces.GPU(duration=120)
86
+ def _gpu_predict(smiles: List[str], assay: str) -> Tuple[pd.DataFrame, object, str, str]:
87
+ """GPU-only path: expects prevalidated inputs and ready models."""
 
 
 
 
88
  model = get_model()
89
 
90
  try:
 
128
  return df, fig, csv_file.name, xlsx_file.name
129
 
130
 
131
+ def run_prediction(smiles_text: str, assay_text: str) -> Tuple[pd.DataFrame, object, str, str]:
132
+ """CPU wrapper: validates inputs and prepares models before GPU allocation."""
133
+ assay = assay_text.strip()
134
+ if not assay:
135
+ raise gr.Error("Please provide a bioassay description.")
136
+
137
+ smiles = parse_smiles(smiles_text)
138
+ # Download/refresh weights on CPU to keep ZeroGPU sessions short
139
+ ensure_models()
140
+
141
+ return _gpu_predict(smiles, assay)
142
+
143
+
144
  def build_demo() -> gr.Blocks:
145
  example_smiles = "CC1=CC=C(C=C1)C2=CC(=NC3=NC=NC(=C23)N)C4=CC=C(C=C4)F\nCC(=O)C1=CC=C(C=C1)NC(=O)C2=CC3=C(C=C2)N=C(C(=N3)C4=CC=CO4)C5=CC=CO5\nCC1=C(C=C(C=C1)Cl)NC2=C/C(=N\S(=O)(=O)C3=CC=CS3)/C4=CC=CC=C4C2=O\nCC(C)C1=NC2=CC=CC=C2C(=N1)SCC(=O)N3CCCC3 "
146
  example_assay = "TR-FRET counterscreen for FAK inhibitors: dose-response biochemical high throughput screening assay to identify inhibitors of Proline-rich tyrosine kinase 2 (Pyk2)"
requirements.txt CHANGED
@@ -1,4 +1,7 @@
1
- twinbooster==0.3.1
 
 
 
2
  huggingface_hub>=0.22.0
3
  pandas==2.0.3
4
  plotly>=5.22.0
 
1
+ --ignore-requires-python # twinbooster may still advertise py3.8; keep latest anyway
2
+
3
+ twinbooster
4
+ gradio==4.44.1
5
  huggingface_hub>=0.22.0
6
  pandas==2.0.3
7
  plotly>=5.22.0