Spaces:
Running
Running
Remove notebook download feature (keep Markdown and Code)
Browse files
app.py
CHANGED
|
@@ -26,7 +26,6 @@ from config import (
|
|
| 26 |
SUPPORTED_LANGUAGES,
|
| 27 |
SYSTEM_PROMPT,
|
| 28 |
EXAMPLE_PROMPTS,
|
| 29 |
-
NOTEBOOK_TEMPLATE,
|
| 30 |
MARKDOWN_TEMPLATE,
|
| 31 |
)
|
| 32 |
|
|
@@ -135,24 +134,6 @@ def create_download_file(
|
|
| 135 |
content = MARKDOWN_TEMPLATE.format(query=query, response=response)
|
| 136 |
filename = f"geoai_response_{timestamp}.md"
|
| 137 |
|
| 138 |
-
elif file_format == "notebook":
|
| 139 |
-
code_blocks = extract_code_blocks(response)
|
| 140 |
-
if not code_blocks:
|
| 141 |
-
# If no code blocks, create a markdown cell
|
| 142 |
-
code_cells = json.dumps([f"# No code blocks found\\n# Response:\\n# {response[:500]}..."])
|
| 143 |
-
else:
|
| 144 |
-
# Create code cells from extracted blocks
|
| 145 |
-
cells = [block["code"] for block in code_blocks if block["language"] == "python"]
|
| 146 |
-
if not cells:
|
| 147 |
-
cells = [code_blocks[0]["code"]] if code_blocks else ["# No Python code found"]
|
| 148 |
-
code_cells = json.dumps(cells)
|
| 149 |
-
|
| 150 |
-
content = NOTEBOOK_TEMPLATE.format(
|
| 151 |
-
query=query.replace('"', '\\"').replace('\n', '\\n'),
|
| 152 |
-
code_cells=code_cells
|
| 153 |
-
)
|
| 154 |
-
filename = f"geoai_notebook_{timestamp}.ipynb"
|
| 155 |
-
|
| 156 |
elif file_format == "code":
|
| 157 |
code_blocks = extract_code_blocks(response)
|
| 158 |
if not code_blocks:
|
|
@@ -184,11 +165,6 @@ def download_as_markdown(response: str, query: str) -> Optional[str]:
|
|
| 184 |
return create_download_file(response, query, "markdown")
|
| 185 |
|
| 186 |
|
| 187 |
-
def download_as_notebook(response: str, query: str) -> Optional[str]:
|
| 188 |
-
"""Download response as Jupyter Notebook."""
|
| 189 |
-
return create_download_file(response, query, "notebook")
|
| 190 |
-
|
| 191 |
-
|
| 192 |
def download_as_code(response: str, query: str) -> Optional[str]:
|
| 193 |
"""Download response as code file."""
|
| 194 |
return create_download_file(response, query, "code")
|
|
@@ -301,7 +277,6 @@ def create_app():
|
|
| 301 |
gr.Markdown("### π₯ Download Response")
|
| 302 |
with gr.Row():
|
| 303 |
download_md_btn = gr.Button("π Markdown", size="sm")
|
| 304 |
-
download_nb_btn = gr.Button("π Notebook", size="sm")
|
| 305 |
download_code_btn = gr.Button("π» Code File", size="sm")
|
| 306 |
|
| 307 |
download_file = gr.File(label="Download", visible=False)
|
|
@@ -343,13 +318,6 @@ def create_app():
|
|
| 343 |
return gr.File(value=filepath, visible=True)
|
| 344 |
return gr.File(visible=False)
|
| 345 |
|
| 346 |
-
def handle_download_nb(response, query):
|
| 347 |
-
"""Handle notebook download."""
|
| 348 |
-
filepath = download_as_notebook(response, query)
|
| 349 |
-
if filepath:
|
| 350 |
-
return gr.File(value=filepath, visible=True)
|
| 351 |
-
return gr.File(visible=False)
|
| 352 |
-
|
| 353 |
def handle_download_code(response, query):
|
| 354 |
"""Handle code file download."""
|
| 355 |
filepath = download_as_code(response, query)
|
|
@@ -391,12 +359,6 @@ def create_app():
|
|
| 391 |
[download_file],
|
| 392 |
)
|
| 393 |
|
| 394 |
-
download_nb_btn.click(
|
| 395 |
-
handle_download_nb,
|
| 396 |
-
[last_response, last_query],
|
| 397 |
-
[download_file],
|
| 398 |
-
)
|
| 399 |
-
|
| 400 |
download_code_btn.click(
|
| 401 |
handle_download_code,
|
| 402 |
[last_response, last_query],
|
|
|
|
| 26 |
SUPPORTED_LANGUAGES,
|
| 27 |
SYSTEM_PROMPT,
|
| 28 |
EXAMPLE_PROMPTS,
|
|
|
|
| 29 |
MARKDOWN_TEMPLATE,
|
| 30 |
)
|
| 31 |
|
|
|
|
| 134 |
content = MARKDOWN_TEMPLATE.format(query=query, response=response)
|
| 135 |
filename = f"geoai_response_{timestamp}.md"
|
| 136 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 137 |
elif file_format == "code":
|
| 138 |
code_blocks = extract_code_blocks(response)
|
| 139 |
if not code_blocks:
|
|
|
|
| 165 |
return create_download_file(response, query, "markdown")
|
| 166 |
|
| 167 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 168 |
def download_as_code(response: str, query: str) -> Optional[str]:
|
| 169 |
"""Download response as code file."""
|
| 170 |
return create_download_file(response, query, "code")
|
|
|
|
| 277 |
gr.Markdown("### π₯ Download Response")
|
| 278 |
with gr.Row():
|
| 279 |
download_md_btn = gr.Button("π Markdown", size="sm")
|
|
|
|
| 280 |
download_code_btn = gr.Button("π» Code File", size="sm")
|
| 281 |
|
| 282 |
download_file = gr.File(label="Download", visible=False)
|
|
|
|
| 318 |
return gr.File(value=filepath, visible=True)
|
| 319 |
return gr.File(visible=False)
|
| 320 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 321 |
def handle_download_code(response, query):
|
| 322 |
"""Handle code file download."""
|
| 323 |
filepath = download_as_code(response, query)
|
|
|
|
| 359 |
[download_file],
|
| 360 |
)
|
| 361 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 362 |
download_code_btn.click(
|
| 363 |
handle_download_code,
|
| 364 |
[last_response, last_query],
|