Spaces:
Running
on
Zero
Running
on
Zero
Julian Bilcke
commited on
Commit
·
ffde4ae
1
Parent(s):
a247fdb
fixing the gradio_pdf issue
Browse files- .claude/settings.local.json +12 -0
- app.py +15 -2
.claude/settings.local.json
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"permissions": {
|
| 3 |
+
"allow": [
|
| 4 |
+
"Read(//Users/jbilcke/Projects/comic_or_story_generation/gradio-pdf/backend/gradio_pdf/**)",
|
| 5 |
+
"Read(//Users/jbilcke/Projects/comic_or_story_generation/gradio-pdf/frontend/**)",
|
| 6 |
+
"Read(//Users/jbilcke/Projects/comic_or_story_generation/gradio-pdf/**)",
|
| 7 |
+
"Bash(python -m gradio:*)"
|
| 8 |
+
],
|
| 9 |
+
"deny": [],
|
| 10 |
+
"ask": []
|
| 11 |
+
}
|
| 12 |
+
}
|
app.py
CHANGED
|
@@ -779,10 +779,15 @@ def create_multi_page_pdf(session_manager: SessionManager) -> str:
|
|
| 779 |
for page in page_pdf_reader.pages:
|
| 780 |
pdf_writer.add_page(page)
|
| 781 |
|
| 782 |
-
# Write to file
|
| 783 |
pdf_path = session_manager.pdf_path
|
| 784 |
with open(pdf_path, 'wb') as f:
|
| 785 |
pdf_writer.write(f)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 786 |
|
| 787 |
return str(pdf_path)
|
| 788 |
|
|
@@ -1164,7 +1169,15 @@ with gr.Blocks(css=css) as demo:
|
|
| 1164 |
|
| 1165 |
# Right column - PDF Preview
|
| 1166 |
with gr.Column(scale=2):
|
| 1167 |
-
pdf_preview = PDF(
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1168 |
|
| 1169 |
# Add interaction to show/hide custom style text field
|
| 1170 |
def toggle_custom_style(style_value):
|
|
|
|
| 779 |
for page in page_pdf_reader.pages:
|
| 780 |
pdf_writer.add_page(page)
|
| 781 |
|
| 782 |
+
# Write to file with explicit flushing
|
| 783 |
pdf_path = session_manager.pdf_path
|
| 784 |
with open(pdf_path, 'wb') as f:
|
| 785 |
pdf_writer.write(f)
|
| 786 |
+
f.flush() # Flush Python's internal buffer
|
| 787 |
+
os.fsync(f.fileno()) # Ensure OS writes to disk
|
| 788 |
+
|
| 789 |
+
# Small delay to ensure file system catches up
|
| 790 |
+
time.sleep(0.1)
|
| 791 |
|
| 792 |
return str(pdf_path)
|
| 793 |
|
|
|
|
| 1169 |
|
| 1170 |
# Right column - PDF Preview
|
| 1171 |
with gr.Column(scale=2):
|
| 1172 |
+
pdf_preview = PDF(
|
| 1173 |
+
label="PDF Preview",
|
| 1174 |
+
show_label=True,
|
| 1175 |
+
height=900,
|
| 1176 |
+
elem_id="pdf-preview",
|
| 1177 |
+
enable_zoom=True,
|
| 1178 |
+
min_zoom=1.0,
|
| 1179 |
+
max_zoom=3.0
|
| 1180 |
+
)
|
| 1181 |
|
| 1182 |
# Add interaction to show/hide custom style text field
|
| 1183 |
def toggle_custom_style(style_value):
|