Skip to content

Commit 6caf833

Browse files
committed
Added a textbox to display time the generation process takes
1 parent 39ac60e commit 6caf833

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

Diff for: examples/apps/flux-demo.py

+16-11
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import os
1+
import time
22

33
import gradio as gr
44
import torch
@@ -51,13 +51,15 @@
5151

5252

5353
def generate_image(prompt, inference_step, batch_size=2):
54+
start_time = time.time()
5455
image = pipe(
5556
prompt,
5657
output_type="pil",
5758
num_inference_steps=inference_step,
5859
num_images_per_prompt=batch_size,
5960
).images
60-
return image
61+
end_time = time.time()
62+
return image, end_time - start_time
6163

6264

6365
generate_image(["Test"], 2)
@@ -88,8 +90,6 @@ def load_lora(path):
8890
print("Refitting Finished!")
8991

9092

91-
generate_image(["Test"], 2)
92-
9393
# Create Gradio interface
9494
with gr.Blocks(title="Flux Demo with Torch-TensorRT") as demo:
9595
gr.Markdown("# Flux Image Generation Demo Accelerated by Torch-TensorRT")
@@ -125,23 +125,28 @@ def load_lora(path):
125125
with gr.Column():
126126
# Output component
127127
output_image = gr.Gallery(label="Generated Image")
128+
time_taken = gr.Textbox(
129+
label="Generation Time (seconds)", interactive=False
130+
)
128131

129132
# Connect the button to the generation function
130133
model_dropdown.change(model_change, inputs=[model_dropdown])
134+
load_lora_btn.click(
135+
fn=load_lora,
136+
inputs=[
137+
lora_upload_path,
138+
],
139+
)
140+
141+
# Update generate button click to include time output
131142
generate_btn.click(
132143
fn=generate_image,
133144
inputs=[
134145
prompt_input,
135146
num_steps,
136147
batch_size,
137148
],
138-
outputs=output_image,
139-
)
140-
load_lora_btn.click(
141-
fn=load_lora,
142-
inputs=[
143-
lora_upload_path,
144-
],
149+
outputs=[output_image, time_taken],
145150
)
146151

147152
# Launch the interface

0 commit comments

Comments
 (0)