erikbeltran commited on
Commit
8789230
·
verified ·
1 Parent(s): 2c7b642

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -8
app.py CHANGED
@@ -16,7 +16,7 @@ pipe = DiffusionPipeline.from_pretrained(base_model, torch_dtype=dtype, vae=taef
16
  MAX_SEED = 2**32-1
17
 
18
  @spaces.GPU()
19
- def generate_image(prompt, width, height, lora_path, trigger_word, steps):
20
  # Load LoRA weights
21
  pipe.load_lora_weights(lora_path)
22
 
@@ -37,10 +37,14 @@ def generate_image(prompt, width, height, lora_path, trigger_word, steps):
37
  generator=generator,
38
  ).images[0]
39
 
40
- # Generate a hash for the image
41
- image_bytes = image.tobytes()
42
- hash_object = hashlib.sha256(image_bytes)
43
- image_hash = hash_object.hexdigest()
 
 
 
 
44
 
45
  # Save the image with the hash as filename
46
  image_path = f"{image_hash}.png"
@@ -48,8 +52,8 @@ def generate_image(prompt, width, height, lora_path, trigger_word, steps):
48
 
49
  return image, image_hash
50
 
51
- def run_lora(prompt, width, height, lora_path, trigger_word, steps):
52
- return generate_image(prompt, width, height, lora_path, trigger_word, steps)
53
 
54
  # Set up the Gradio interface
55
  with gr.Blocks() as app:
@@ -69,6 +73,9 @@ with gr.Blocks() as app:
69
  with gr.Row():
70
  steps = gr.Slider(label="Inference Steps", minimum=1, maximum=100, step=1, value=28)
71
 
 
 
 
72
  generate_button = gr.Button("Generate Image")
73
 
74
  output_image = gr.Image(label="Generated Image")
@@ -76,7 +83,7 @@ with gr.Blocks() as app:
76
 
77
  generate_button.click(
78
  fn=run_lora,
79
- inputs=[prompt, width, height, lora_path, trigger_word, steps],
80
  outputs=[output_image, output_hash]
81
  )
82
 
 
16
  MAX_SEED = 2**32-1
17
 
18
  @spaces.GPU()
19
+ def generate_image(prompt, width, height, lora_path, trigger_word, steps, custom_hash):
20
  # Load LoRA weights
21
  pipe.load_lora_weights(lora_path)
22
 
 
37
  generator=generator,
38
  ).images[0]
39
 
40
+ # Generate or use provided hash for the image
41
+ if not custom_hash:
42
+ # Generate a hash if custom_hash is not provided
43
+ image_bytes = image.tobytes()
44
+ hash_object = hashlib.sha256(image_bytes)
45
+ image_hash = hash_object.hexdigest()
46
+ else:
47
+ image_hash = custom_hash
48
 
49
  # Save the image with the hash as filename
50
  image_path = f"{image_hash}.png"
 
52
 
53
  return image, image_hash
54
 
55
+ def run_lora(prompt, width, height, lora_path, trigger_word, steps, custom_hash):
56
+ return generate_image(prompt, width, height, lora_path, trigger_word, steps, custom_hash)
57
 
58
  # Set up the Gradio interface
59
  with gr.Blocks() as app:
 
73
  with gr.Row():
74
  steps = gr.Slider(label="Inference Steps", minimum=1, maximum=100, step=1, value=28)
75
 
76
+ with gr.Row():
77
+ custom_hash = gr.Textbox(label="Custom Hash (optional)", placeholder="Leave blank to auto-generate hash")
78
+
79
  generate_button = gr.Button("Generate Image")
80
 
81
  output_image = gr.Image(label="Generated Image")
 
83
 
84
  generate_button.click(
85
  fn=run_lora,
86
+ inputs=[prompt, width, height, lora_path, trigger_word, steps, custom_hash],
87
  outputs=[output_image, output_hash]
88
  )
89