Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -11,7 +11,7 @@ import base64
|
|
11 |
import tempfile
|
12 |
from reportlab.pdfgen import canvas
|
13 |
from reportlab.lib.pagesizes import letter
|
14 |
-
from PyPDF2 import PdfReader
|
15 |
|
16 |
from hugchat import hugchat
|
17 |
from hugchat.login import Login
|
@@ -197,13 +197,16 @@ def clear_all(history, uploaded_file_paths, chats):
|
|
197 |
c.save()
|
198 |
# Verschiebe den Lesekopf an den Beginn des Bytes IO Streams
|
199 |
memoryFile.seek(0)
|
200 |
-
# Erstelle ein PDF-Objekt aus dem Bytes IO Stream
|
201 |
-
pdf = PdfReader(memoryFile)
|
202 |
-
# Öffne eine neue PDF-Datei und kopiere den Inhalt des Bytestreams hinein
|
203 |
-
with open(file_path_download, 'wb') as outf:
|
204 |
-
pdf.write(outf)
|
205 |
-
|
206 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
207 |
|
208 |
#die session variable in gradio erweitern und alle fliepath neu in das gr.File hochladen
|
209 |
uploaded_file_paths= uploaded_file_paths + [file_path_download]
|
|
|
11 |
import tempfile
|
12 |
from reportlab.pdfgen import canvas
|
13 |
from reportlab.lib.pagesizes import letter
|
14 |
+
from PyPDF2 import PdfReader, PdfWriter
|
15 |
|
16 |
from hugchat import hugchat
|
17 |
from hugchat.login import Login
|
|
|
197 |
c.save()
|
198 |
# Verschiebe den Lesekopf an den Beginn des Bytes IO Streams
|
199 |
memoryFile.seek(0)
|
|
|
|
|
|
|
|
|
|
|
|
|
200 |
|
201 |
+
# Erstelle ein PdfFileWriter-Objekt aus dem BytesIO-Stream
|
202 |
+
pdf_writer = PdfWriter()
|
203 |
+
pdf_reader = PdfReader(memoryFile)
|
204 |
+
# Gib das PDF-Objekt an PdfFileWriter weiter
|
205 |
+
for page in range(pdf_reader.getNumPages()):
|
206 |
+
pdf_writer.addPage(pdf_reader.getPage(page))
|
207 |
+
# Speichere das PDF-Objekt in einer neuen Datei
|
208 |
+
with open(file_path_download, "wb") as fp:
|
209 |
+
pdf_writer.write(fp)
|
210 |
|
211 |
#die session variable in gradio erweitern und alle fliepath neu in das gr.File hochladen
|
212 |
uploaded_file_paths= uploaded_file_paths + [file_path_download]
|