radames commited on
Commit
caeb1f4
1 Parent(s): 1303d02

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -23
app.py CHANGED
@@ -25,33 +25,35 @@ aesthetic_pipe = pipeline("image-classification",
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 = [{ row["label"]:row["score"] for row in image } for image in results]
 
 
40
 
41
- return label_data[0], label_data
42
 
43
  with gr.Blocks() as blocks:
44
- with gr.Row():
45
- with gr.Column():
46
- image = gr.Image(label="Image to test", type="filepath")
47
- files = gr.File(label="Multipls Images", file_types=["image"], file_count="multiple")
48
- with gr.Column():
49
- label = gr.Label(label="style")
50
- results = gr.JSON(label="Results")
51
- # gallery = gr.Gallery().style(grid=[2], height="auto")
52
- btn = gr.Button("Run")
53
-
54
- btn.click(fn=predict, inputs=[image, files], outputs=[label, results], api_name="inference")
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)