emban362 EduardoM102 commited on
Commit
82731d0
·
verified ·
1 Parent(s): c61dbbb

base64 encoding (#1)

Browse files

- read from base64 (3c18f7a0804a94b8cdd4b7b8b67378fd38716933)


Co-authored-by: EduardoM Magdaleno <[email protected]>

Files changed (1) hide show
  1. app.py +10 -8
app.py CHANGED
@@ -24,7 +24,8 @@ import gradio as gr
24
  from gradio_imageslider import ImageSlider
25
 
26
  from huggingface_hub import hf_hub_download
27
-
 
28
  USE_TORCH_COMPILE = False
29
  ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
30
 
@@ -161,17 +162,16 @@ def prepare_image(input_image, resolution, hdr):
161
 
162
  @spaces.GPU
163
  @timer_func
164
- def gradio_process_image(input_image, resolution, num_inference_steps, strength, hdr, guidance_scale):
165
  print("Starting image processing...")
166
  torch.cuda.empty_cache()
 
 
167
 
168
  condition_image = prepare_image(input_image, resolution, hdr)
169
 
170
- # prompt = "masterpiece, best quality, highres"
171
- # negative_prompt = "low quality, normal quality, ugly, blurry, blur, lowres, bad anatomy, bad hands, cropped, worst quality, verybadimagenegative_v1.3, JuggernautNegative-neg"
172
-
173
- prompt = ""
174
- negative_prompt = ""
175
 
176
  options = {
177
  "prompt": prompt,
@@ -209,6 +209,8 @@ with gr.Blocks() as demo:
209
  with gr.Row():
210
  with gr.Column():
211
  input_image = gr.Image(type="pil", label="Input Image")
 
 
212
  run_button = gr.Button("Enhance Image")
213
  with gr.Column():
214
  output_slider = ImageSlider(label="Before / After", type="numpy")
@@ -220,7 +222,7 @@ with gr.Blocks() as demo:
220
  guidance_scale = gr.Slider(minimum=0, maximum=20, value=3, step=0.5, label="Guidance Scale")
221
 
222
  run_button.click(fn=gradio_process_image,
223
- inputs=[input_image, resolution, num_inference_steps, strength, hdr, guidance_scale],
224
  outputs=output_slider)
225
 
226
  # # Add examples with all required inputs
 
24
  from gradio_imageslider import ImageSlider
25
 
26
  from huggingface_hub import hf_hub_download
27
+ import base64
28
+ from io import BytesIO
29
  USE_TORCH_COMPILE = False
30
  ENABLE_CPU_OFFLOAD = os.getenv("ENABLE_CPU_OFFLOAD", "0") == "1"
31
 
 
162
 
163
  @spaces.GPU
164
  @timer_func
165
+ def gradio_process_image(input_image, input_base64, resolution, num_inference_steps, strength, hdr, guidance_scale):
166
  print("Starting image processing...")
167
  torch.cuda.empty_cache()
168
+ if input_base64 and len(input_base64) > 0:
169
+ input_image = Image.open(BytesIO(base64.b64decode(input_base64)))
170
 
171
  condition_image = prepare_image(input_image, resolution, hdr)
172
 
173
+ prompt = "masterpiece, best quality, highres"
174
+ negative_prompt = "low quality, normal quality, ugly, blurry, blur, lowres, bad anatomy, bad hands, cropped, worst quality, verybadimagenegative_v1.3, JuggernautNegative-neg"
 
 
 
175
 
176
  options = {
177
  "prompt": prompt,
 
209
  with gr.Row():
210
  with gr.Column():
211
  input_image = gr.Image(type="pil", label="Input Image")
212
+ input_base64 = gr.Textbox(label="OR Paste Base64 Encoded Image", lines=3)
213
+
214
  run_button = gr.Button("Enhance Image")
215
  with gr.Column():
216
  output_slider = ImageSlider(label="Before / After", type="numpy")
 
222
  guidance_scale = gr.Slider(minimum=0, maximum=20, value=3, step=0.5, label="Guidance Scale")
223
 
224
  run_button.click(fn=gradio_process_image,
225
+ inputs=[input_image, input_base64, resolution, num_inference_steps, strength, hdr, guidance_scale],
226
  outputs=output_slider)
227
 
228
  # # Add examples with all required inputs