CyberRohith commited on
Commit
c791c40
·
verified ·
1 Parent(s): 2480131

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -7
app.py CHANGED
@@ -1,10 +1,12 @@
1
  import gradio as gr
2
  import torch
 
 
3
  if not hasattr(torch, 'float8_e8m0fnu'):
4
  torch.float8_e8m0fnu = torch.float16
 
5
  from LLM_pipeline import smart_generate
6
  from model_loading import GenerationSession
7
- import time
8
 
9
  model_id = "runwayml/stable-diffusion-v1-5"
10
  session = GenerationSession(model_id)
@@ -15,7 +17,7 @@ def ui_handler(user_prompt):
15
  final_image = image_list if isinstance(image_list, list) else image_list
16
  end_time = time.time()
17
  print(f"Image generation time: {end_time:.2f}s")
18
-
19
  return final_image, enhanced_text, f"Total generation time: {end_time - start_time:.2f}s"
20
 
21
  def ui_reset():
@@ -24,18 +26,30 @@ def ui_reset():
24
 
25
  with gr.Blocks(title="Active Image Generator", theme=gr.Theme.from_hub("Respair/Shiki")) as demo:
26
  gr.Markdown("## Active Image Generator\n\nEnter a prompt to generate or modify an image. Each new prompt will build upon the previous image, creating a dynamic and evolving visual experience. Use the reset button to start fresh with a new base image.")
27
-
28
  with gr.Row():
29
  prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Describe the image you want to create or modify...")
30
  generate_button = gr.Button("Generate", variant="primary")
31
  reset_button = gr.Button("Reset Session", variant="secondary")
32
-
33
  with gr.Column():
34
  output_image = gr.Image(label="Generated Image")
35
  enhanced_prompt = gr.Textbox(label="Enhanced Prompt", interactive=False)
 
 
36
 
37
- generate_button.click(fn=ui_handler, inputs=prompt_input, outputs=[output_image, enhanced_prompt, gr.Textbox(label="Generation Time", interactive=False)])
38
- reset_button.click(fn=ui_reset, inputs=None, outputs=[output_image, enhanced_prompt, gr.Textbox(label="Generation Time", interactive=False)])
 
 
 
 
 
 
 
 
 
 
39
 
40
  if __name__ == "__main__":
41
- demo.launch()
 
1
  import gradio as gr
2
  import torch
3
+ import time
4
+
5
  if not hasattr(torch, 'float8_e8m0fnu'):
6
  torch.float8_e8m0fnu = torch.float16
7
+
8
  from LLM_pipeline import smart_generate
9
  from model_loading import GenerationSession
 
10
 
11
  model_id = "runwayml/stable-diffusion-v1-5"
12
  session = GenerationSession(model_id)
 
17
  final_image = image_list if isinstance(image_list, list) else image_list
18
  end_time = time.time()
19
  print(f"Image generation time: {end_time:.2f}s")
20
+
21
  return final_image, enhanced_text, f"Total generation time: {end_time - start_time:.2f}s"
22
 
23
  def ui_reset():
 
26
 
27
  with gr.Blocks(title="Active Image Generator", theme=gr.Theme.from_hub("Respair/Shiki")) as demo:
28
  gr.Markdown("## Active Image Generator\n\nEnter a prompt to generate or modify an image. Each new prompt will build upon the previous image, creating a dynamic and evolving visual experience. Use the reset button to start fresh with a new base image.")
29
+
30
  with gr.Row():
31
  prompt_input = gr.Textbox(label="Enter your prompt", placeholder="Describe the image you want to create or modify...")
32
  generate_button = gr.Button("Generate", variant="primary")
33
  reset_button = gr.Button("Reset Session", variant="secondary")
34
+
35
  with gr.Column():
36
  output_image = gr.Image(label="Generated Image")
37
  enhanced_prompt = gr.Textbox(label="Enhanced Prompt", interactive=False)
38
+ # Fix: Defined the component here and assigned it to a variable
39
+ time_output = gr.Textbox(label="Generation Time", interactive=False)
40
 
41
+ # Fix: Used the variable 'time_output' in the outputs list
42
+ generate_button.click(
43
+ fn=ui_handler,
44
+ inputs=prompt_input,
45
+ outputs=[output_image, enhanced_prompt, time_output]
46
+ )
47
+
48
+ reset_button.click(
49
+ fn=ui_reset,
50
+ inputs=None,
51
+ outputs=[output_image, enhanced_prompt, time_output]
52
+ )
53
 
54
  if __name__ == "__main__":
55
+ demo.launch()