chandrujobs commited on
Commit
54ba740
·
verified ·
1 Parent(s): c1d31c9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -7
app.py CHANGED
@@ -1,6 +1,5 @@
1
  import gradio as gr
2
  from PIL import Image
3
- import numpy as np
4
  import random
5
  from io import BytesIO
6
 
@@ -63,7 +62,11 @@ def generate_palette_image(colors):
63
  img = Image.new('RGB', (color_width, img_height), color)
64
  palette_img.paste(img, (i * color_width, 0))
65
 
66
- return palette_img # Return PIL image directly
 
 
 
 
67
 
68
  # Function to generate the CSS code for the color palette
69
  def generate_css_code(colors):
@@ -99,10 +102,7 @@ def generate_palette(image_path):
99
  def gradio_interface(image_path):
100
  palette_html, palette_img, css_code = generate_palette(image_path)
101
 
102
- # Convert PIL image to NumPy array (Gradio expects a NumPy array or filepath)
103
- palette_img_np = np.array(palette_img)
104
-
105
- return palette_html, palette_img_np, css_code
106
 
107
  # Create the Gradio interface
108
  with gr.Blocks() as interface:
@@ -124,5 +124,5 @@ with gr.Blocks() as interface:
124
  clear_btn.click(lambda: [None, None, None, None], inputs=[], outputs=[
125
  image_input, palette_output, palette_image_output, css_code_output])
126
 
127
- # Launch the interface (without `share=True`)
128
  interface.launch()
 
1
  import gradio as gr
2
  from PIL import Image
 
3
  import random
4
  from io import BytesIO
5
 
 
62
  img = Image.new('RGB', (color_width, img_height), color)
63
  palette_img.paste(img, (i * color_width, 0))
64
 
65
+ # Save the image to a file in memory
66
+ buf = BytesIO()
67
+ palette_img.save(buf, format='PNG')
68
+ buf.seek(0)
69
+ return buf
70
 
71
  # Function to generate the CSS code for the color palette
72
  def generate_css_code(colors):
 
102
  def gradio_interface(image_path):
103
  palette_html, palette_img, css_code = generate_palette(image_path)
104
 
105
+ return palette_html, palette_img, css_code
 
 
 
106
 
107
  # Create the Gradio interface
108
  with gr.Blocks() as interface:
 
124
  clear_btn.click(lambda: [None, None, None, None], inputs=[], outputs=[
125
  image_input, palette_output, palette_image_output, css_code_output])
126
 
127
+ # Launch the interface
128
  interface.launch()