Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -121,14 +121,8 @@ def function(model_name: str, input_mode: str, num_molecules: int = None, seed_n
|
|
121 |
config.inf_smiles = temp_smiles_file
|
122 |
config.sample_num = len(smiles_list)
|
123 |
|
124 |
-
#
|
125 |
-
|
126 |
-
config.seed = random.randint(0, 10000)
|
127 |
-
else:
|
128 |
-
try:
|
129 |
-
config.seed = int(seed_num)
|
130 |
-
except ValueError:
|
131 |
-
raise gr.Error("The seed must be an integer value!")
|
132 |
|
133 |
if model_name != "NoTarget":
|
134 |
model_name = "DrugGEN"
|
@@ -331,28 +325,48 @@ For more details, see our [paper on arXiv](https://arxiv.org/abs/2302.07868).
|
|
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.
|
335 |
value=False,
|
336 |
-
label="
|
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
|
344 |
gr.HTML("""
|
345 |
<style>
|
346 |
#input-mode-switch {
|
347 |
-
margin:
|
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;
|
@@ -360,12 +374,63 @@ For more details, see our [paper on arXiv](https://arxiv.org/abs/2302.07868).
|
|
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
|
@@ -394,13 +459,6 @@ For more details, see our [paper on arXiv](https://arxiv.org/abs/2302.07868).
|
|
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):
|
@@ -419,9 +477,9 @@ For more details, see our [paper on arXiv](https://arxiv.org/abs/2302.07868).
|
|
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,
|
423 |
mode = "smiles" if checkbox_value else "generate"
|
424 |
-
seed =
|
425 |
return [mode, num_mols, seed, smiles]
|
426 |
|
427 |
with gr.Column(scale=2):
|
@@ -448,14 +506,14 @@ For more details, see our [paper on arXiv](https://arxiv.org/abs/2302.07868).
|
|
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,
|
452 |
model,
|
453 |
"smiles" if checkbox else "generate",
|
454 |
num_mols,
|
455 |
-
|
456 |
smiles
|
457 |
),
|
458 |
-
inputs=[model_name, input_mode_switch, num_molecules, seed_num_generate,
|
459 |
outputs=[
|
460 |
image_output,
|
461 |
file_download,
|
|
|
121 |
config.inf_smiles = temp_smiles_file
|
122 |
config.sample_num = len(smiles_list)
|
123 |
|
124 |
+
# Always use a fixed seed for SMILES mode
|
125 |
+
config.seed = 42
|
|
|
|
|
|
|
|
|
|
|
|
|
126 |
|
127 |
if model_name != "NoTarget":
|
128 |
model_name = "DrugGEN"
|
|
|
325 |
gr.Markdown("### Classic Generation", elem_id="generate-mode-label")
|
326 |
|
327 |
with gr.Column(scale=1, min_width=150):
|
328 |
+
input_mode_switch = gr.Checkbox(
|
329 |
value=False,
|
330 |
+
label="Switch Input Mode",
|
331 |
elem_id="input-mode-switch"
|
332 |
)
|
333 |
|
334 |
with gr.Column(scale=1, min_width=150):
|
335 |
gr.Markdown("### Custom SMILES Input", elem_id="smiles-mode-label")
|
336 |
|
337 |
+
# Add custom CSS and JavaScript for better styling
|
338 |
gr.HTML("""
|
339 |
<style>
|
340 |
#input-mode-switch {
|
341 |
+
margin: 20px auto;
|
342 |
display: flex;
|
343 |
justify-content: center;
|
|
|
344 |
}
|
345 |
+
|
346 |
#generate-mode-label, #smiles-mode-label {
|
347 |
text-align: center;
|
348 |
margin-top: 10px;
|
349 |
+
font-weight: bold;
|
350 |
+
transition: opacity 0.3s ease;
|
351 |
}
|
352 |
+
|
353 |
+
/* Make the inactive mode label more subtle */
|
354 |
+
#generate-mode-label {
|
355 |
+
opacity: 1;
|
356 |
+
color: #4CAF50;
|
357 |
+
}
|
358 |
+
|
359 |
+
#smiles-mode-label {
|
360 |
+
opacity: 0.5;
|
361 |
+
color: #2196F3;
|
362 |
+
}
|
363 |
+
|
364 |
+
.active-mode {
|
365 |
+
text-decoration: underline;
|
366 |
+
font-size: 1.1em;
|
367 |
+
}
|
368 |
+
|
369 |
+
/* Style for the input boxes */
|
370 |
.input-box {
|
371 |
border: 2px solid rgba(128, 128, 228, 0.3);
|
372 |
border-radius: 10px;
|
|
|
374 |
margin-top: 15px;
|
375 |
background-color: rgba(32, 36, 45, 0.7);
|
376 |
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
|
377 |
+
transition: all 0.3s ease;
|
378 |
}
|
379 |
+
|
380 |
.input-box:hover {
|
381 |
border-color: rgba(128, 128, 228, 0.6);
|
382 |
box-shadow: 0 6px 8px rgba(0, 0, 0, 0.15);
|
383 |
}
|
384 |
+
|
385 |
+
/* Style the checkbox */
|
386 |
+
#input-mode-switch label {
|
387 |
+
font-weight: bold;
|
388 |
+
font-size: 1.1em;
|
389 |
+
color: rgba(128, 128, 228, 0.9);
|
390 |
+
}
|
391 |
+
|
392 |
+
/* Add a hint to indicate the toggle functionality */
|
393 |
+
#input-mode-switch::after {
|
394 |
+
content: 'Click to toggle between modes';
|
395 |
+
display: block;
|
396 |
+
text-align: center;
|
397 |
+
font-size: 0.8em;
|
398 |
+
opacity: 0.7;
|
399 |
+
margin-top: 5px;
|
400 |
+
}
|
401 |
</style>
|
402 |
+
|
403 |
+
<script>
|
404 |
+
// Add JavaScript to enhance the mode switching UI
|
405 |
+
document.addEventListener('DOMContentLoaded', function() {
|
406 |
+
// Get references to elements
|
407 |
+
const checkbox = document.querySelector('#input-mode-switch input[type="checkbox"]');
|
408 |
+
const generateLabel = document.querySelector('#generate-mode-label');
|
409 |
+
const smilesLabel = document.querySelector('#smiles-mode-label');
|
410 |
+
|
411 |
+
// Add initial active class
|
412 |
+
generateLabel.classList.add('active-mode');
|
413 |
+
|
414 |
+
// Add event listener to checkbox
|
415 |
+
if (checkbox) {
|
416 |
+
checkbox.addEventListener('change', function() {
|
417 |
+
if (this.checked) {
|
418 |
+
// SMILES mode is active
|
419 |
+
generateLabel.style.opacity = '0.5';
|
420 |
+
smilesLabel.style.opacity = '1';
|
421 |
+
generateLabel.classList.remove('active-mode');
|
422 |
+
smilesLabel.classList.add('active-mode');
|
423 |
+
} else {
|
424 |
+
// Generate mode is active
|
425 |
+
generateLabel.style.opacity = '1';
|
426 |
+
smilesLabel.style.opacity = '0.5';
|
427 |
+
generateLabel.classList.add('active-mode');
|
428 |
+
smilesLabel.classList.remove('active-mode');
|
429 |
+
}
|
430 |
+
});
|
431 |
+
}
|
432 |
+
});
|
433 |
+
</script>
|
434 |
""")
|
435 |
|
436 |
# Create container for generation mode inputs
|
|
|
459 |
lines=10,
|
460 |
placeholder="CC(=O)OC1=CC=CC=C1C(=O)O\nCCO\nC1=CC=C(C=C1)C(=O)O\n...",
|
461 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
462 |
|
463 |
# Handle visibility toggling between the two input modes
|
464 |
def toggle_visibility(checkbox_value):
|
|
|
477 |
)
|
478 |
|
479 |
# Helper function to determine which mode is active and which seed to use
|
480 |
+
def get_inputs(checkbox_value, num_mols, seed_gen, smiles):
|
481 |
mode = "smiles" if checkbox_value else "generate"
|
482 |
+
seed = "42" if checkbox_value else seed_gen # Use default seed 42 for SMILES mode
|
483 |
return [mode, num_mols, seed, smiles]
|
484 |
|
485 |
with gr.Column(scale=2):
|
|
|
506 |
gr.Markdown("### Created by the HUBioDataLab | [GitHub](https://github.com/HUBioDataLab/DrugGEN) | [Paper](https://arxiv.org/abs/2302.07868)")
|
507 |
|
508 |
submit_button.click(
|
509 |
+
fn=lambda model, checkbox, num_mols, seed_gen, smiles: function(
|
510 |
model,
|
511 |
"smiles" if checkbox else "generate",
|
512 |
num_mols,
|
513 |
+
"42" if checkbox else seed_gen, # Use default seed 42 for SMILES mode
|
514 |
smiles
|
515 |
),
|
516 |
+
inputs=[model_name, input_mode_switch, num_molecules, seed_num_generate, smiles_input],
|
517 |
outputs=[
|
518 |
image_output,
|
519 |
file_download,
|