ginipick commited on
Commit
79a7cbc
ยท
verified ยท
1 Parent(s): dd25f95

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +34 -34
app.py CHANGED
@@ -130,44 +130,44 @@ def process_images(image_paths, session_id):
130
  return pages_info
131
 
132
  def create_flipbook_from_pdf(pdf_file, view_mode="2d", skin="light"):
133
- """Create a flipbook from uploaded PDF."""
 
 
 
 
 
 
 
 
 
134
  try:
135
- session_id = str(uuid.uuid4())
136
- pages_info = []
137
- debug_info = ""
138
-
139
- if pdf_file is not None:
140
- # In Gradio, pdf_file is a file path string, not the actual content
141
- pdf_path = pdf_file.name # Get the file path
142
- debug_info += f"PDF path: {pdf_path}\n"
143
-
144
- # Copy the PDF file to a location accessible by the public URL
145
- pdf_public_path = os.path.join(HTML_DIR, f"pdf_{session_id}.pdf")
146
- shutil.copy(pdf_path, pdf_public_path)
147
-
148
- # Create a simple HTML page with direct PDF loading
149
- html_filename = f"flipbook_{session_id}.html"
150
- html_path = os.path.join(HTML_DIR, html_filename)
151
-
152
- # Create HTML content that uses CDN resources
153
- html_content = create_flipbook_html_page(f"pdf_{session_id}.pdf", session_id, view_mode, skin)
154
-
155
- # Write the HTML file
156
- with open(html_path, 'w', encoding='utf-8') as f:
157
- f.write(html_content)
158
-
159
- # Generate link to the HTML file
160
- public_url = f"/public/flipbooks/{html_filename}"
161
- flipbook_link = generate_flipbook_link(public_url, session_id, view_mode, skin)
162
-
163
- return flipbook_link, debug_info
164
- else:
165
- return """<div style="color: red; padding: 20px;">PDF ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”.</div>""", "No file uploaded"
166
-
167
  except Exception as e:
168
  error_msg = f"Error creating flipbook from PDF: {e}"
169
  print(error_msg)
170
- return f"""<div style="color: red; padding: 20px;">์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {str(e)}</div>""", error_msg
 
 
 
 
171
 
172
  def create_flipbook_from_images(images, view_mode="2d", skin="light"):
173
  """Create a flipbook from uploaded images."""
 
130
  return pages_info
131
 
132
  def create_flipbook_from_pdf(pdf_file, view_mode="2d", skin="light"):
133
+ """Create a flipbook from an uploaded PDF."""
134
+ session_id = str(uuid.uuid4())
135
+ debug_info = ""
136
+
137
+ if not pdf_file:
138
+ return (
139
+ "<div style='color:red;padding:20px;'>PDF ํŒŒ์ผ์„ ์—…๋กœ๋“œํ•ด์ฃผ์„ธ์š”.</div>",
140
+ "No file uploaded",
141
+ )
142
+
143
  try:
144
+ pdf_path = pdf_file.name # Gradio File ๊ฐ์ฒด์˜ ์‹ค์ œ ๊ฒฝ๋กœ
145
+ debug_info += f"PDF path: {pdf_path}\n"
146
+
147
+ # 1) PDF ํŽ˜์ด์ง€๋ฅผ ์ด๋ฏธ์ง€๋กœ ๋ณ€ํ™˜
148
+ pages_info = process_pdf(pdf_path, session_id)
149
+ debug_info += f"Number of pages: {len(pages_info)}\n"
150
+
151
+ if not pages_info:
152
+ return (
153
+ "<div style='color:red;padding:20px;'>PDF ์ฒ˜๋ฆฌ ์‹คํŒจ.</div>",
154
+ "No pages processed",
155
+ )
156
+
157
+ # 2) ์ด๋ฏธ์ง€ ๋ฆฌ์ŠคํŠธ๋กœ ํ”Œ๋ฆฝ๋ถ HTML ์ƒ์„ฑ
158
+ iframe_html = generate_flipbook_html(
159
+ pages_info, session_id, view_mode, skin
160
+ )
161
+ return iframe_html, debug_info
162
+
 
 
 
 
 
 
 
 
 
 
 
 
 
163
  except Exception as e:
164
  error_msg = f"Error creating flipbook from PDF: {e}"
165
  print(error_msg)
166
+ return (
167
+ f"<div style='color:red;padding:20px;'>์˜ค๋ฅ˜๊ฐ€ ๋ฐœ์ƒํ–ˆ์Šต๋‹ˆ๋‹ค: {e}</div>",
168
+ error_msg,
169
+ )
170
+
171
 
172
  def create_flipbook_from_images(images, view_mode="2d", skin="light"):
173
  """Create a flipbook from uploaded images."""