liuganghuggingface commited on
Commit
31acec8
·
verified ·
1 Parent(s): d33f846

Upload app.py with huggingface_hub

Browse files
Files changed (1) hide show
  1. app.py +22 -19
app.py CHANGED
@@ -86,9 +86,8 @@ def save_interesting_log(smiles, properties, suggested_properties):
86
  }
87
  writer.writerow(log_data)
88
 
89
- def generate_graph(CH4, CO2, H2, N2, O2, guidance_scale, num_nodes, repeating_time, model_state, num_chain_steps, fps):
90
- model, device = model_state
91
-
92
  properties = [CH4, CO2, H2, N2, O2]
93
 
94
  def is_nan_like(x):
@@ -185,8 +184,11 @@ def numpy_to_python(obj):
185
  return obj
186
 
187
  @spaces.GPU(duration=60)
188
- def on_generate(CH4, CO2, H2, N2, O2, guidance_scale, num_nodes, repeating_time, model_state, num_chain_steps, fps):
189
- result = generate_graph(CH4, CO2, H2, N2, O2, guidance_scale, num_nodes, repeating_time, model_state, num_chain_steps, fps)
 
 
 
190
  # Check if the generation was successful
191
  if result[0].startswith("**Generated polymer SMILES:**"):
192
  smiles = result[0].split("**Generated polymer SMILES:** `")[1].split("`")[0]
@@ -281,7 +283,8 @@ with gr.Blocks(title="Polymer Design with GraphDiT") as iface:
281
  ```
282
  """)
283
 
284
- model_state = gr.State(model_labeled)
 
285
 
286
  with gr.Row():
287
  CH4_input = gr.Slider(0, property_ranges['CH4'][1], value=2.5, label=f"CH₄ (Barrier) [0-{property_ranges['CH4'][1]:.1f}]")
@@ -310,18 +313,17 @@ with gr.Blocks(title="Polymer Design with GraphDiT") as iface:
310
  feedback_btn = gr.Button("🌟 I think this polymer is interesting!", visible=True, interactive=False)
311
  feedback_result = gr.Textbox(label="Feedback Result", visible=False)
312
 
313
- # Add model switching functionality
314
- def switch_model(choice):
315
- # Convert display name back to internal name
316
- internal_name = next(key for key, value in model_name_mapping.items() if value == choice)
317
- if internal_name == 'model_labeled':
318
- return model_labeled
319
- elif internal_name == 'model_all':
320
- return model_all
321
- else:
322
- raise ValueError('Not support model', internal_name)
323
-
324
- model_choice.change(switch_model, inputs=[model_choice], outputs=[model_state])
325
 
326
  # Hidden components to store generation data
327
  hidden_smiles = gr.Textbox(visible=False)
@@ -336,7 +338,8 @@ with gr.Blocks(title="Polymer Design with GraphDiT") as iface:
336
 
337
  generate_btn.click(
338
  on_generate,
339
- inputs=[CH4_input, CO2_input, H2_input, N2_input, O2_input, guidance_scale, num_nodes, repeating_time, model_state, num_chain_steps, fps],
 
340
  outputs=[result_text, result_image, result_gif, hidden_smiles, hidden_properties, hidden_suggested_properties, feedback_btn]
341
  )
342
 
 
86
  }
87
  writer.writerow(log_data)
88
 
89
+ # def generate_graph(CH4, CO2, H2, N2, O2, guidance_scale, num_nodes, repeating_time, model, num_chain_steps, fps):
90
+ def generate_graph(CH4, CO2, H2, N2, O2, guidance_scale, num_nodes, repeating_time, num_chain_steps, fps):
 
91
  properties = [CH4, CO2, H2, N2, O2]
92
 
93
  def is_nan_like(x):
 
184
  return obj
185
 
186
  @spaces.GPU(duration=60)
187
+ def on_generate(CH4, CO2, H2, N2, O2, guidance_scale, num_nodes, repeating_time, num_chain_steps, fps):
188
+ # def on_generate(CH4, CO2, H2, N2, O2, guidance_scale, num_nodes, repeating_time, model_state, num_chain_steps, fps):
189
+ # model = model_state
190
+ # result = generate_graph(CH4, CO2, H2, N2, O2, guidance_scale, num_nodes, repeating_time, model, num_chain_steps, fps)
191
+ result = generate_graph(CH4, CO2, H2, N2, O2, guidance_scale, num_nodes, repeating_time, num_chain_steps, fps)
192
  # Check if the generation was successful
193
  if result[0].startswith("**Generated polymer SMILES:**"):
194
  smiles = result[0].split("**Generated polymer SMILES:** `")[1].split("`")[0]
 
283
  ```
284
  """)
285
 
286
+ # model_state = gr.State(value=model_labeled)
287
+ # model_state = model_labeled
288
 
289
  with gr.Row():
290
  CH4_input = gr.Slider(0, property_ranges['CH4'][1], value=2.5, label=f"CH₄ (Barrier) [0-{property_ranges['CH4'][1]:.1f}]")
 
313
  feedback_btn = gr.Button("🌟 I think this polymer is interesting!", visible=True, interactive=False)
314
  feedback_result = gr.Textbox(label="Feedback Result", visible=False)
315
 
316
+ # def switch_model(choice):
317
+ # # Convert display name back to internal name
318
+ # internal_name = next(key for key, value in model_name_mapping.items() if value == choice)
319
+ # if internal_name == 'model_labeled':
320
+ # return model_labeled
321
+ # elif internal_name == 'model_all':
322
+ # return model_all
323
+ # else:
324
+ # raise ValueError('Not support model', internal_name)
325
+
326
+ # model_choice.change(switch_model, inputs=[model_choice], outputs=[model_state])
 
327
 
328
  # Hidden components to store generation data
329
  hidden_smiles = gr.Textbox(visible=False)
 
338
 
339
  generate_btn.click(
340
  on_generate,
341
+ # inputs=[CH4_input, CO2_input, H2_input, N2_input, O2_input, guidance_scale, num_nodes, repeating_time, model_state, num_chain_steps, fps],
342
+ inputs=[CH4_input, CO2_input, H2_input, N2_input, O2_input, guidance_scale, num_nodes, repeating_time, num_chain_steps, fps],
343
  outputs=[result_text, result_image, result_gif, hidden_smiles, hidden_properties, hidden_suggested_properties, feedback_btn]
344
  )
345