BoltzmannEntropy commited on
Commit
24e893f
·
1 Parent(s): 29fe5a4
Files changed (1) hide show
  1. app.py +30 -15
app.py CHANGED
@@ -140,12 +140,13 @@ def generate_hamiltonians(num_hamiltonians, selected_qubits, selected_order, wri
140
  store_in_duckdb(results_table)
141
 
142
  # Function to load results from either DuckDB or Hugging Face dataset
143
- def load_results(load_from_hf, load_from_duckdb):
144
- if load_from_hf:
145
- return load_from_hf_dataset()
146
- if load_from_duckdb:
147
- return load_from_duckdb()
148
 
 
149
  # Gradio app
150
  with gr.Blocks() as app:
151
  gr.Markdown("# Quantum Hamiltonian Generator")
@@ -157,26 +158,40 @@ with gr.Blocks() as app:
157
  order_choices = [1, 2, 3, 4, 5]
158
  selected_order = gr.Dropdown(label="Select Trotter order", choices=order_choices, value=1)
159
 
160
- # Checkboxes for writing to HF dataset and DuckDB
161
- write_to_hf = gr.Checkbox(label="Write to Hugging Face dataset", value=False)
162
- write_to_duckdb = gr.Checkbox(label="Write to DuckDB", value=True)
 
163
 
164
  generate_button = gr.Button("Generate Hamiltonians")
165
  status = gr.Markdown("Click 'Generate Hamiltonians' to start the process.")
166
 
167
- def update_status(num, qubits, order, write_hf, write_duckdb):
168
- generate_hamiltonians(num, qubits, order, write_hf, write_duckdb)
 
 
 
 
 
169
  return "Data stored as per selection."
170
 
171
- generate_button.click(update_status, inputs=[num_hamiltonians, selected_qubits, selected_order, write_to_hf, write_to_duckdb], outputs=status)
172
 
173
  with gr.Tab("View Results"):
174
- load_from_hf = gr.Checkbox(label="Load from Hugging Face dataset", value=False)
175
- load_from_duckdb = gr.Checkbox(label="Load from DuckDB", value=True)
 
176
 
177
  load_button = gr.Button("Load Results")
178
  output_display = gr.HTML()
179
 
180
- load_button.click(load_results, inputs=[load_from_hf, load_from_duckdb], outputs=output_display)
 
 
 
 
 
 
 
181
 
182
- app.launch()
 
140
  store_in_duckdb(results_table)
141
 
142
  # Function to load results from either DuckDB or Hugging Face dataset
143
+ def load_results(load_from_hf_checkbox, load_from_duckdb_checkbox):
144
+ if load_from_hf_checkbox:
145
+ return load_from_hf_dataset() # Load from HF dataset
146
+ if load_from_duckdb_checkbox:
147
+ return load_from_duckdb() # Load from DuckDB
148
 
149
+ # Gradio app
150
  # Gradio app
151
  with gr.Blocks() as app:
152
  gr.Markdown("# Quantum Hamiltonian Generator")
 
158
  order_choices = [1, 2, 3, 4, 5]
159
  selected_order = gr.Dropdown(label="Select Trotter order", choices=order_choices, value=1)
160
 
161
+ # Radio buttons for selecting either Hugging Face dataset or DuckDB
162
+ write_option = gr.Radio(label="Where do you want to store the data?",
163
+ choices=["Write to Hugging Face dataset", "Write to DuckDB"],
164
+ value="Write to Hugging Face dataset")
165
 
166
  generate_button = gr.Button("Generate Hamiltonians")
167
  status = gr.Markdown("Click 'Generate Hamiltonians' to start the process.")
168
 
169
+ def update_status(num, qubits, order, write_option):
170
+ if write_option == "Write to Hugging Face dataset":
171
+ # Call function to write to Hugging Face dataset
172
+ generate_hamiltonians(num, qubits, order, write_to_hf=True, write_to_duckdb=False)
173
+ else:
174
+ # Call function to write to DuckDB
175
+ generate_hamiltonians(num, qubits, order, write_to_hf=False, write_to_duckdb=True)
176
  return "Data stored as per selection."
177
 
178
+ generate_button.click(update_status, inputs=[num_hamiltonians, selected_qubits, selected_order, write_option], outputs=status)
179
 
180
  with gr.Tab("View Results"):
181
+ load_option = gr.Radio(label="Where do you want to load the data from?",
182
+ choices=["Load from Hugging Face dataset", "Load from DuckDB"],
183
+ value="Load from DuckDB")
184
 
185
  load_button = gr.Button("Load Results")
186
  output_display = gr.HTML()
187
 
188
+ def load_results(load_option):
189
+ if load_option == "Load from Hugging Face dataset":
190
+ return load_from_hf_dataset()
191
+ else:
192
+ return load_from_duckdb()
193
+
194
+ load_button.click(load_results, inputs=[load_option], outputs=output_display)
195
+
196
 
197
+ app.launch(share=True)