Spaces:
Sleeping
Sleeping
Commit
·
98f29b4
1
Parent(s):
da039a5
fabric system v2 fix
Browse files
app.py
CHANGED
@@ -134,7 +134,7 @@ def generate_urls(img, start_angle=0, end_angle=350, step=10):
|
|
134 |
return urls
|
135 |
|
136 |
|
137 |
-
async def download_images(img_urls,
|
138 |
# Compile a regex pattern to extract the angle from the URL
|
139 |
angle_pattern = re.compile(r'angle/(\d+)')
|
140 |
count_img_downloaded = 0 # Counter for downloaded images
|
@@ -153,7 +153,7 @@ async def download_images(img_urls, product_name, fabric_name):
|
|
153 |
if angle_match:
|
154 |
# Create a file name using the product name and the angle
|
155 |
angle_value = angle_match.group(1)
|
156 |
-
img_name = f"{
|
157 |
else:
|
158 |
# Default file name if the angle is not found
|
159 |
img_name = "product_unknown.jpg"
|
@@ -183,7 +183,7 @@ async def download_images(img_urls, product_name, fabric_name):
|
|
183 |
return zip_buffer # Return the zip file as a byte stream
|
184 |
|
185 |
|
186 |
-
async def process_images(username, password, product_url,
|
187 |
async with async_playwright() as playwright:
|
188 |
browser = await playwright.chromium.launch(headless=True)
|
189 |
context = await browser.new_context()
|
@@ -200,7 +200,7 @@ async def process_images(username, password, product_url, product_name, fabric_n
|
|
200 |
|
201 |
img = await siloshot_making(page, fabric_name)
|
202 |
img_urls = generate_urls(img, start_angle=0, end_angle=360, step=10)
|
203 |
-
zip_buffer = await download_images(img_urls
|
204 |
await browser.close()
|
205 |
return zip_buffer
|
206 |
|
|
|
134 |
return urls
|
135 |
|
136 |
|
137 |
+
async def download_images(img_urls, fabric_name):
|
138 |
# Compile a regex pattern to extract the angle from the URL
|
139 |
angle_pattern = re.compile(r'angle/(\d+)')
|
140 |
count_img_downloaded = 0 # Counter for downloaded images
|
|
|
153 |
if angle_match:
|
154 |
# Create a file name using the product name and the angle
|
155 |
angle_value = angle_match.group(1)
|
156 |
+
img_name = f"{angle_value}_{fabric_name}.png"
|
157 |
else:
|
158 |
# Default file name if the angle is not found
|
159 |
img_name = "product_unknown.jpg"
|
|
|
183 |
return zip_buffer # Return the zip file as a byte stream
|
184 |
|
185 |
|
186 |
+
async def process_images(username, password, product_url, fabric_name):
|
187 |
async with async_playwright() as playwright:
|
188 |
browser = await playwright.chromium.launch(headless=True)
|
189 |
context = await browser.new_context()
|
|
|
200 |
|
201 |
img = await siloshot_making(page, fabric_name)
|
202 |
img_urls = generate_urls(img, start_angle=0, end_angle=360, step=10)
|
203 |
+
zip_buffer = await download_images(img_urls)
|
204 |
await browser.close()
|
205 |
return zip_buffer
|
206 |
|