alimotahharynia commited on
Commit
8af0501
·
verified ·
1 Parent(s): 04d56f2

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -10
app.py CHANGED
@@ -95,14 +95,14 @@ class SMILESGenerator:
95
  if generated_smiles not in generated_smiles_set:
96
  generated_smiles_set.add(generated_smiles)
97
  except (IndexError, AttributeError) as e:
98
- logging.warning(f"Failed to parse SMILES due to error: {str(e)}. Skipping.")
99
 
100
  if progress_callback:
101
  progress_callback((retries + 1) / 30)
102
 
103
  retries += 1
104
 
105
- logging.info(f"SMILES generation completed. Generated {len(generated_smiles_set)} SMILES.")
106
  return list(generated_smiles_set)
107
 
108
  # Gradio interface
@@ -136,7 +136,7 @@ def generate_smiles_gradio(sequence_input=None, uniprot_id=None, num_generated=1
136
  except Exception as e:
137
  results[str(uniprot_counter)] = {
138
  "sequence": seq,
139
- "error": f"Error generating SMILES: {str(e)}"
140
  }
141
  uniprot_counter += 1
142
 
@@ -161,12 +161,12 @@ def generate_smiles_gradio(sequence_input=None, uniprot_id=None, num_generated=1
161
  except Exception as e:
162
  results[uid] = {
163
  "sequence": "N/A",
164
- "error": f"Error generating SMILES: {str(e)}"
165
  }
166
 
167
  # Check if no results were generated
168
  if not results:
169
- return {"error": "No SMILES generated. Please try again with different inputs."}
170
 
171
  # Save results to a file
172
  file_path = save_smiles_to_file(results)
@@ -212,7 +212,7 @@ if __name__ == "__main__":
212
  with gr.Blocks(theme=theme, css=css) as iface:
213
  gr.Markdown("## DrugGen", elem_id="app-title")
214
  gr.Markdown(
215
- "Generate **drug-like SMILES structures** from protein sequences or UniProt IDs. "
216
  "Input data, specify parameters, and download the results.",
217
  elem_id="description"
218
  )
@@ -220,7 +220,7 @@ if __name__ == "__main__":
220
  with gr.Row():
221
  sequence_input = gr.Textbox(
222
  label="Protein Sequences",
223
- placeholder="Enter sequences separated by commas (e.g., MGAASGRRGP, MGETLGDSPI, ...)",
224
  lines=3,
225
  )
226
  uniprot_id_input = gr.Textbox(
@@ -234,16 +234,16 @@ if __name__ == "__main__":
234
  maximum=100,
235
  step=1,
236
  value=10,
237
- label="Number of Unique SMILES to Generate",
238
  )
239
 
240
- output = gr.JSON(label="Generated SMILES")
241
  file_output = gr.File(
242
  label="Download Results as JSON",
243
  elem_id=["file-output"]
244
  )
245
 
246
- generate_button = gr.Button("Generate SMILES", elem_id="generate-button")
247
  generate_button.click(
248
  generate_smiles_gradio,
249
  inputs=[sequence_input, uniprot_id_input, num_generated_slider],
 
95
  if generated_smiles not in generated_smiles_set:
96
  generated_smiles_set.add(generated_smiles)
97
  except (IndexError, AttributeError) as e:
98
+ logging.warning(f"Failed to parse small molecule due to error: {str(e)}. Skipping.")
99
 
100
  if progress_callback:
101
  progress_callback((retries + 1) / 30)
102
 
103
  retries += 1
104
 
105
+ logging.info(f"Small molecules generation completed. Generated {len(generated_smiles_set)} Small molecules.")
106
  return list(generated_smiles_set)
107
 
108
  # Gradio interface
 
136
  except Exception as e:
137
  results[str(uniprot_counter)] = {
138
  "sequence": seq,
139
+ "error": f"Error generating small molecules: {str(e)}"
140
  }
141
  uniprot_counter += 1
142
 
 
161
  except Exception as e:
162
  results[uid] = {
163
  "sequence": "N/A",
164
+ "error": f"Error generating small molecules: {str(e)}"
165
  }
166
 
167
  # Check if no results were generated
168
  if not results:
169
+ return {"error": "No small molecules generated. Please try again with different inputs."}
170
 
171
  # Save results to a file
172
  file_path = save_smiles_to_file(results)
 
212
  with gr.Blocks(theme=theme, css=css) as iface:
213
  gr.Markdown("## DrugGen", elem_id="app-title")
214
  gr.Markdown(
215
+ "Generate **drug-like small molecules structures** from protein sequences or UniProt IDs. "
216
  "Input data, specify parameters, and download the results.",
217
  elem_id="description"
218
  )
 
220
  with gr.Row():
221
  sequence_input = gr.Textbox(
222
  label="Protein Sequences",
223
+ placeholder="Enter sequences separated by commas (e.g., MGAASGRRGP..., MGETLGDSPI..., ...)",
224
  lines=3,
225
  )
226
  uniprot_id_input = gr.Textbox(
 
234
  maximum=100,
235
  step=1,
236
  value=10,
237
+ label="Number of Unique Small Molecules to Generate",
238
  )
239
 
240
+ output = gr.JSON(label="Generated Small Molecules")
241
  file_output = gr.File(
242
  label="Download Results as JSON",
243
  elem_id=["file-output"]
244
  )
245
 
246
+ generate_button = gr.Button("Generate Small Molecule", elem_id="generate-button")
247
  generate_button.click(
248
  generate_smiles_gradio,
249
  inputs=[sequence_input, uniprot_id_input, num_generated_slider],