Spaces:
Paused
Paused
pseudotheos
commited on
Commit
•
715339d
1
Parent(s):
33fe4d2
Update app.py
Browse files
app.py
CHANGED
@@ -258,32 +258,31 @@ async def generate_image(
|
|
258 |
):
|
259 |
async def generate_image_task():
|
260 |
try:
|
261 |
-
|
262 |
-
|
263 |
-
|
264 |
-
|
265 |
-
|
266 |
-
|
267 |
-
|
268 |
-
|
269 |
-
|
270 |
-
|
271 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
272 |
return "Failed to generate image"
|
273 |
|
274 |
-
# Save the generated image as binary data
|
275 |
-
output_image_io = io.BytesIO()
|
276 |
-
generated_image.save(output_image_io, format="PNG")
|
277 |
-
output_image_io.seek(0)
|
278 |
-
|
279 |
-
# Return the image as a streaming response
|
280 |
-
return StreamingResponse(content=output_image_io, media_type="image/png")
|
281 |
-
|
282 |
-
except Exception as e:
|
283 |
-
logger.error("Error occurred during image generation: %s", str(e))
|
284 |
-
return "Failed to generate image"
|
285 |
-
|
286 |
-
pass
|
287 |
try:
|
288 |
await queue_manager.add_task(generate_image_task)
|
289 |
position_in_queue = queue_manager.queue.qsize()
|
@@ -292,9 +291,7 @@ async def generate_image(
|
|
292 |
|
293 |
except Exception as e:
|
294 |
logger.error("Error occurred during image generation: %s", str(e))
|
295 |
-
return "Failed to add task to the queue"
|
296 |
-
|
297 |
-
|
298 |
|
299 |
async def start_fastapi():
|
300 |
# Get internal IP address
|
|
|
258 |
):
|
259 |
async def generate_image_task():
|
260 |
try:
|
261 |
+
# Save the uploaded image to a temporary file
|
262 |
+
temp_image_path = f"/tmp/{int(time.time())}_{image.filename}"
|
263 |
+
with open(temp_image_path, "wb") as temp_image:
|
264 |
+
temp_image.write(image.file.read())
|
265 |
+
|
266 |
+
# Open the uploaded image using PIL
|
267 |
+
control_image = Image.open(temp_image_path)
|
268 |
+
|
269 |
+
# Call existing inference function with the provided parameters
|
270 |
+
generated_image = inference(control_image, prompt, "", guidance_scale, controlnet_scale, 0, controlnet_end, upscaler_strength, seed, sampler_type)
|
271 |
+
if generated_image is None:
|
272 |
+
return "Failed to generate image"
|
273 |
+
|
274 |
+
# Save the generated image as binary data
|
275 |
+
output_image_io = io.BytesIO()
|
276 |
+
generated_image.save(output_image_io, format="PNG")
|
277 |
+
output_image_io.seek(0)
|
278 |
+
|
279 |
+
# Return the image as a streaming response
|
280 |
+
return StreamingResponse(content=output_image_io, media_type="image/png")
|
281 |
+
|
282 |
+
except Exception as e:
|
283 |
+
logger.error("Error occurred during image generation: %s", str(e))
|
284 |
return "Failed to generate image"
|
285 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
286 |
try:
|
287 |
await queue_manager.add_task(generate_image_task)
|
288 |
position_in_queue = queue_manager.queue.qsize()
|
|
|
291 |
|
292 |
except Exception as e:
|
293 |
logger.error("Error occurred during image generation: %s", str(e))
|
294 |
+
return "Failed to add task to the queue"
|
|
|
|
|
295 |
|
296 |
async def start_fastapi():
|
297 |
# Get internal IP address
|