KajetanNiewczas commited on
Commit Β·
721b7bd
1
Parent(s): eb14eba
Downloadable zip archive with the presentation output
Browse files
src/interface/download_files.py
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import zipfile
|
| 2 |
+
from pathlib import Path
|
| 3 |
+
from ..telemetry.logging_utils import Logger
|
| 4 |
+
|
| 5 |
+
LOGGER = Logger.get_logger()
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
def download_files(folder_path) -> str:
|
| 9 |
+
"""Prepare downloadable zip archive from the specified folder path."""
|
| 10 |
+
|
| 11 |
+
if not folder_path:
|
| 12 |
+
return "No folder path provided."
|
| 13 |
+
|
| 14 |
+
folder = Path(folder_path)
|
| 15 |
+
zip_path = Path.cwd() / "presentation.zip"
|
| 16 |
+
|
| 17 |
+
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zipf:
|
| 18 |
+
for file in folder.rglob('*'):
|
| 19 |
+
if file.is_file():
|
| 20 |
+
zipf.write(file, arcname="presentation")
|
| 21 |
+
LOGGER.info("π¦ Created zip archive at %s", zip_path)
|
| 22 |
+
|
| 23 |
+
return str(zip_path)
|
src/interface/gradio_interface.py
CHANGED
|
@@ -2,6 +2,7 @@
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
from .upload_files import upload_files
|
|
|
|
| 5 |
from ..services import generate_presentation
|
| 6 |
from ..telemetry import submit_feedback
|
| 7 |
import base64
|
|
@@ -21,7 +22,8 @@ def upload_and_update_list(files: list, uploaded_list) -> tuple[str, list[str]]:
|
|
| 21 |
return status, updated_list
|
| 22 |
|
| 23 |
|
| 24 |
-
def generate_iframe(
|
|
|
|
| 25 |
if not file_path:
|
| 26 |
return ""
|
| 27 |
else:
|
|
@@ -76,14 +78,28 @@ image_base64 = encode_image("gfx/long_logo.png")
|
|
| 76 |
|
| 77 |
with gr.Blocks(theme=theme, js=js_func) as demo:
|
| 78 |
uploaded_files_state = gr.State([])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
|
| 80 |
gr.Markdown(
|
| 81 |
'<h1 style="text-align:center;">AI-powered LaTeX Presentation Generator</h1>'
|
| 82 |
)
|
| 83 |
with gr.Row():
|
| 84 |
with gr.Column(scale=1):
|
| 85 |
-
gr.HTML(
|
| 86 |
-
f"""
|
| 87 |
<div style="text-align:center;">
|
| 88 |
<img src="{image_base64}" style="max-width: 100%; height: auto;" />
|
| 89 |
</div>
|
|
@@ -216,12 +232,12 @@ with gr.Blocks(theme=theme, js=js_func) as demo:
|
|
| 216 |
)
|
| 217 |
|
| 218 |
gr.Markdown("## π Presentation Processing")
|
| 219 |
-
|
| 220 |
label="Compilation Status", lines=1, interactive=False
|
| 221 |
)
|
| 222 |
|
| 223 |
gr.Markdown("## π Final Presentation")
|
| 224 |
-
pdf_output = gr.File(label="Download/View Presentation", interactive=False)
|
| 225 |
pdf_output_viewer = gr.HTML(label="Presentation Preview")
|
| 226 |
trace_id_state = gr.State("")
|
| 227 |
|
|
@@ -239,12 +255,18 @@ with gr.Blocks(theme=theme, js=js_func) as demo:
|
|
| 239 |
topic_input,
|
| 240 |
uploaded_files_state,
|
| 241 |
],
|
| 242 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 243 |
)
|
| 244 |
|
| 245 |
pdf_output.change(
|
| 246 |
fn=generate_iframe,
|
| 247 |
-
inputs=
|
| 248 |
outputs=pdf_output_viewer,
|
| 249 |
)
|
| 250 |
|
|
|
|
| 2 |
|
| 3 |
import gradio as gr
|
| 4 |
from .upload_files import upload_files
|
| 5 |
+
from .download_files import download_files
|
| 6 |
from ..services import generate_presentation
|
| 7 |
from ..telemetry import submit_feedback
|
| 8 |
import base64
|
|
|
|
| 22 |
return status, updated_list
|
| 23 |
|
| 24 |
|
| 25 |
+
def generate_iframe(folder_path):
|
| 26 |
+
file_path = f"{folder_path}/presentation.pdf"
|
| 27 |
if not file_path:
|
| 28 |
return ""
|
| 29 |
else:
|
|
|
|
| 78 |
|
| 79 |
with gr.Blocks(theme=theme, js=js_func) as demo:
|
| 80 |
uploaded_files_state = gr.State([])
|
| 81 |
+
presentation_folder_state = gr.State("")
|
| 82 |
+
|
| 83 |
+
# Mess with the download-box
|
| 84 |
+
gr.HTML(
|
| 85 |
+
"""
|
| 86 |
+
<style>
|
| 87 |
+
#download-box svg.feather-file {
|
| 88 |
+
display: none !important;
|
| 89 |
+
}
|
| 90 |
+
</style>
|
| 91 |
+
""",
|
| 92 |
+
elem_id="custom-style-injection",
|
| 93 |
+
visible=False
|
| 94 |
+
)
|
| 95 |
+
|
| 96 |
|
| 97 |
gr.Markdown(
|
| 98 |
'<h1 style="text-align:center;">AI-powered LaTeX Presentation Generator</h1>'
|
| 99 |
)
|
| 100 |
with gr.Row():
|
| 101 |
with gr.Column(scale=1):
|
| 102 |
+
gr.HTML(f"""
|
|
|
|
| 103 |
<div style="text-align:center;">
|
| 104 |
<img src="{image_base64}" style="max-width: 100%; height: auto;" />
|
| 105 |
</div>
|
|
|
|
| 232 |
)
|
| 233 |
|
| 234 |
gr.Markdown("## π Presentation Processing")
|
| 235 |
+
compilation_status = gr.Textbox(
|
| 236 |
label="Compilation Status", lines=1, interactive=False
|
| 237 |
)
|
| 238 |
|
| 239 |
gr.Markdown("## π Final Presentation")
|
| 240 |
+
pdf_output = gr.File(label="Download/View Presentation", interactive=False, elem_id="download-box")
|
| 241 |
pdf_output_viewer = gr.HTML(label="Presentation Preview")
|
| 242 |
trace_id_state = gr.State("")
|
| 243 |
|
|
|
|
| 255 |
topic_input,
|
| 256 |
uploaded_files_state,
|
| 257 |
],
|
| 258 |
+
outputs=[compilation_status, trace_id_state, presentation_folder_state],
|
| 259 |
+
)
|
| 260 |
+
|
| 261 |
+
compilation_status.change(
|
| 262 |
+
fn=download_files,
|
| 263 |
+
inputs=presentation_folder_state,
|
| 264 |
+
outputs=pdf_output,
|
| 265 |
)
|
| 266 |
|
| 267 |
pdf_output.change(
|
| 268 |
fn=generate_iframe,
|
| 269 |
+
inputs=presentation_folder_state,
|
| 270 |
outputs=pdf_output_viewer,
|
| 271 |
)
|
| 272 |
|
src/services/generator.py
CHANGED
|
@@ -25,8 +25,8 @@ def generate_presentation(theme, color, topic, uploaded_files) -> tuple[str, str
|
|
| 25 |
Returns:
|
| 26 |
tuple: A 3-element tuple:
|
| 27 |
- str: Success message.
|
| 28 |
-
- str:
|
| 29 |
-
- str:
|
| 30 |
"""
|
| 31 |
with traced_block(
|
| 32 |
"π½οΈ generate_presentation",
|
|
@@ -63,5 +63,5 @@ def generate_presentation(theme, color, topic, uploaded_files) -> tuple[str, str
|
|
| 63 |
compile_presentation(answer.text, work_dir)
|
| 64 |
|
| 65 |
delete_uploaded_files(uploaded_files)
|
| 66 |
-
|
| 67 |
-
return "Presentation generated successfully!",
|
|
|
|
| 25 |
Returns:
|
| 26 |
tuple: A 3-element tuple:
|
| 27 |
- str: Success message.
|
| 28 |
+
- str: Trace ID for telemetry purposes.
|
| 29 |
+
- str: Path to the presentation folder.
|
| 30 |
"""
|
| 31 |
with traced_block(
|
| 32 |
"π½οΈ generate_presentation",
|
|
|
|
| 63 |
compile_presentation(answer.text, work_dir)
|
| 64 |
|
| 65 |
delete_uploaded_files(uploaded_files)
|
| 66 |
+
|
| 67 |
+
return "Presentation generated successfully!", trace_id, work_dir
|