Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
Update app.py
Browse files
app.py
CHANGED
@@ -25,33 +25,35 @@ aesthetic_pipe = pipeline("image-classification",
|
|
25 |
torch_dtype=dtype)
|
26 |
|
27 |
def predict(image, files=None):
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
images_paths = list(map(lambda x: x.name, files))
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
|
|
|
|
40 |
|
41 |
-
|
42 |
|
43 |
with gr.Blocks() as blocks:
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
|
56 |
blocks.queue()
|
57 |
blocks.launch(debug=True,inline=True)
|
|
|
25 |
torch_dtype=dtype)
|
26 |
|
27 |
def predict(image, files=None):
|
28 |
+
print(image, files)
|
29 |
+
images_paths = [image]
|
30 |
+
if not files == None:
|
31 |
images_paths = list(map(lambda x: x.name, files))
|
32 |
+
pil_images = [Image.open(image_path).convert("RGB") for image_path in images_paths]
|
33 |
+
|
34 |
+
style = style_pipe(pil_images)
|
35 |
+
aesthetic = aesthetic_pipe(pil_images)
|
36 |
+
nsfw = nsfw_pipe(pil_images)
|
37 |
+
results = [ a + b + c for (a,b,c) in zip(style, aesthetic, nsfw)]
|
38 |
+
|
39 |
+
label_data = {}
|
40 |
+
if image:
|
41 |
+
label_data = [{ row["label"]:row["score"] for row in image } for image in results]
|
42 |
|
43 |
+
return label_data[0], results
|
44 |
|
45 |
with gr.Blocks() as blocks:
|
46 |
+
with gr.Row():
|
47 |
+
with gr.Column():
|
48 |
+
image = gr.Image(label="Image to test", type="filepath")
|
49 |
+
files = gr.File(label="Multipls Images", file_types=["image"], file_count="multiple")
|
50 |
+
with gr.Column():
|
51 |
+
label = gr.Label(label="style")
|
52 |
+
results = gr.JSON(label="Results")
|
53 |
+
# gallery = gr.Gallery().style(grid=[2], height="auto")
|
54 |
+
btn = gr.Button("Run")
|
55 |
+
|
56 |
+
btn.click(fn=predict, inputs=[image, files], outputs=[label, results], api_name="inference")
|
57 |
|
58 |
blocks.queue()
|
59 |
blocks.launch(debug=True,inline=True)
|