Joey Callanan commited on
Commit
56cce54
Β·
1 Parent(s): 8722415

minor changes

Browse files
Files changed (2) hide show
  1. src/ui/components.py +2 -2
  2. src/ui/handlers.py +43 -21
src/ui/components.py CHANGED
@@ -242,8 +242,8 @@ def create_chemical_variations_tab():
242
  show_label=False,
243
  elem_id="variations_gallery",
244
  columns=3,
245
- rows=3,
246
- height=300,
247
  object_fit="contain",
248
  allow_preview=True,
249
  show_share_button=False,
 
242
  show_label=False,
243
  elem_id="variations_gallery",
244
  columns=3,
245
+ rows=4,
246
+ height='auto',
247
  object_fit="contain",
248
  allow_preview=True,
249
  show_share_button=False,
src/ui/handlers.py CHANGED
@@ -27,55 +27,77 @@ class VariationHandlers:
27
  # -------------------------------------------------------------
28
  def generate_variations_for_display(self, input_smiles, num_variations=12):
29
  """
30
- 1. Display the input molecule as the big image.
31
- 2. Generate scaffold variations using Gen_PartialSMILES2.py.
32
- 3. Convert all generated SMILES into 2D RDKit images.
33
- 4. Return them in a format the Gradio Gallery can render.
34
  """
35
 
36
- print("=== GENERATE_VARIATIONS_FOR_DISPLAY CALLED ===")
 
 
37
  print(f"User input SMILES: {input_smiles}")
 
38
 
39
  # ------------------------------------------------------------
40
- # Step 1 β€” Display input molecule as the big image
41
  # ------------------------------------------------------------
42
  from rdkit import Chem
43
  from rdkit.Chem import Draw
44
-
45
  mol_input = Chem.MolFromSmiles(input_smiles)
46
  if mol_input is None:
47
- return [], "", "Invalid SMILES"
 
48
 
49
  big_image = Draw.MolToImage(mol_input, size=(400, 300))
50
 
 
 
51
  # ------------------------------------------------------------
52
- # Step 2 β€” Call generator (creates generated_molecules.csv)
53
  # ------------------------------------------------------------
54
  variations = generate_variations_from_partial_smiles(
55
  input_smiles,
56
  n_to_gen=num_variations
57
  )
58
 
 
 
 
59
  if not variations:
60
- print("No variations returned.")
61
- [], input_smiles, "No variations generated"
62
 
63
  self.current_variations = variations
64
 
65
- # ------------------------------------------------------------
66
- # Step 3 β€” Format for Gradio Gallery
67
- # ------------------------------------------------------------
68
  gallery_items = []
69
- for v in variations:
70
- gallery_items.append((v["image"], v["smiles"]))
 
 
 
 
 
 
 
 
 
 
 
71
 
72
- print(f"Generated {len(gallery_items)} icons.")
73
 
74
- # ------------------------------------------------------------
75
- # Return to Gradio
76
- # ------------------------------------------------------------
77
- return gallery_items, input_smiles, "" # (grid, selected SMILES, style)
78
 
 
 
 
 
79
 
80
  # -------------------------------------------------------------
81
  # Handle selection from the variations grid
 
27
  # -------------------------------------------------------------
28
  def generate_variations_for_display(self, input_smiles, num_variations=12):
29
  """
30
+ Generate variations using Gen_PartialSMILES2.py, convert to RDKit images,
31
+ and return formatted gallery items while printing debugging info.
 
 
32
  """
33
 
34
+ print("\n==============================")
35
+ print("πŸš€ generate_variations_for_display CALLED")
36
+ print("==============================")
37
  print(f"User input SMILES: {input_smiles}")
38
+ print(f"Requested # variations: {num_variations}")
39
 
40
  # ------------------------------------------------------------
41
+ # Create big image for the user input molecule
42
  # ------------------------------------------------------------
43
  from rdkit import Chem
44
  from rdkit.Chem import Draw
45
+
46
  mol_input = Chem.MolFromSmiles(input_smiles)
47
  if mol_input is None:
48
+ print("❌ ERROR: Invalid SMILES input. Cannot generate big preview.")
49
+ return [], input_smiles, "Invalid SMILES"
50
 
51
  big_image = Draw.MolToImage(mol_input, size=(400, 300))
52
 
53
+ print("βœ” Input molecule rendered successfully.")
54
+
55
  # ------------------------------------------------------------
56
+ # Run the generation helper
57
  # ------------------------------------------------------------
58
  variations = generate_variations_from_partial_smiles(
59
  input_smiles,
60
  n_to_gen=num_variations
61
  )
62
 
63
+ print(f"Generator returned {len(variations)} variations.")
64
+
65
+ # No variations returned β‰  UI failure β€” show empty grid
66
  if not variations:
67
+ print("⚠ No variations generated β€” returning empty gallery.")
68
+ return [], input_smiles, ""
69
 
70
  self.current_variations = variations
71
 
72
+ # ------------------------------------------------------------
73
+ # Build gallery items for Gradio
74
+ # ------------------------------------------------------------
75
  gallery_items = []
76
+ print("\nπŸ“¦ Building gallery_items...\n")
77
+
78
+ for i, v in enumerate(variations):
79
+ img = v["image"]
80
+ smi = v["smiles"]
81
+
82
+ print(f" #{i+1}:")
83
+ print(f" SMILES: {smi}")
84
+ print(f" Image type: {type(img)}")
85
+ try:
86
+ print(f" Image size: {img.size}")
87
+ except:
88
+ print(" ⚠ Could not read image size")
89
 
90
+ gallery_items.append((img, smi))
91
 
92
+ print("\n==============================")
93
+ print("πŸŽ‰ Returning data to UI")
94
+ print(f"Total gallery items: {len(gallery_items)}")
95
+ print("==============================\n")
96
 
97
+ # ------------------------------------------------------------
98
+ # Return to Gradio exactly as before
99
+ # ------------------------------------------------------------
100
+ return gallery_items, input_smiles, ""
101
 
102
  # -------------------------------------------------------------
103
  # Handle selection from the variations grid