LeonceNsh commited on
Commit
ce0f72b
·
verified ·
1 Parent(s): ba8fbda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -11
app.py CHANGED
@@ -17,7 +17,7 @@ if not openai.api_key:
17
  raise ValueError("Please set the OPENAI_API_KEY environment variable.")
18
 
19
  load_dotenv()
20
- sbx = Sandbox() # By default, the sandbox is alive for 5 minutes
21
 
22
  # Path to your Parquet dataset
23
  DATASET_PATH = 'hsas.parquet' # Update with your Parquet file path
@@ -194,18 +194,22 @@ with gr.Blocks(css="""
194
  results_out = gr.Dataframe(label="Query Results", interactive=False)
195
  btn_copy_results = gr.Button("Copy to Clipboard", variant="secondary", size="sm")
196
 
197
- # JavaScript for copying to clipboard
198
  copy_script = gr.HTML("""
199
  <script>
200
  function copyToClipboard() {
201
- const resultsTable = document.querySelector(".dataframe-output table");
202
- if (resultsTable) {
203
- const range = document.createRange();
204
- range.selectNode(resultsTable);
205
- window.getSelection().removeAllRanges();
206
- window.getSelection().addRange(range);
207
- document.execCommand("copy");
208
- window.getSelection().removeAllRanges();
 
 
 
 
209
  alert("Copied results to clipboard!");
210
  } else {
211
  alert("No results to copy!");
@@ -216,7 +220,7 @@ with gr.Blocks(css="""
216
 
217
  # Connect JavaScript function to button
218
  btn_copy_results.click(
219
- None, None, None, js="copyToClipboard"
220
  )
221
 
222
  with gr.Tab("📋 Dataset Schema", elem_classes="schema-tab"):
 
17
  raise ValueError("Please set the OPENAI_API_KEY environment variable.")
18
 
19
  load_dotenv()
20
+ sbx = Sandbox() # By default, the sandbox is alive for 5 minutes
21
 
22
  # Path to your Parquet dataset
23
  DATASET_PATH = 'hsas.parquet' # Update with your Parquet file path
 
194
  results_out = gr.Dataframe(label="Query Results", interactive=False)
195
  btn_copy_results = gr.Button("Copy to Clipboard", variant="secondary", size="sm")
196
 
197
+ # JavaScript for copying to clipboard - updated approach
198
  copy_script = gr.HTML("""
199
  <script>
200
  function copyToClipboard() {
201
+ const resultsContainer = document.querySelector('.dataframe-output table');
202
+ if (resultsContainer) {
203
+ const text = Array.from(resultsContainer.rows)
204
+ .map(row => Array.from(row.cells)
205
+ .map(cell => cell.innerText).join("\t"))
206
+ .join("\n");
207
+ const tempTextArea = document.createElement('textarea');
208
+ tempTextArea.value = text;
209
+ document.body.appendChild(tempTextArea);
210
+ tempTextArea.select();
211
+ document.execCommand('copy');
212
+ document.body.removeChild(tempTextArea);
213
  alert("Copied results to clipboard!");
214
  } else {
215
  alert("No results to copy!");
 
220
 
221
  # Connect JavaScript function to button
222
  btn_copy_results.click(
223
+ None, None, None, _js="copyToClipboard"
224
  )
225
 
226
  with gr.Tab("📋 Dataset Schema", elem_classes="schema-tab"):