Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -25,30 +25,26 @@ def dynamic_cloud_call(prompt, image=None, strength=0.45, **kwargs):
|
|
| 25 |
image.save(img_byte_arr, format='PNG')
|
| 26 |
img_bytes = img_byte_arr.getvalue()
|
| 27 |
output_image = api_client.image_to_image(img_bytes, prompt=prompt, model=target_model, strength=strength)
|
| 28 |
-
|
| 29 |
-
class DiffusersOutput:
|
| 30 |
-
def __init__(self, images):
|
| 31 |
-
self.images = [images] if not isinstance(images, list) else images
|
| 32 |
-
return DiffusersOutput(images=output_image)
|
| 33 |
-
|
| 34 |
-
if session.txt2img_pipeline is not None:
|
| 35 |
-
session.txt2img_pipeline.__class__.__call__ = dynamic_cloud_call
|
| 36 |
|
| 37 |
def ui_handler(user_prompt):
|
| 38 |
start_time = time.time()
|
| 39 |
-
image_list, enhanced_text = smart_generate(user_prompt, session, strength=0.45)
|
| 40 |
|
| 41 |
-
if
|
| 42 |
-
final_image =
|
| 43 |
else:
|
| 44 |
-
final_image =
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
end_time = time.time()
|
| 47 |
return final_image, enhanced_text, f"Total generation time: {end_time - start_time:.2f}s"
|
| 48 |
|
| 49 |
def ui_reset():
|
| 50 |
session.reset()
|
| 51 |
-
return None, "Session cleared.
|
| 52 |
|
| 53 |
with gr.Blocks(title="Active Image Generator", theme=gr.Theme.from_hub("Respair/Shiki")) as demo:
|
| 54 |
gr.Markdown("## Active Image Generator\n\nEnter a prompt to generate or modify an image.")
|
|
@@ -71,9 +67,4 @@ with gr.Blocks(title="Active Image Generator", theme=gr.Theme.from_hub("Respair/
|
|
| 71 |
|
| 72 |
reset_button.click(
|
| 73 |
fn=ui_reset,
|
| 74 |
-
inputs=None,
|
| 75 |
-
outputs=[output_image, enhanced_prompt, time_output]
|
| 76 |
-
)
|
| 77 |
-
|
| 78 |
-
if __name__ == "__main__":
|
| 79 |
-
demo.launch()
|
|
|
|
| 25 |
image.save(img_byte_arr, format='PNG')
|
| 26 |
img_bytes = img_byte_arr.getvalue()
|
| 27 |
output_image = api_client.image_to_image(img_bytes, prompt=prompt, model=target_model, strength=strength)
|
| 28 |
+
return output_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
|
| 30 |
def ui_handler(user_prompt):
|
| 31 |
start_time = time.time()
|
|
|
|
| 32 |
|
| 33 |
+
if session.current_image is None:
|
| 34 |
+
final_image = dynamic_cloud_call(prompt=user_prompt)
|
| 35 |
else:
|
| 36 |
+
final_image = dynamic_cloud_call(prompt=user_prompt, image=session.current_image, strength=0.45)
|
| 37 |
+
|
| 38 |
+
session.current_image = final_image
|
| 39 |
+
session.current_prompt = user_prompt
|
| 40 |
+
enhanced_text = user_prompt
|
| 41 |
|
| 42 |
end_time = time.time()
|
| 43 |
return final_image, enhanced_text, f"Total generation time: {end_time - start_time:.2f}s"
|
| 44 |
|
| 45 |
def ui_reset():
|
| 46 |
session.reset()
|
| 47 |
+
return None, "Session cleared.", "Session reset."
|
| 48 |
|
| 49 |
with gr.Blocks(title="Active Image Generator", theme=gr.Theme.from_hub("Respair/Shiki")) as demo:
|
| 50 |
gr.Markdown("## Active Image Generator\n\nEnter a prompt to generate or modify an image.")
|
|
|
|
| 67 |
|
| 68 |
reset_button.click(
|
| 69 |
fn=ui_reset,
|
| 70 |
+
inputs=None,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|