zhiweili
commited on
Commit
Β·
f614a18
1
Parent(s):
e4c1258
print time cost
Browse files- app_onediff.py +7 -4
app_onediff.py
CHANGED
|
@@ -49,7 +49,7 @@ base_pipe.unet = nexfort_compile(base_pipe.unet)
|
|
| 49 |
|
| 50 |
def create_demo() -> gr.Blocks:
|
| 51 |
|
| 52 |
-
@spaces.GPU(duration=
|
| 53 |
def text_to_image(
|
| 54 |
prompt:str,
|
| 55 |
steps:int,
|
|
@@ -62,7 +62,7 @@ def create_demo() -> gr.Blocks:
|
|
| 62 |
num_inference_steps=steps,
|
| 63 |
).images[0]
|
| 64 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
| 65 |
-
return generated_image
|
| 66 |
|
| 67 |
def get_time_cost(run_task_time, time_cost_str):
|
| 68 |
now_time = int(time.time()*1000)
|
|
@@ -84,12 +84,15 @@ def create_demo() -> gr.Blocks:
|
|
| 84 |
g_btn = gr.Button("Generate")
|
| 85 |
|
| 86 |
with gr.Row():
|
| 87 |
-
|
|
|
|
|
|
|
|
|
|
| 88 |
|
| 89 |
g_btn.click(
|
| 90 |
fn=text_to_image,
|
| 91 |
inputs=[prompt, steps],
|
| 92 |
-
outputs=[generated_image],
|
| 93 |
)
|
| 94 |
|
| 95 |
return demo
|
|
|
|
| 49 |
|
| 50 |
def create_demo() -> gr.Blocks:
|
| 51 |
|
| 52 |
+
@spaces.GPU(duration=30)
|
| 53 |
def text_to_image(
|
| 54 |
prompt:str,
|
| 55 |
steps:int,
|
|
|
|
| 62 |
num_inference_steps=steps,
|
| 63 |
).images[0]
|
| 64 |
run_task_time, time_cost_str = get_time_cost(run_task_time, time_cost_str)
|
| 65 |
+
return generated_image, time_cost_str
|
| 66 |
|
| 67 |
def get_time_cost(run_task_time, time_cost_str):
|
| 68 |
now_time = int(time.time()*1000)
|
|
|
|
| 84 |
g_btn = gr.Button("Generate")
|
| 85 |
|
| 86 |
with gr.Row():
|
| 87 |
+
with gr.Column:
|
| 88 |
+
generated_image = gr.Image(label="Generated Image", type="pil", interactive=False)
|
| 89 |
+
with gr.Column:
|
| 90 |
+
time_cost = gr.Textbox(label="Time Cost", lines=1, interactive=False)
|
| 91 |
|
| 92 |
g_btn.click(
|
| 93 |
fn=text_to_image,
|
| 94 |
inputs=[prompt, steps],
|
| 95 |
+
outputs=[generated_image, time_cost],
|
| 96 |
)
|
| 97 |
|
| 98 |
return demo
|