Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
|
@@ -36,7 +36,7 @@ print(device)
|
|
| 36 |
def wait_for_image_with_prefix(folder, prefix):
|
| 37 |
def is_file_ready(file_path):
|
| 38 |
initial_size = os.path.getsize(file_path)
|
| 39 |
-
time.sleep(
|
| 40 |
return initial_size == os.path.getsize(file_path)
|
| 41 |
|
| 42 |
while True:
|
|
@@ -51,7 +51,7 @@ def wait_for_image_with_prefix(folder, prefix):
|
|
| 51 |
|
| 52 |
if is_file_ready(latest_image):
|
| 53 |
# Wait a bit more to ensure the file is completely written
|
| 54 |
-
time.sleep(
|
| 55 |
return latest_image
|
| 56 |
|
| 57 |
# If no matching file found, wait before checking again
|
|
@@ -133,9 +133,12 @@ def generate_image(prompt, image):
|
|
| 133 |
finally:
|
| 134 |
if process and process.poll() is None:
|
| 135 |
process.terminate()
|
|
|
|
| 136 |
try:
|
|
|
|
| 137 |
process.wait(timeout=5)
|
| 138 |
except subprocess.TimeoutExpired:
|
|
|
|
| 139 |
process.kill()
|
| 140 |
|
| 141 |
|
|
|
|
| 36 |
def wait_for_image_with_prefix(folder, prefix):
|
| 37 |
def is_file_ready(file_path):
|
| 38 |
initial_size = os.path.getsize(file_path)
|
| 39 |
+
time.sleep(1)
|
| 40 |
return initial_size == os.path.getsize(file_path)
|
| 41 |
|
| 42 |
while True:
|
|
|
|
| 51 |
|
| 52 |
if is_file_ready(latest_image):
|
| 53 |
# Wait a bit more to ensure the file is completely written
|
| 54 |
+
time.sleep(3)
|
| 55 |
return latest_image
|
| 56 |
|
| 57 |
# If no matching file found, wait before checking again
|
|
|
|
| 133 |
finally:
|
| 134 |
if process and process.poll() is None:
|
| 135 |
process.terminate()
|
| 136 |
+
logger.debug("process.terminate()")
|
| 137 |
try:
|
| 138 |
+
logger.debug("process.wait(timeout=5)")
|
| 139 |
process.wait(timeout=5)
|
| 140 |
except subprocess.TimeoutExpired:
|
| 141 |
+
logger.debug("process.kill()")
|
| 142 |
process.kill()
|
| 143 |
|
| 144 |
|