atharvapawar commited on
Commit
983b7f3
·
verified ·
1 Parent(s): a026198

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +8 -3
app.py CHANGED
@@ -21,7 +21,12 @@ def image_to_base64(image):
21
  image.save(buffered, format="JPEG")
22
  return base64.b64encode(buffered.getvalue()).decode()
23
 
24
- def handle_upload(image, prompt):
 
 
 
 
 
25
  upscaled_image = upscale_image(image, prompt)
26
  base64_str = image_to_base64(upscaled_image)
27
  return base64_str
@@ -32,11 +37,11 @@ def main():
32
 
33
  with gr.Row():
34
  with gr.Column(scale=1):
35
- image_input = gr.Image(type="pil", label="Low-Resolution Image")
36
  prompt_input = gr.Textbox(label="Prompt", value="a white cat")
37
 
38
  upload_btn = gr.Button("Upload and Upscale")
39
- base64_output = gr.Textbox(label="Base64 Encoded Image")
40
 
41
  upload_btn.click(fn=handle_upload, inputs=[image_input, prompt_input], outputs=[base64_output])
42
 
 
21
  image.save(buffered, format="JPEG")
22
  return base64.b64encode(buffered.getvalue()).decode()
23
 
24
+ def base64_to_image(base64_str):
25
+ image_data = base64.b64decode(base64_str)
26
+ return Image.open(BytesIO(image_data))
27
+
28
+ def handle_upload(base64_image, prompt):
29
+ image = base64_to_image(base64_image)
30
  upscaled_image = upscale_image(image, prompt)
31
  base64_str = image_to_base64(upscaled_image)
32
  return base64_str
 
37
 
38
  with gr.Row():
39
  with gr.Column(scale=1):
40
+ image_input = gr.Textbox(label="Base64 Encoded Low-Resolution Image")
41
  prompt_input = gr.Textbox(label="Prompt", value="a white cat")
42
 
43
  upload_btn = gr.Button("Upload and Upscale")
44
+ base64_output = gr.Textbox(label="Base64 Encoded Upscaled Image")
45
 
46
  upload_btn.click(fn=handle_upload, inputs=[image_input, prompt_input], outputs=[base64_output])
47