Update app.py
Browse files
app.py
CHANGED
@@ -13,7 +13,7 @@ from transformers import AutoModelForCausalLM, AutoTokenizer, AutoModel
|
|
13 |
from diffusers import StableDiffusionPipeline
|
14 |
from torch.utils.data import Dataset, DataLoader
|
15 |
import csv
|
16 |
-
from pdf2image import convert_from_path
|
17 |
import requests
|
18 |
from PIL import Image
|
19 |
import cv2
|
@@ -309,6 +309,10 @@ class DiffusionBuilder:
|
|
309 |
return self.pipeline(prompt, num_inference_steps=20).images[0]
|
310 |
|
311 |
# Utility Functions
|
|
|
|
|
|
|
|
|
312 |
def get_download_link(file_path, mime_type="text/plain", label="Download"):
|
313 |
with open(file_path, 'rb') as f:
|
314 |
data = f.read()
|
@@ -426,7 +430,7 @@ async def process_pdf_snapshot(pdf_path, mode="thumbnail"):
|
|
426 |
start_time = time.time()
|
427 |
status = st.empty()
|
428 |
status.text(f"Processing PDF Snapshot ({mode})... (0s)")
|
429 |
-
images = convert_from_path(pdf_path, dpi=200)
|
430 |
output_files = []
|
431 |
if mode == "thumbnail":
|
432 |
img = images[0].resize((int(images[0].width * 0.5), int(images[0].height * 0.5)), Image.Resampling.LANCZOS)
|
|
|
13 |
from diffusers import StableDiffusionPipeline
|
14 |
from torch.utils.data import Dataset, DataLoader
|
15 |
import csv
|
16 |
+
from pdf2image import convert_from_path
|
17 |
import requests
|
18 |
from PIL import Image
|
19 |
import cv2
|
|
|
309 |
return self.pipeline(prompt, num_inference_steps=20).images[0]
|
310 |
|
311 |
# Utility Functions
|
312 |
+
def generate_filename(sequence, ext="png"):
|
313 |
+
timestamp = time.strftime("%d%m%Y%H%M%S")
|
314 |
+
return f"{sequence}{timestamp}.{ext}"
|
315 |
+
|
316 |
def get_download_link(file_path, mime_type="text/plain", label="Download"):
|
317 |
with open(file_path, 'rb') as f:
|
318 |
data = f.read()
|
|
|
430 |
start_time = time.time()
|
431 |
status = st.empty()
|
432 |
status.text(f"Processing PDF Snapshot ({mode})... (0s)")
|
433 |
+
images = convert_from_path(pdf_path, dpi=200)
|
434 |
output_files = []
|
435 |
if mode == "thumbnail":
|
436 |
img = images[0].resize((int(images[0].width * 0.5), int(images[0].height * 0.5)), Image.Resampling.LANCZOS)
|