Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -111,105 +111,100 @@ def process_images(image_paths, session_id):
|
|
111 |
thumb_path = os.path.join(thumbs_folder, f"thumb_{i + 1}.png")
|
112 |
create_thumbnail(img_path, thumb_path)
|
113 |
|
114 |
-
# Add interactive content to
|
115 |
html_content = ""
|
116 |
-
items = []
|
117 |
|
118 |
if i == 0: # First image example with HTML content
|
119 |
html_content = """
|
120 |
<div style="position: absolute; top: 50px; left: 50px; background-color: rgba(255,255,255,0.7); padding: 10px; border-radius: 5px;">
|
121 |
-
<
|
122 |
-
<
|
123 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
124 |
</div>
|
125 |
"""
|
126 |
-
elif i == 1: # Second image with video example (if available)
|
127 |
-
items = [
|
128 |
-
{
|
129 |
-
"type": "link",
|
130 |
-
"x": 50,
|
131 |
-
"y": 50,
|
132 |
-
"width": 200,
|
133 |
-
"height": 50,
|
134 |
-
"page": 1,
|
135 |
-
"title": "Previous image"
|
136 |
-
}
|
137 |
-
]
|
138 |
-
|
139 |
-
# Example of adding a YouTube video if it's the second image
|
140 |
-
if len(image_paths) > 1:
|
141 |
-
html_content = """
|
142 |
-
<iframe class="flipbook-page-item"
|
143 |
-
src="https://www.youtube.com/embed/dQw4w9WgXcQ"
|
144 |
-
style="top:200px;left:50px;width:300px;height:200px;"
|
145 |
-
frameborder="0"
|
146 |
-
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
|
147 |
-
allowfullscreen="">
|
148 |
-
</iframe>
|
149 |
-
"""
|
150 |
|
151 |
-
#
|
152 |
-
|
153 |
-
"src":
|
154 |
-
"thumb":
|
155 |
-
"title": f"
|
156 |
-
"htmlContent": html_content if html_content else None
|
157 |
-
|
158 |
-
|
|
|
|
|
|
|
159 |
except Exception as e:
|
160 |
print(f"Error processing image {img_path}: {e}")
|
161 |
|
162 |
return pages_info
|
163 |
|
164 |
-
def create_flipbook_from_pdf(pdf_file, view_mode="
|
165 |
"""Create a flipbook from uploaded PDF."""
|
166 |
try:
|
167 |
session_id = str(uuid.uuid4())
|
168 |
pages_info = []
|
|
|
169 |
|
170 |
if pdf_file is not None:
|
171 |
# In Gradio, pdf_file is a file path string, not the actual content
|
172 |
pdf_path = pdf_file.name # Get the file path
|
|
|
173 |
|
174 |
# Process PDF using the file path directly
|
175 |
pages_info = process_pdf(pdf_path, session_id)
|
|
|
176 |
else:
|
177 |
-
return """<div style="color: red; padding: 20px;">
|
178 |
|
179 |
if not pages_info:
|
180 |
-
return """<div style="color: red; padding: 20px;">
|
181 |
|
182 |
# Create and return HTML for the flipbook
|
183 |
flipbook_html = generate_flipbook_html(pages_info, session_id, view_mode, skin)
|
184 |
-
|
|
|
185 |
|
186 |
except Exception as e:
|
187 |
-
|
188 |
-
|
|
|
189 |
|
190 |
-
def create_flipbook_from_images(images, view_mode="
|
191 |
"""Create a flipbook from uploaded images."""
|
192 |
try:
|
193 |
session_id = str(uuid.uuid4())
|
194 |
pages_info = []
|
|
|
195 |
|
196 |
if images is not None and len(images) > 0:
|
197 |
# Process images using file paths
|
198 |
image_paths = [img.name for img in images]
|
|
|
|
|
199 |
pages_info = process_images(image_paths, session_id)
|
|
|
200 |
else:
|
201 |
-
return """<div style="color: red; padding: 20px;"
|
202 |
|
203 |
if not pages_info:
|
204 |
-
return """<div style="color: red; padding: 20px;"
|
205 |
|
206 |
# Create and return HTML for the flipbook
|
207 |
flipbook_html = generate_flipbook_html(pages_info, session_id, view_mode, skin)
|
208 |
-
|
|
|
209 |
|
210 |
except Exception as e:
|
211 |
-
|
212 |
-
|
|
|
213 |
|
214 |
def generate_flipbook_html(pages_info, session_id, view_mode, skin):
|
215 |
"""Generate HTML for the flipbook."""
|
@@ -228,149 +223,175 @@ def generate_flipbook_html(pages_info, session_id, view_mode, skin):
|
|
228 |
|
229 |
# HTML template with embedded CSS and JavaScript
|
230 |
html = f"""
|
231 |
-
|
232 |
-
|
233 |
-
<head>
|
234 |
-
<meta charset="UTF-8">
|
235 |
-
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
236 |
-
<title>3D Flipbook</title>
|
237 |
-
<style>
|
238 |
-
#flipbook-container {{
|
239 |
-
width: 100%;
|
240 |
-
height: 600px;
|
241 |
-
margin: 0 auto;
|
242 |
-
position: relative;
|
243 |
-
}}
|
244 |
-
body, html {{
|
245 |
-
margin: 0;
|
246 |
-
padding: 0;
|
247 |
-
height: 100%;
|
248 |
-
overflow: hidden;
|
249 |
-
}}
|
250 |
-
</style>
|
251 |
-
<link rel="stylesheet" type="text/css" href="flipbook.css">
|
252 |
-
</head>
|
253 |
-
<body>
|
254 |
-
<div id="{flipbook_id}" class="flipbook-container"></div>
|
255 |
-
|
256 |
-
<script src="flipbook.js"></script>
|
257 |
-
<script src="flipbook.webgl.js"></script>
|
258 |
-
<script src="flipbook.swipe.js"></script>
|
259 |
-
<script src="flipbook.scroll.js"></script>
|
260 |
-
<script src="flipbook.book3.js"></script>
|
261 |
|
262 |
<script>
|
263 |
-
//
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
272 |
-
|
273 |
-
|
274 |
-
|
275 |
-
|
276 |
-
|
277 |
-
|
278 |
-
|
279 |
-
|
280 |
-
|
281 |
-
|
282 |
-
|
283 |
-
|
284 |
-
|
285 |
-
|
286 |
-
|
287 |
-
|
288 |
-
|
289 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
290 |
}});
|
291 |
</script>
|
292 |
-
</
|
293 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
294 |
"""
|
295 |
return html
|
296 |
|
|
|
297 |
with gr.Blocks(title="3D Flipbook Viewer") as demo:
|
298 |
gr.Markdown("# 3D Flipbook Viewer")
|
299 |
gr.Markdown("""
|
300 |
-
##
|
301 |
|
302 |
-
|
303 |
|
304 |
-
###
|
305 |
-
-
|
306 |
-
-
|
307 |
-
-
|
308 |
-
-
|
|
|
309 |
""")
|
310 |
|
311 |
with gr.Tabs():
|
312 |
-
with gr.TabItem("PDF
|
313 |
-
pdf_file = gr.File(label="
|
314 |
|
315 |
-
with gr.Accordion("
|
316 |
-
pdf_view_mode = gr.
|
317 |
choices=["webgl", "3d", "2d", "swipe"],
|
318 |
-
value="
|
319 |
-
label="
|
|
|
320 |
)
|
321 |
-
pdf_skin = gr.
|
322 |
choices=["light", "dark", "gradient"],
|
323 |
value="light",
|
324 |
-
label="
|
|
|
325 |
)
|
326 |
|
327 |
-
pdf_create_btn = gr.Button("
|
328 |
-
|
|
|
329 |
|
330 |
# Set up PDF event handler
|
331 |
pdf_create_btn.click(
|
332 |
fn=create_flipbook_from_pdf,
|
333 |
inputs=[pdf_file, pdf_view_mode, pdf_skin],
|
334 |
-
outputs=pdf_output
|
335 |
)
|
336 |
|
337 |
-
with gr.TabItem("
|
338 |
-
images = gr.File(label="
|
339 |
|
340 |
-
with gr.Accordion("
|
341 |
-
img_view_mode = gr.
|
342 |
choices=["webgl", "3d", "2d", "swipe"],
|
343 |
-
value="
|
344 |
-
label="
|
|
|
345 |
)
|
346 |
-
img_skin = gr.
|
347 |
choices=["light", "dark", "gradient"],
|
348 |
value="light",
|
349 |
-
label="
|
|
|
350 |
)
|
351 |
|
352 |
-
img_create_btn = gr.Button("
|
353 |
-
|
|
|
354 |
|
355 |
# Set up image event handler
|
356 |
img_create_btn.click(
|
357 |
fn=create_flipbook_from_images,
|
358 |
inputs=[images, img_view_mode, img_skin],
|
359 |
-
outputs=img_output
|
360 |
)
|
361 |
|
362 |
gr.Markdown("""
|
363 |
-
###
|
364 |
-
1.
|
365 |
-
2.
|
366 |
-
3.
|
367 |
-
4.
|
368 |
-
5.
|
369 |
|
370 |
-
###
|
371 |
-
-
|
372 |
-
-
|
373 |
-
-
|
|
|
374 |
""")
|
375 |
|
376 |
|
|
|
111 |
thumb_path = os.path.join(thumbs_folder, f"thumb_{i + 1}.png")
|
112 |
create_thumbnail(img_path, thumb_path)
|
113 |
|
114 |
+
# Add interactive content as simple text overlays to avoid compatibility issues
|
115 |
html_content = ""
|
|
|
116 |
|
117 |
if i == 0: # First image example with HTML content
|
118 |
html_content = """
|
119 |
<div style="position: absolute; top: 50px; left: 50px; background-color: rgba(255,255,255,0.7); padding: 10px; border-radius: 5px;">
|
120 |
+
<div style="color: #333; font-size: 18px; font-weight: bold;">์ด๋ฏธ์ง ๊ฐค๋ฌ๋ฆฌ</div>
|
121 |
+
<div style="color: #666; margin-top: 5px;">๊ฐค๋ฌ๋ฆฌ์ ์ฒซ ๋ฒ์งธ ์ด๋ฏธ์ง์
๋๋ค.</div>
|
122 |
+
</div>
|
123 |
+
"""
|
124 |
+
elif i == 1: # Second image
|
125 |
+
html_content = """
|
126 |
+
<div style="position: absolute; top: 50px; left: 50px; background-color: rgba(255,255,255,0.7); padding: 10px; border-radius: 5px;">
|
127 |
+
<div style="color: #333; font-size: 18px; font-weight: bold;">๋ ๋ฒ์งธ ์ด๋ฏธ์ง</div>
|
128 |
+
<div style="color: #666; margin-top: 5px;">ํ์ด์ง๋ฅผ ๋๊ธฐ๊ฑฐ๋ ๋ชจ์๋ฆฌ๋ฅผ ๋๋๊ทธํ์ฌ ์ด๋ฏธ์ง๋ฅผ ํ์ํ ์ ์์ต๋๋ค.</div>
|
129 |
</div>
|
130 |
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
131 |
|
132 |
+
# Create a simpler page structure to avoid potential compatibility issues
|
133 |
+
page_info = {
|
134 |
+
"src": dest_path.replace("\\", "/"), # Ensure forward slashes for web paths
|
135 |
+
"thumb": thumb_path.replace("\\", "/"),
|
136 |
+
"title": f"์ด๋ฏธ์ง {i + 1}",
|
137 |
+
"htmlContent": html_content if html_content else None
|
138 |
+
}
|
139 |
+
|
140 |
+
pages_info.append(page_info)
|
141 |
+
print(f"Processed image {i+1}: {dest_path}")
|
142 |
+
|
143 |
except Exception as e:
|
144 |
print(f"Error processing image {img_path}: {e}")
|
145 |
|
146 |
return pages_info
|
147 |
|
148 |
+
def create_flipbook_from_pdf(pdf_file, view_mode="2d", skin="light"):
|
149 |
"""Create a flipbook from uploaded PDF."""
|
150 |
try:
|
151 |
session_id = str(uuid.uuid4())
|
152 |
pages_info = []
|
153 |
+
debug_info = ""
|
154 |
|
155 |
if pdf_file is not None:
|
156 |
# In Gradio, pdf_file is a file path string, not the actual content
|
157 |
pdf_path = pdf_file.name # Get the file path
|
158 |
+
debug_info += f"PDF path: {pdf_path}\n"
|
159 |
|
160 |
# Process PDF using the file path directly
|
161 |
pages_info = process_pdf(pdf_path, session_id)
|
162 |
+
debug_info += f"Number of pages processed: {len(pages_info)}\n"
|
163 |
else:
|
164 |
+
return """<div style="color: red; padding: 20px;">PDF ํ์ผ์ ์
๋ก๋ํด์ฃผ์ธ์.</div>""", "No file uploaded"
|
165 |
|
166 |
if not pages_info:
|
167 |
+
return """<div style="color: red; padding: 20px;">PDF ํ์ผ ์ฒ๋ฆฌ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ค์ ์๋ํด์ฃผ์ธ์.</div>""", "No pages processed"
|
168 |
|
169 |
# Create and return HTML for the flipbook
|
170 |
flipbook_html = generate_flipbook_html(pages_info, session_id, view_mode, skin)
|
171 |
+
debug_info += f"HTML generated with view mode: {view_mode}, skin: {skin}\n"
|
172 |
+
return flipbook_html, debug_info
|
173 |
|
174 |
except Exception as e:
|
175 |
+
error_msg = f"Error creating flipbook from PDF: {e}"
|
176 |
+
print(error_msg)
|
177 |
+
return f"""<div style="color: red; padding: 20px;">์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}</div>""", error_msg
|
178 |
|
179 |
+
def create_flipbook_from_images(images, view_mode="2d", skin="light"):
|
180 |
"""Create a flipbook from uploaded images."""
|
181 |
try:
|
182 |
session_id = str(uuid.uuid4())
|
183 |
pages_info = []
|
184 |
+
debug_info = ""
|
185 |
|
186 |
if images is not None and len(images) > 0:
|
187 |
# Process images using file paths
|
188 |
image_paths = [img.name for img in images]
|
189 |
+
debug_info += f"Image paths: {image_paths}\n"
|
190 |
+
|
191 |
pages_info = process_images(image_paths, session_id)
|
192 |
+
debug_info += f"Number of images processed: {len(pages_info)}\n"
|
193 |
else:
|
194 |
+
return """<div style="color: red; padding: 20px;">์ต์ ํ ๊ฐ ์ด์์ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํด์ฃผ์ธ์.</div>""", "No images uploaded"
|
195 |
|
196 |
if not pages_info:
|
197 |
+
return """<div style="color: red; padding: 20px;">์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค. ๋ค์ ์๋ํด์ฃผ์ธ์.</div>""", "No images processed"
|
198 |
|
199 |
# Create and return HTML for the flipbook
|
200 |
flipbook_html = generate_flipbook_html(pages_info, session_id, view_mode, skin)
|
201 |
+
debug_info += f"HTML generated with view mode: {view_mode}, skin: {skin}\n"
|
202 |
+
return flipbook_html, debug_info
|
203 |
|
204 |
except Exception as e:
|
205 |
+
error_msg = f"Error creating flipbook from images: {e}"
|
206 |
+
print(error_msg)
|
207 |
+
return f"""<div style="color: red; padding: 20px;">์ค๋ฅ๊ฐ ๋ฐ์ํ์ต๋๋ค: {str(e)}</div>""", error_msg
|
208 |
|
209 |
def generate_flipbook_html(pages_info, session_id, view_mode, skin):
|
210 |
"""Generate HTML for the flipbook."""
|
|
|
223 |
|
224 |
# HTML template with embedded CSS and JavaScript
|
225 |
html = f"""
|
226 |
+
<div style="height:700px; width:100%; position:relative; overflow:hidden; border:1px solid #ccc;">
|
227 |
+
<div id="{flipbook_id}" style="width:100%; height:100%;"></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
228 |
|
229 |
<script>
|
230 |
+
// Function to load scripts sequentially
|
231 |
+
function loadScript(src, callback) {{
|
232 |
+
let script = document.createElement('script');
|
233 |
+
script.src = src;
|
234 |
+
script.onload = callback;
|
235 |
+
document.head.appendChild(script);
|
236 |
+
}}
|
237 |
+
|
238 |
+
// Function to add CSS
|
239 |
+
function loadCSS(href) {{
|
240 |
+
let link = document.createElement('link');
|
241 |
+
link.rel = 'stylesheet';
|
242 |
+
link.type = 'text/css';
|
243 |
+
link.href = href;
|
244 |
+
document.head.appendChild(link);
|
245 |
+
}}
|
246 |
+
|
247 |
+
// Load CSS first
|
248 |
+
loadCSS('flipbook.css');
|
249 |
+
|
250 |
+
// Load scripts in sequence
|
251 |
+
loadScript('flipbook.js', function() {{
|
252 |
+
loadScript('flipbook.webgl.js', function() {{
|
253 |
+
loadScript('flipbook.swipe.js', function() {{
|
254 |
+
loadScript('flipbook.scroll.js', function() {{
|
255 |
+
loadScript('flipbook.book3.js', function() {{
|
256 |
+
// All scripts loaded, now initialize flipbook
|
257 |
+
const options = {{
|
258 |
+
pages: {pages_json},
|
259 |
+
viewMode: '{view_mode}',
|
260 |
+
skin: '{skin}',
|
261 |
+
responsiveView: true,
|
262 |
+
singlePageMode: false,
|
263 |
+
singlePageModeIfMobile: true,
|
264 |
+
pageFlipDuration: 1,
|
265 |
+
sound: true,
|
266 |
+
backgroundMusic: false,
|
267 |
+
thumbnailsOnStart: true,
|
268 |
+
btnThumbs: {{ enabled: true }},
|
269 |
+
btnPrint: {{ enabled: true }},
|
270 |
+
btnDownloadPages: {{ enabled: true }},
|
271 |
+
btnDownloadPdf: {{ enabled: true }},
|
272 |
+
btnShare: {{ enabled: true }},
|
273 |
+
btnSound: {{ enabled: true }},
|
274 |
+
btnExpand: {{ enabled: true }},
|
275 |
+
rightToLeft: false,
|
276 |
+
autoplayOnStart: false,
|
277 |
+
autoplayInterval: 3000
|
278 |
+
}};
|
279 |
+
|
280 |
+
try {{
|
281 |
+
const container = document.getElementById('{flipbook_id}');
|
282 |
+
if (container) {{
|
283 |
+
console.log("Container found, initializing flipbook");
|
284 |
+
new FlipBook(container, options);
|
285 |
+
}} else {{
|
286 |
+
console.error("Container not found: #{flipbook_id}");
|
287 |
+
}}
|
288 |
+
}} catch (error) {{
|
289 |
+
console.error("Error initializing flipbook:", error);
|
290 |
+
}}
|
291 |
+
}});
|
292 |
+
}});
|
293 |
+
}});
|
294 |
+
}});
|
295 |
}});
|
296 |
</script>
|
297 |
+
</div>
|
298 |
+
<div style="margin-top:20px; padding:10px; background-color:#f5f5f5; border-radius:5px;">
|
299 |
+
<p><strong>์ฐธ๊ณ :</strong> ํ๋ฆฝ๋ถ์ด ๋ณด์ด์ง ์๋ ๊ฒฝ์ฐ:</p>
|
300 |
+
<ol>
|
301 |
+
<li>ํ์ด์ง๋ฅผ ์๋ก๊ณ ์นจํ์ธ์.</li>
|
302 |
+
<li>๋ค๋ฅธ ๋ทฐ ๋ชจ๋๋ฅผ ์ ํํด๋ณด์ธ์ (์นGL ๋์ 2D ๋๋ 3D).</li>
|
303 |
+
<li>๋ธ๋ผ์ฐ์ ์ฝ์์์ ์ค๋ฅ ๋ฉ์์ง๋ฅผ ํ์ธํ์ธ์.</li>
|
304 |
+
</ol>
|
305 |
+
</div>
|
306 |
"""
|
307 |
return html
|
308 |
|
309 |
+
# Define the Gradio interface
|
310 |
with gr.Blocks(title="3D Flipbook Viewer") as demo:
|
311 |
gr.Markdown("# 3D Flipbook Viewer")
|
312 |
gr.Markdown("""
|
313 |
+
## 3D ํ๋ฆฝ๋ถ ๋ทฐ์ด
|
314 |
|
315 |
+
PDF ํ์ผ์ด๋ ์ฌ๋ฌ ์ด๋ฏธ์ง๋ฅผ ์
๋ก๋ํ์ฌ ์ธํฐ๋ํฐ๋ธ 3D ํ๋ฆฝ๋ถ์ ๋ง๋ค ์ ์์ต๋๋ค.
|
316 |
|
317 |
+
### ํน์ง:
|
318 |
+
- ํ์ด์ง ๋๊น ํจ๊ณผ์ ํจ๊ป ์ธํฐ๋ํฐ๋ธํ ๊ธฐ๋ฅ ์ ๊ณต
|
319 |
+
- ์ฒซ ํ์ด์ง์๋ ์์๋ก ์ธํฐ๋ํฐ๋ธ ์์๊ฐ ํฌํจ๋จ
|
320 |
+
- ํด๋ฐ๋ฅผ ์ฌ์ฉํ๊ฑฐ๋ ํ์ด์ง ๋ชจ์๋ฆฌ๋ฅผ ๋๋๊ทธํ์ฌ ํ์
|
321 |
+
- ์ธ๋ค์ผ ๋ณด๊ธฐ๋ก ๋น ๋ฅธ ํ์ ๊ฐ๋ฅ
|
322 |
+
- ์ ์ฒด ํ๋ฉด์ผ๋ก ์ ํํ์ฌ ๋ ๋์ ๋ณด๊ธฐ ๊ฒฝํ
|
323 |
""")
|
324 |
|
325 |
with gr.Tabs():
|
326 |
+
with gr.TabItem("PDF ์
๋ก๋"):
|
327 |
+
pdf_file = gr.File(label="PDF ํ์ผ ์
๋ก๋", file_types=[".pdf"])
|
328 |
|
329 |
+
with gr.Accordion("๊ณ ๊ธ ์ค์ ", open=False):
|
330 |
+
pdf_view_mode = gr.Radio(
|
331 |
choices=["webgl", "3d", "2d", "swipe"],
|
332 |
+
value="2d", # Changed default to 2d for better compatibility
|
333 |
+
label="๋ทฐ ๋ชจ๋",
|
334 |
+
info="WebGL: ์ต๊ณ ํ์ง, 2D: ๊ฐ์ฅ ์์ ์ , 3D: ์ค๊ฐ, Swipe: ๋ชจ๋ฐ์ผ์ฉ"
|
335 |
)
|
336 |
+
pdf_skin = gr.Radio(
|
337 |
choices=["light", "dark", "gradient"],
|
338 |
value="light",
|
339 |
+
label="์คํจ",
|
340 |
+
info="light: ๋ฐ์ ํ
๋ง, dark: ์ด๋์ด ํ
๋ง, gradient: ๊ทธ๋ผ๋ฐ์ด์
ํ
๋ง"
|
341 |
)
|
342 |
|
343 |
+
pdf_create_btn = gr.Button("PDF์์ ํ๋ฆฝ๋ถ ๋ง๋ค๊ธฐ", variant="primary", size="lg")
|
344 |
+
pdf_debug = gr.Textbox(label="๋๋ฒ๊ทธ ์ ๋ณด", visible=False)
|
345 |
+
pdf_output = gr.HTML(label="ํ๋ฆฝ๋ถ ๊ฒฐ๊ณผ๋ฌผ")
|
346 |
|
347 |
# Set up PDF event handler
|
348 |
pdf_create_btn.click(
|
349 |
fn=create_flipbook_from_pdf,
|
350 |
inputs=[pdf_file, pdf_view_mode, pdf_skin],
|
351 |
+
outputs=[pdf_output, pdf_debug]
|
352 |
)
|
353 |
|
354 |
+
with gr.TabItem("์ด๋ฏธ์ง ์
๋ก๋"):
|
355 |
+
images = gr.File(label="์ด๋ฏธ์ง ํ์ผ ์
๋ก๋", file_types=["image"], file_count="multiple")
|
356 |
|
357 |
+
with gr.Accordion("๊ณ ๊ธ ์ค์ ", open=False):
|
358 |
+
img_view_mode = gr.Radio(
|
359 |
choices=["webgl", "3d", "2d", "swipe"],
|
360 |
+
value="2d", # Changed default to 2d for better compatibility
|
361 |
+
label="๋ทฐ ๋ชจ๋",
|
362 |
+
info="WebGL: ์ต๊ณ ํ์ง, 2D: ๊ฐ์ฅ ์์ ์ , 3D: ์ค๊ฐ, Swipe: ๋ชจ๋ฐ์ผ์ฉ"
|
363 |
)
|
364 |
+
img_skin = gr.Radio(
|
365 |
choices=["light", "dark", "gradient"],
|
366 |
value="light",
|
367 |
+
label="์คํจ",
|
368 |
+
info="light: ๋ฐ์ ํ
๋ง, dark: ์ด๋์ด ํ
๋ง, gradient: ๊ทธ๋ผ๋ฐ์ด์
ํ
๋ง"
|
369 |
)
|
370 |
|
371 |
+
img_create_btn = gr.Button("์ด๋ฏธ์ง์์ ํ๋ฆฝ๋ถ ๋ง๋ค๊ธฐ", variant="primary", size="lg")
|
372 |
+
img_debug = gr.Textbox(label="๋๋ฒ๊ทธ ์ ๋ณด", visible=False)
|
373 |
+
img_output = gr.HTML(label="ํ๋ฆฝ๋ถ ๊ฒฐ๊ณผ๋ฌผ")
|
374 |
|
375 |
# Set up image event handler
|
376 |
img_create_btn.click(
|
377 |
fn=create_flipbook_from_images,
|
378 |
inputs=[images, img_view_mode, img_skin],
|
379 |
+
outputs=[img_output, img_debug]
|
380 |
)
|
381 |
|
382 |
gr.Markdown("""
|
383 |
+
### ์ฌ์ฉ๋ฒ:
|
384 |
+
1. ์ปจํ
์ธ ์ ํ์ ๋ฐ๋ผ ํญ์ ์ ํํ์ธ์ (PDF ๋๋ ์ด๋ฏธ์ง)
|
385 |
+
2. ํ์ผ์ ์
๋ก๋ํ์ธ์
|
386 |
+
3. ํ์์ ๋ฐ๋ผ ๊ณ ๊ธ ์ค์ ์์ ๋ทฐ ๋ชจ๋์ ์คํจ์ ์กฐ์ ํ์ธ์
|
387 |
+
4. ํ๋ฆฝ๋ถ ๋ง๋ค๊ธฐ ๋ฒํผ์ ํด๋ฆญํ์ธ์
|
388 |
+
5. ์ถ๋ ฅ ์์ญ์์ ํ๋ฆฝ๋ถ๊ณผ ์ํธ์์ฉํ์ธ์
|
389 |
|
390 |
+
### ์ฐธ๊ณ :
|
391 |
+
- ์ฒ์ ํ์ด์ง์๋ ์์๋ก ์ธํฐ๋ํฐ๋ธ ์์์ ๋งํฌ๊ฐ ํฌํจ๋์ด ์์ต๋๋ค
|
392 |
+
- ์ต์์ ๊ฒฐ๊ณผ๋ฅผ ์ํด ์ ๋ช
ํ ํ
์คํธ์ ์ด๋ฏธ์ง๊ฐ ์๋ PDF๋ฅผ ์ฌ์ฉํ์ธ์
|
393 |
+
- ์ง์๋๋ ์ด๋ฏธ์ง ํ์: JPG, PNG, GIF ๋ฑ
|
394 |
+
- ํ๋ฆฝ๋ถ์ด ๋ณด์ด์ง ์๋ ๊ฒฝ์ฐ, 2D ๋ชจ๋๋ฅผ ์ ํํ๊ณ ๋ค์ ์๋ํด๋ณด์ธ์
|
395 |
""")
|
396 |
|
397 |
|