Update app.py
Browse files
app.py
CHANGED
|
@@ -17,7 +17,7 @@ session = GenerationSession(model_id)
|
|
| 17 |
api_client = InferenceClient()
|
| 18 |
target_model = "simianluo/lcm_dreamshaper_v7"
|
| 19 |
|
| 20 |
-
def dynamic_cloud_call(prompt, image=None, strength=0.45
|
| 21 |
if image is None:
|
| 22 |
output_image = api_client.text_to_image(prompt, model=target_model)
|
| 23 |
else:
|
|
@@ -30,15 +30,27 @@ def dynamic_cloud_call(prompt, image=None, strength=0.45, **kwargs):
|
|
| 30 |
def ui_handler(user_prompt):
|
| 31 |
start_time = time.time()
|
| 32 |
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 38 |
session.current_image = final_image
|
| 39 |
-
session.current_prompt =
|
| 40 |
-
|
| 41 |
-
|
| 42 |
end_time = time.time()
|
| 43 |
return final_image, enhanced_text, f"Total generation time: {end_time - start_time:.2f}s"
|
| 44 |
|
|
@@ -67,4 +79,9 @@ with gr.Blocks(title="Active Image Generator", theme=gr.Theme.from_hub("Respair/
|
|
| 67 |
|
| 68 |
reset_button.click(
|
| 69 |
fn=ui_reset,
|
| 70 |
-
inputs=None,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
api_client = InferenceClient()
|
| 18 |
target_model = "simianluo/lcm_dreamshaper_v7"
|
| 19 |
|
| 20 |
+
def dynamic_cloud_call(prompt, image=None, strength=0.45):
|
| 21 |
if image is None:
|
| 22 |
output_image = api_client.text_to_image(prompt, model=target_model)
|
| 23 |
else:
|
|
|
|
| 30 |
def ui_handler(user_prompt):
|
| 31 |
start_time = time.time()
|
| 32 |
|
| 33 |
+
try:
|
| 34 |
+
image_list, enhanced_text = smart_generate(user_prompt, session, strength=0.45)
|
| 35 |
+
if isinstance(image_list, list) and len(image_list) > 0:
|
| 36 |
+
base_img = image_list
|
| 37 |
+
else:
|
| 38 |
+
base_img = image_list
|
| 39 |
+
|
| 40 |
+
if hasattr(base_img, "save"):
|
| 41 |
+
final_image = base_img
|
| 42 |
+
else:
|
| 43 |
+
raise ValueError()
|
| 44 |
+
except Exception:
|
| 45 |
+
enhanced_text = user_prompt
|
| 46 |
+
if session.current_image is None:
|
| 47 |
+
final_image = dynamic_cloud_call(prompt=user_prompt)
|
| 48 |
+
else:
|
| 49 |
+
final_image = dynamic_cloud_call(prompt=user_prompt, image=session.current_image, strength=0.45)
|
| 50 |
+
|
| 51 |
session.current_image = final_image
|
| 52 |
+
session.current_prompt = enhanced_text
|
| 53 |
+
|
|
|
|
| 54 |
end_time = time.time()
|
| 55 |
return final_image, enhanced_text, f"Total generation time: {end_time - start_time:.2f}s"
|
| 56 |
|
|
|
|
| 79 |
|
| 80 |
reset_button.click(
|
| 81 |
fn=ui_reset,
|
| 82 |
+
inputs=None,
|
| 83 |
+
outputs=[output_image, enhanced_prompt, time_output]
|
| 84 |
+
)
|
| 85 |
+
|
| 86 |
+
if __name__ == "__main__":
|
| 87 |
+
demo.launch()
|