Spaces:
Running
Running
Upload folder using huggingface_hub
Browse files- __pycache__/app.cpython-310.pyc +0 -0
- app.py +119 -1
__pycache__/app.cpython-310.pyc
CHANGED
|
Binary files a/__pycache__/app.cpython-310.pyc and b/__pycache__/app.cpython-310.pyc differ
|
|
|
app.py
CHANGED
|
@@ -1,7 +1,8 @@
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
from pathlib import Path
|
| 4 |
-
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
import pandas as pd
|
| 7 |
from huggingface_hub import snapshot_download
|
|
@@ -186,6 +187,76 @@ def get_contract():
|
|
| 186 |
"message": "backend_contract.json not loaded. Check HF_TOKEN secret or BUNDLE_REPO variable.",
|
| 187 |
}
|
| 188 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 189 |
|
| 190 |
loaded_ok, loaded_msg = download_bundle_light()
|
| 191 |
|
|
@@ -234,7 +305,54 @@ Important:
|
|
| 234 |
inputs=smiles_input,
|
| 235 |
outputs=[score_table, score_json],
|
| 236 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
with gr.Tab("Example Generate Response"):
|
| 239 |
gr.Markdown(
|
| 240 |
"""
|
|
|
|
| 1 |
import json
|
| 2 |
import os
|
| 3 |
from pathlib import Path
|
| 4 |
+
import uuid
|
| 5 |
+
from datetime import datetime
|
| 6 |
import gradio as gr
|
| 7 |
import pandas as pd
|
| 8 |
from huggingface_hub import snapshot_download
|
|
|
|
| 187 |
"message": "backend_contract.json not loaded. Check HF_TOKEN secret or BUNDLE_REPO variable.",
|
| 188 |
}
|
| 189 |
|
| 190 |
+
def generate_job_demo(num_molecules, return_top_k, docking_mode):
|
| 191 |
+
"""
|
| 192 |
+
CPU demo generation endpoint.
|
| 193 |
+
|
| 194 |
+
This does not run live REINVENT generation.
|
| 195 |
+
It returns a backend-style generation job response using the packaged example rows,
|
| 196 |
+
so frontend/filter/backend teams can test JSON + CSV + job history behavior.
|
| 197 |
+
"""
|
| 198 |
+
job_id = f"gen_{uuid.uuid4().hex[:8]}"
|
| 199 |
+
created_at = datetime.utcnow().isoformat() + "Z"
|
| 200 |
+
|
| 201 |
+
if EXAMPLE_JSON and "results" in EXAMPLE_JSON:
|
| 202 |
+
rows = EXAMPLE_JSON["results"]
|
| 203 |
+
else:
|
| 204 |
+
rows = [
|
| 205 |
+
compute_row("CCO"),
|
| 206 |
+
compute_row("c1ccccc1"),
|
| 207 |
+
]
|
| 208 |
+
|
| 209 |
+
num_molecules = int(num_molecules)
|
| 210 |
+
return_top_k = int(return_top_k)
|
| 211 |
+
|
| 212 |
+
selected = rows[: max(1, min(return_top_k, len(rows)))]
|
| 213 |
+
|
| 214 |
+
clean_rows = []
|
| 215 |
+
for row in selected:
|
| 216 |
+
clean = dict(row)
|
| 217 |
+
|
| 218 |
+
clean["docking_score"] = None
|
| 219 |
+
clean["docking_status"] = "not_run"
|
| 220 |
+
clean["docking_pose_file"] = None
|
| 221 |
+
|
| 222 |
+
if "pred_pAff_mean" not in clean:
|
| 223 |
+
clean["pred_pAff_mean"] = None
|
| 224 |
+
|
| 225 |
+
clean_rows.append(clean)
|
| 226 |
+
|
| 227 |
+
df = pd.DataFrame(clean_rows)
|
| 228 |
+
|
| 229 |
+
output_dir = Path("outputs")
|
| 230 |
+
output_dir.mkdir(exist_ok=True)
|
| 231 |
+
|
| 232 |
+
csv_path = output_dir / f"{job_id}_results.csv"
|
| 233 |
+
df.to_csv(csv_path, index=False)
|
| 234 |
+
|
| 235 |
+
response = {
|
| 236 |
+
"job_id": job_id,
|
| 237 |
+
"status": "completed",
|
| 238 |
+
"mode": "generate_job_cpu_demo",
|
| 239 |
+
"created_at": created_at,
|
| 240 |
+
"preset": "egfr_generator",
|
| 241 |
+
"docking_mode": docking_mode,
|
| 242 |
+
"summary": {
|
| 243 |
+
"num_requested": num_molecules,
|
| 244 |
+
"num_generated": len(rows),
|
| 245 |
+
"num_returned": len(clean_rows),
|
| 246 |
+
},
|
| 247 |
+
"columns": list(df.columns),
|
| 248 |
+
"results": clean_rows,
|
| 249 |
+
"download_csv_file": str(csv_path),
|
| 250 |
+
"warnings": [
|
| 251 |
+
"This is a CPU demo generation response.",
|
| 252 |
+
"Live REINVENT generation is not executed in this Space version.",
|
| 253 |
+
"The response shape matches the planned backend contract.",
|
| 254 |
+
"Real docking is not run in this CPU Space; docking_status is not_run.",
|
| 255 |
+
],
|
| 256 |
+
}
|
| 257 |
+
|
| 258 |
+
return df, response, str(csv_path)
|
| 259 |
+
|
| 260 |
|
| 261 |
loaded_ok, loaded_msg = download_bundle_light()
|
| 262 |
|
|
|
|
| 305 |
inputs=smiles_input,
|
| 306 |
outputs=[score_table, score_json],
|
| 307 |
)
|
| 308 |
+
with gr.Tab("Generate Job Demo"):
|
| 309 |
+
gr.Markdown(
|
| 310 |
+
"""
|
| 311 |
+
This tab demonstrates the expected backend behavior for generation jobs.
|
| 312 |
|
| 313 |
+
It returns:
|
| 314 |
+
|
| 315 |
+
- job_id
|
| 316 |
+
- status
|
| 317 |
+
- summary
|
| 318 |
+
- results JSON
|
| 319 |
+
- downloadable CSV file
|
| 320 |
+
|
| 321 |
+
Important:
|
| 322 |
+
This CPU Space does not run live REINVENT generation. It uses packaged example rows to let frontend, filters, and backend test the full response format.
|
| 323 |
+
"""
|
| 324 |
+
)
|
| 325 |
+
|
| 326 |
+
gen_num_molecules = gr.Number(
|
| 327 |
+
label="num_molecules",
|
| 328 |
+
value=100,
|
| 329 |
+
precision=0,
|
| 330 |
+
)
|
| 331 |
+
|
| 332 |
+
gen_return_top_k = gr.Number(
|
| 333 |
+
label="return_top_k",
|
| 334 |
+
value=20,
|
| 335 |
+
precision=0,
|
| 336 |
+
)
|
| 337 |
+
|
| 338 |
+
gen_docking_mode = gr.Dropdown(
|
| 339 |
+
label="docking_mode",
|
| 340 |
+
choices=["off", "top_k", "all"],
|
| 341 |
+
value="off",
|
| 342 |
+
)
|
| 343 |
+
|
| 344 |
+
gen_btn = gr.Button("Generate Job Demo")
|
| 345 |
+
|
| 346 |
+
gen_table = gr.Dataframe(label="Generated results table")
|
| 347 |
+
gen_json = gr.JSON(label="Backend-style generation JSON")
|
| 348 |
+
gen_file = gr.File(label="Download CSV")
|
| 349 |
+
|
| 350 |
+
gen_btn.click(
|
| 351 |
+
generate_job_demo,
|
| 352 |
+
inputs=[gen_num_molecules, gen_return_top_k, gen_docking_mode],
|
| 353 |
+
outputs=[gen_table, gen_json, gen_file],
|
| 354 |
+
)
|
| 355 |
+
|
| 356 |
with gr.Tab("Example Generate Response"):
|
| 357 |
gr.Markdown(
|
| 358 |
"""
|