|
1 |
| -import os |
| 1 | +import time |
2 | 2 |
|
3 | 3 | import gradio as gr
|
4 | 4 | import torch
|
|
51 | 51 |
|
52 | 52 |
|
53 | 53 | def generate_image(prompt, inference_step, batch_size=2):
|
| 54 | + start_time = time.time() |
54 | 55 | image = pipe(
|
55 | 56 | prompt,
|
56 | 57 | output_type="pil",
|
57 | 58 | num_inference_steps=inference_step,
|
58 | 59 | num_images_per_prompt=batch_size,
|
59 | 60 | ).images
|
60 |
| - return image |
| 61 | + end_time = time.time() |
| 62 | + return image, end_time - start_time |
61 | 63 |
|
62 | 64 |
|
63 | 65 | generate_image(["Test"], 2)
|
@@ -88,8 +90,6 @@ def load_lora(path):
|
88 | 90 | print("Refitting Finished!")
|
89 | 91 |
|
90 | 92 |
|
91 |
| -generate_image(["Test"], 2) |
92 |
| - |
93 | 93 | # Create Gradio interface
|
94 | 94 | with gr.Blocks(title="Flux Demo with Torch-TensorRT") as demo:
|
95 | 95 | gr.Markdown("# Flux Image Generation Demo Accelerated by Torch-TensorRT")
|
@@ -125,23 +125,28 @@ def load_lora(path):
|
125 | 125 | with gr.Column():
|
126 | 126 | # Output component
|
127 | 127 | output_image = gr.Gallery(label="Generated Image")
|
| 128 | + time_taken = gr.Textbox( |
| 129 | + label="Generation Time (seconds)", interactive=False |
| 130 | + ) |
128 | 131 |
|
129 | 132 | # Connect the button to the generation function
|
130 | 133 | 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 |
131 | 142 | generate_btn.click(
|
132 | 143 | fn=generate_image,
|
133 | 144 | inputs=[
|
134 | 145 | prompt_input,
|
135 | 146 | num_steps,
|
136 | 147 | batch_size,
|
137 | 148 | ],
|
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], |
145 | 150 | )
|
146 | 151 |
|
147 | 152 | # Launch the interface
|
|
0 commit comments