Spaces:
Build error
Build error
Refactor: Remove unused import and timeout handling in app.py
Browse files
app.py
CHANGED
|
@@ -90,7 +90,6 @@ import torch
|
|
| 90 |
from diffusers import StableDiffusionPipeline
|
| 91 |
import logging
|
| 92 |
from PIL import Image
|
| 93 |
-
import signal
|
| 94 |
|
| 95 |
# 配置日志记录
|
| 96 |
logging.basicConfig(level=logging.DEBUG)
|
|
@@ -108,17 +107,12 @@ def timeout_handler(signum, frame):
|
|
| 108 |
def generate_image(prompt):
|
| 109 |
try:
|
| 110 |
logging.debug("Starting image generation process...")
|
| 111 |
-
|
| 112 |
-
# 设置60秒超时
|
| 113 |
-
signal.signal(signal.SIGALRM, timeout_handler)
|
| 114 |
-
signal.alarm(900)
|
| 115 |
|
| 116 |
# 使用Stable Diffusion模型生成图像,减少图像尺寸
|
| 117 |
with torch.no_grad():
|
| 118 |
generated_images = pipe(prompt=prompt, height=256, width=256, num_inference_steps=20).images
|
| 119 |
-
|
| 120 |
-
signal.alarm(0) # 取消超时
|
| 121 |
-
|
| 122 |
if not generated_images or not isinstance(generated_images[0], Image.Image):
|
| 123 |
error_message = "Error: Generated image is not valid."
|
| 124 |
logging.error(error_message)
|
|
|
|
| 90 |
from diffusers import StableDiffusionPipeline
|
| 91 |
import logging
|
| 92 |
from PIL import Image
|
|
|
|
| 93 |
|
| 94 |
# 配置日志记录
|
| 95 |
logging.basicConfig(level=logging.DEBUG)
|
|
|
|
| 107 |
def generate_image(prompt):
|
| 108 |
try:
|
| 109 |
logging.debug("Starting image generation process...")
|
| 110 |
+
|
|
|
|
|
|
|
|
|
|
| 111 |
|
| 112 |
# 使用Stable Diffusion模型生成图像,减少图像尺寸
|
| 113 |
with torch.no_grad():
|
| 114 |
generated_images = pipe(prompt=prompt, height=256, width=256, num_inference_steps=20).images
|
| 115 |
+
|
|
|
|
|
|
|
| 116 |
if not generated_images or not isinstance(generated_images[0], Image.Image):
|
| 117 |
error_message = "Error: Generated image is not valid."
|
| 118 |
logging.error(error_message)
|