Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -321,16 +321,55 @@ For more details, see our [paper on arXiv](https://arxiv.org/abs/2302.07868).
|
|
321 |
info="Choose which protein target or general model to use for molecule generation"
|
322 |
)
|
323 |
|
324 |
-
|
325 |
-
|
326 |
-
|
327 |
-
|
328 |
-
|
329 |
-
|
330 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
331 |
|
332 |
# Create container for generation mode inputs
|
333 |
-
with gr.
|
334 |
num_molecules = gr.Slider(
|
335 |
minimum=10,
|
336 |
maximum=250,
|
@@ -339,27 +378,37 @@ For more details, see our [paper on arXiv](https://arxiv.org/abs/2302.07868).
|
|
339 |
label="Number of Molecules to Generate",
|
340 |
info="This space runs on a CPU, which may result in slower performance. Generating 200 molecules takes approximately 6 minutes. Therefore, We set a 250-molecule cap. On a GPU, the model can generate 10,000 molecules in the same amount of time. Please check our GitHub repo for running our models on GPU."
|
341 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
342 |
|
343 |
# Create container for SMILES input mode
|
344 |
-
with gr.
|
345 |
smiles_input = gr.Textbox(
|
346 |
label="Input SMILES",
|
347 |
info="Enter up to 100 SMILES strings, one per line",
|
348 |
lines=10,
|
349 |
placeholder="CC(=O)OC1=CC=CC=C1C(=O)O\nCCO\nC1=CC=C(C=C1)C(=O)O\n...",
|
350 |
)
|
351 |
-
|
352 |
-
|
353 |
-
|
354 |
-
|
355 |
-
|
356 |
-
|
357 |
-
|
358 |
|
359 |
# Handle visibility toggling between the two input modes
|
360 |
-
|
361 |
-
|
362 |
-
|
|
|
|
|
|
|
363 |
outputs=[generate_group, smiles_group]
|
364 |
)
|
365 |
|
@@ -368,6 +417,12 @@ For more details, see our [paper on arXiv](https://arxiv.org/abs/2302.07868).
|
|
368 |
variant="primary",
|
369 |
size="lg"
|
370 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
371 |
|
372 |
with gr.Column(scale=2):
|
373 |
basic_metrics_df = gr.Dataframe(
|
@@ -393,8 +448,14 @@ For more details, see our [paper on arXiv](https://arxiv.org/abs/2302.07868).
|
|
393 |
gr.Markdown("### Created by the HUBioDataLab | [GitHub](https://github.com/HUBioDataLab/DrugGEN) | [Paper](https://arxiv.org/abs/2302.07868)")
|
394 |
|
395 |
submit_button.click(
|
396 |
-
|
397 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
398 |
outputs=[
|
399 |
image_output,
|
400 |
file_download,
|
|
|
321 |
info="Choose which protein target or general model to use for molecule generation"
|
322 |
)
|
323 |
|
324 |
+
# Add a separator between model selection and input mode
|
325 |
+
gr.Markdown("---")
|
326 |
+
gr.Markdown("## Input Settings")
|
327 |
+
|
328 |
+
# Replace radio with switch using a better layout
|
329 |
+
with gr.Row(equal_height=True):
|
330 |
+
with gr.Column(scale=1, min_width=150):
|
331 |
+
gr.Markdown("### Classic Generation", elem_id="generate-mode-label")
|
332 |
+
|
333 |
+
with gr.Column(scale=1, min_width=150):
|
334 |
+
input_mode_switch = gr.Switch(
|
335 |
+
value=False,
|
336 |
+
label="Custom SMILES Input",
|
337 |
+
elem_id="input-mode-switch"
|
338 |
+
)
|
339 |
+
|
340 |
+
with gr.Column(scale=1, min_width=150):
|
341 |
+
gr.Markdown("### Custom SMILES Input", elem_id="smiles-mode-label")
|
342 |
+
|
343 |
+
# Add custom CSS for the switch styling
|
344 |
+
gr.HTML("""
|
345 |
+
<style>
|
346 |
+
#input-mode-switch {
|
347 |
+
margin: 0 auto;
|
348 |
+
display: flex;
|
349 |
+
justify-content: center;
|
350 |
+
transform: scale(1.5);
|
351 |
+
}
|
352 |
+
#generate-mode-label, #smiles-mode-label {
|
353 |
+
text-align: center;
|
354 |
+
margin-top: 10px;
|
355 |
+
}
|
356 |
+
.input-box {
|
357 |
+
border: 2px solid rgba(128, 128, 228, 0.3);
|
358 |
+
border-radius: 10px;
|
359 |
+
padding: 15px;
|
360 |
+
margin-top: 15px;
|
361 |
+
background-color: rgba(32, 36, 45, 0.7);
|
362 |
+
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
363 |
+
}
|
364 |
+
.input-box:hover {
|
365 |
+
border-color: rgba(128, 128, 228, 0.6);
|
366 |
+
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
|
367 |
+
}
|
368 |
+
</style>
|
369 |
+
""")
|
370 |
|
371 |
# Create container for generation mode inputs
|
372 |
+
with gr.Box(visible=True, elem_id="generate-box", elem_classes="input-box") as generate_group:
|
373 |
num_molecules = gr.Slider(
|
374 |
minimum=10,
|
375 |
maximum=250,
|
|
|
378 |
label="Number of Molecules to Generate",
|
379 |
info="This space runs on a CPU, which may result in slower performance. Generating 200 molecules takes approximately 6 minutes. Therefore, We set a 250-molecule cap. On a GPU, the model can generate 10,000 molecules in the same amount of time. Please check our GitHub repo for running our models on GPU."
|
380 |
)
|
381 |
+
|
382 |
+
# Seed input used in generate mode
|
383 |
+
seed_num_generate = gr.Textbox(
|
384 |
+
label="Random Seed (Optional)",
|
385 |
+
value="",
|
386 |
+
info="Set a specific seed for reproducible results, or leave empty for random generation"
|
387 |
+
)
|
388 |
|
389 |
# Create container for SMILES input mode
|
390 |
+
with gr.Box(visible=False, elem_id="smiles-box", elem_classes="input-box") as smiles_group:
|
391 |
smiles_input = gr.Textbox(
|
392 |
label="Input SMILES",
|
393 |
info="Enter up to 100 SMILES strings, one per line",
|
394 |
lines=10,
|
395 |
placeholder="CC(=O)OC1=CC=CC=C1C(=O)O\nCCO\nC1=CC=C(C=C1)C(=O)O\n...",
|
396 |
)
|
397 |
+
|
398 |
+
# Seed input used in SMILES mode
|
399 |
+
seed_num_smiles = gr.Textbox(
|
400 |
+
label="Random Seed (Optional)",
|
401 |
+
value="",
|
402 |
+
info="Set a specific seed for reproducible results, or leave empty for random generation"
|
403 |
+
)
|
404 |
|
405 |
# Handle visibility toggling between the two input modes
|
406 |
+
def toggle_visibility(checkbox_value):
|
407 |
+
return not checkbox_value, checkbox_value
|
408 |
+
|
409 |
+
input_mode_switch.change(
|
410 |
+
fn=toggle_visibility,
|
411 |
+
inputs=[input_mode_switch],
|
412 |
outputs=[generate_group, smiles_group]
|
413 |
)
|
414 |
|
|
|
417 |
variant="primary",
|
418 |
size="lg"
|
419 |
)
|
420 |
+
|
421 |
+
# Helper function to determine which mode is active and which seed to use
|
422 |
+
def get_inputs(checkbox_value, num_mols, seed_gen, seed_smiles, smiles):
|
423 |
+
mode = "smiles" if checkbox_value else "generate"
|
424 |
+
seed = seed_smiles if checkbox_value else seed_gen
|
425 |
+
return [mode, num_mols, seed, smiles]
|
426 |
|
427 |
with gr.Column(scale=2):
|
428 |
basic_metrics_df = gr.Dataframe(
|
|
|
448 |
gr.Markdown("### Created by the HUBioDataLab | [GitHub](https://github.com/HUBioDataLab/DrugGEN) | [Paper](https://arxiv.org/abs/2302.07868)")
|
449 |
|
450 |
submit_button.click(
|
451 |
+
fn=lambda model, checkbox, num_mols, seed_gen, seed_smiles, smiles: function(
|
452 |
+
model,
|
453 |
+
"smiles" if checkbox else "generate",
|
454 |
+
num_mols,
|
455 |
+
seed_smiles if checkbox else seed_gen,
|
456 |
+
smiles
|
457 |
+
),
|
458 |
+
inputs=[model_name, input_mode_switch, num_molecules, seed_num_generate, seed_num_smiles, smiles_input],
|
459 |
outputs=[
|
460 |
image_output,
|
461 |
file_download,
|