Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -18,6 +18,7 @@ color_mapping = {
|
|
18 |
"Sky": (135, 206, 235) # Sky Blue
|
19 |
}
|
20 |
|
|
|
21 |
def predict(image):
|
22 |
# Decode the image from base64
|
23 |
image_data = np.frombuffer(base64.b64decode(image.split(",")[1]), np.uint8)
|
@@ -32,6 +33,10 @@ def predict(image):
|
|
32 |
generated_image = (generated_image * 255).astype(np.uint8) # Rescale to 0-255
|
33 |
return generated_image
|
34 |
|
|
|
|
|
|
|
|
|
35 |
# Create Gradio interface
|
36 |
with gr.Blocks() as demo:
|
37 |
gr.Markdown("<h1>Sketch to Draw Model</h1>")
|
@@ -39,21 +44,23 @@ with gr.Blocks() as demo:
|
|
39 |
with gr.Row():
|
40 |
with gr.Column():
|
41 |
# Create a sketchpad for drawing
|
42 |
-
canvas = gr.Sketchpad(label="Draw Here"
|
43 |
clear_btn = gr.Button("Clear")
|
44 |
generate_btn = gr.Button("Generate Image")
|
45 |
|
46 |
with gr.Column():
|
47 |
# Create color buttons for different terrains
|
|
|
|
|
|
|
|
|
|
|
48 |
for color_name, color in color_mapping.items():
|
49 |
-
gr.Button(color_name, variant="primary").click(fn=
|
50 |
-
|
51 |
output_image = gr.Image(label="Generated Image", type="numpy")
|
52 |
|
53 |
# Define the actions for buttons
|
54 |
-
def clear_canvas():
|
55 |
-
return np.zeros((400, 400, 3), dtype=np.uint8)
|
56 |
-
|
57 |
clear_btn.click(fn=clear_canvas, inputs=None, outputs=canvas)
|
58 |
|
59 |
# Click to generate an image
|
|
|
18 |
"Sky": (135, 206, 235) # Sky Blue
|
19 |
}
|
20 |
|
21 |
+
# Function to predict and generate image
|
22 |
def predict(image):
|
23 |
# Decode the image from base64
|
24 |
image_data = np.frombuffer(base64.b64decode(image.split(",")[1]), np.uint8)
|
|
|
33 |
generated_image = (generated_image * 255).astype(np.uint8) # Rescale to 0-255
|
34 |
return generated_image
|
35 |
|
36 |
+
# Function to clear the canvas
|
37 |
+
def clear_canvas():
|
38 |
+
return np.zeros((400, 400, 3), dtype=np.uint8)
|
39 |
+
|
40 |
# Create Gradio interface
|
41 |
with gr.Blocks() as demo:
|
42 |
gr.Markdown("<h1>Sketch to Draw Model</h1>")
|
|
|
44 |
with gr.Row():
|
45 |
with gr.Column():
|
46 |
# Create a sketchpad for drawing
|
47 |
+
canvas = gr.Sketchpad(label="Draw Here")
|
48 |
clear_btn = gr.Button("Clear")
|
49 |
generate_btn = gr.Button("Generate Image")
|
50 |
|
51 |
with gr.Column():
|
52 |
# Create color buttons for different terrains
|
53 |
+
brush_color = gr.Variable(default="black") # Variable to store brush color
|
54 |
+
|
55 |
+
def change_color(color):
|
56 |
+
brush_color.set(color) # Update the brush color
|
57 |
+
|
58 |
for color_name, color in color_mapping.items():
|
59 |
+
gr.Button(color_name, variant="primary").click(fn=change_color, inputs=color, outputs=None)
|
60 |
+
|
61 |
output_image = gr.Image(label="Generated Image", type="numpy")
|
62 |
|
63 |
# Define the actions for buttons
|
|
|
|
|
|
|
64 |
clear_btn.click(fn=clear_canvas, inputs=None, outputs=canvas)
|
65 |
|
66 |
# Click to generate an image
|