Spaces:
Runtime error
Runtime error
test examples
Browse files
app.py
CHANGED
@@ -22,26 +22,11 @@ IMAGE_SIZE = 1024
|
|
22 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
23 |
|
24 |
|
25 |
-
def remove_background(image: Image.Image, threshold: int = 50) -> Image.Image:
|
26 |
-
image = image.convert("RGBA")
|
27 |
-
data = image.getdata()
|
28 |
-
new_data = []
|
29 |
-
for item in data:
|
30 |
-
avg = sum(item[:3]) / 3
|
31 |
-
if avg < threshold:
|
32 |
-
new_data.append((0, 0, 0, 0))
|
33 |
-
else:
|
34 |
-
new_data.append(item)
|
35 |
-
|
36 |
-
image.putdata(new_data)
|
37 |
-
return image
|
38 |
-
|
39 |
-
|
40 |
EXAMPLES = [
|
41 |
[
|
42 |
{
|
43 |
"background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
|
44 |
-
"layers": [
|
45 |
"composite": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-composite-2.png", stream=True).raw),
|
46 |
},
|
47 |
"little lion",
|
@@ -53,7 +38,7 @@ EXAMPLES = [
|
|
53 |
[
|
54 |
{
|
55 |
"background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
|
56 |
-
"layers": [
|
57 |
"composite": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-composite-3.png", stream=True).raw),
|
58 |
},
|
59 |
"tattoos",
|
|
|
22 |
DEVICE = "cuda" if torch.cuda.is_available() else "cpu"
|
23 |
|
24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
25 |
EXAMPLES = [
|
26 |
[
|
27 |
{
|
28 |
"background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
|
29 |
+
"layers": [Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-2.png", stream=True).raw)],
|
30 |
"composite": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-composite-2.png", stream=True).raw),
|
31 |
},
|
32 |
"little lion",
|
|
|
38 |
[
|
39 |
{
|
40 |
"background": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-image.png", stream=True).raw),
|
41 |
+
"layers": [Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-mask-3.png", stream=True).raw)],
|
42 |
"composite": Image.open(requests.get("https://media.roboflow.com/spaces/doge-2-composite-3.png", stream=True).raw),
|
43 |
},
|
44 |
"tattoos",
|