Jangai commited on
Commit
cff0816
·
verified ·
1 Parent(s): 5cac164

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -13
app.py CHANGED
@@ -1,20 +1,26 @@
1
  import gradio as gr
2
- from PIL import Image
3
- import numpy as np
4
- import io
5
 
6
  def display_sketch(sketch):
7
- # Ensure the sketch is a numpy array
8
- if isinstance(sketch, dict):
9
- sketch = sketch["image"]
10
- if not isinstance(sketch, np.ndarray):
11
- raise ValueError("The sketch input is not a valid numpy array")
12
- return sketch
13
 
14
- with gr.Blocks() as demo:
15
- sketchpad = gr.Sketchpad(label="Draw Something")
16
- output_image = gr.Image(label="Your Sketch")
17
 
18
- sketchpad.change(display_sketch, inputs=sketchpad, outputs=output_image)
 
19
 
 
 
 
 
 
 
 
 
 
20
  demo.launch()
 
1
  import gradio as gr
 
 
 
2
 
3
  def display_sketch(sketch):
4
+ import numpy as np
5
+ from PIL import Image
6
+
7
+ image_data = sketch["image"]
8
+ img = Image.fromarray(np.uint8(image_data))
9
+ return img
10
 
11
+ # Define the sketchpad component
12
+ sketchpad = gr.Sketchpad(label="Draw Something")
 
13
 
14
+ # Define the image component to display the sketch
15
+ output_image = gr.Image(label="Your Sketch")
16
 
17
+ # Create the interface
18
+ demo = gr.Interface(
19
+ fn=display_sketch,
20
+ inputs=sketchpad,
21
+ outputs=output_image,
22
+ live=True
23
+ )
24
+
25
+ # Launch the app
26
  demo.launch()