unused prompt to inpaint
Browse files
app.py
CHANGED
@@ -20,6 +20,8 @@ segmodel = load_learner("camvid-512.pkl")
|
|
20 |
|
21 |
working_size = (512, 512)
|
22 |
|
|
|
|
|
23 |
seg_vocabulary = ['Animal', 'Archway', 'Bicyclist', 'Bridge', 'Building', 'Car',
|
24 |
'CartLuggagePram', 'Child', 'Column_Pole', 'Fence', 'LaneMkgsDriv',
|
25 |
'LaneMkgsNonDriv', 'Misc_Text', 'MotorcycleScooter', 'OtherMoving',
|
@@ -40,38 +42,18 @@ def get_seg_mask(img):
|
|
40 |
mask = segmodel.predict(img)[0]
|
41 |
return mask
|
42 |
|
43 |
-
def display_mask(img, mask):
|
44 |
-
# Convert the grayscale mask to RGB
|
45 |
-
mask_rgb = np.stack([np.zeros_like(mask), mask, np.zeros_like(mask)], axis=-1)
|
46 |
-
# Convert the image to PIL format
|
47 |
-
img_pil = Image.fromarray(img)
|
48 |
-
# Convert the mask to PIL format
|
49 |
-
mask_pil = Image.fromarray((mask_rgb * 255).astype(np.uint8))
|
50 |
-
# Overlay the mask on the image
|
51 |
-
overlaid_img = Image.blend(img_pil, mask_pil, alpha=0.5)
|
52 |
-
return overlaid_img
|
53 |
-
|
54 |
-
def redact_image(img):
|
55 |
-
img = img.resize((256, 256))
|
56 |
-
mask = get_seg_mask(img)
|
57 |
-
car_mask = ban_cars_mask[mask]
|
58 |
-
return display_mask(img, car_mask)
|
59 |
-
|
60 |
-
def flip(img):
|
61 |
-
return np.flipud(img)
|
62 |
-
|
63 |
|
64 |
-
def app(img):
|
65 |
start_time = datetime.now().timestamp()
|
66 |
img = img.resize(working_size)
|
67 |
mask = ban_cars_mask[get_seg_mask(img)]
|
68 |
overlay_img = Image.fromarray(np.stack([img[:, :, 0], mask / 2, img[:,:,2]], axis=-1))
|
69 |
end_time = datetime.now().timestamp()
|
70 |
draw = ImageDraw.Draw(overlay_img)
|
71 |
-
draw.text((10, 10), f"Duration: {int(1000 * (end_time - start_time))}ms", fill=(255, 255, 255))
|
72 |
return overlay_img
|
73 |
|
74 |
#ideally:
|
75 |
#iface = gr.Interface(app, gr.Image(sources=["webcam"], streaming=True), "image", live=True)
|
76 |
-
iface = gr.Interface(app, gr.Image(), "image")
|
77 |
iface.launch()
|
|
|
20 |
|
21 |
working_size = (512, 512)
|
22 |
|
23 |
+
default_inpainting_prompt = "watercolor of a leafy pedestrian mall at golden hour with multiracial genderqueer joggers and bicyclists and wheelchair users talking and laughing"
|
24 |
+
|
25 |
seg_vocabulary = ['Animal', 'Archway', 'Bicyclist', 'Bridge', 'Building', 'Car',
|
26 |
'CartLuggagePram', 'Child', 'Column_Pole', 'Fence', 'LaneMkgsDriv',
|
27 |
'LaneMkgsNonDriv', 'Misc_Text', 'MotorcycleScooter', 'OtherMoving',
|
|
|
42 |
mask = segmodel.predict(img)[0]
|
43 |
return mask
|
44 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
45 |
|
46 |
+
def app(img, prompt):
|
47 |
start_time = datetime.now().timestamp()
|
48 |
img = img.resize(working_size)
|
49 |
mask = ban_cars_mask[get_seg_mask(img)]
|
50 |
overlay_img = Image.fromarray(np.stack([img[:, :, 0], mask / 2, img[:,:,2]], axis=-1))
|
51 |
end_time = datetime.now().timestamp()
|
52 |
draw = ImageDraw.Draw(overlay_img)
|
53 |
+
draw.text((10, 10), f"Duration: {int(1000 * (end_time - start_time))}ms\n<{prompt}>", fill=(255, 255, 255))
|
54 |
return overlay_img
|
55 |
|
56 |
#ideally:
|
57 |
#iface = gr.Interface(app, gr.Image(sources=["webcam"], streaming=True), "image", live=True)
|
58 |
+
iface = gr.Interface(app, [gr.Image(), gr.Textbox(value=default_inpainting_prompt)], "image")
|
59 |
iface.launch()
|