Update app.py
Browse files
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()
|
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
|
202 |
-
if (
|
203 |
-
const
|
204 |
-
|
205 |
-
|
206 |
-
|
207 |
-
document.
|
208 |
-
|
|
|
|
|
|
|
|
|
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,
|
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"):
|