kinsung commited on
Commit
e58fe96
·
1 Parent(s): 89c6167
Files changed (1) hide show
  1. app.py +5 -10
app.py CHANGED
@@ -8,17 +8,13 @@ feature_extractor = DetrImageProcessor.from_pretrained("facebook/detr-resnet-101
8
  dmodel = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-101")
9
 
10
  i1 = gr.inputs.Image(type="pil", label="Input image")
11
- i2 = gr.inputs.Textbox(label="Input text")
12
- i3 = gr.inputs.Number(default=0.96, label="Threshold percentage score")
13
- i4 = gr.inputs.Number(default=400, label="Custom Width (optional)")
14
- i5 = gr.inputs.Number(default=400, label="Custom Height (optional)")
15
  o1 = gr.outputs.Image(type="pil", label="Cropped part")
16
- o2 = gr.outputs.Textbox(label="Similarity score")
17
 
18
- def extract_image(image, text, prob, custom_width, custom_height):
19
  inputs = feature_extractor(images=image, return_tensors="pt")
20
  outputs = dmodel(**inputs)
21
- pout = ""
22
 
23
  target_sizes = torch.tensor([image.size[::-1]])
24
  results = feature_extractor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[0]
@@ -53,9 +49,8 @@ def extract_image(image, text, prob, custom_width, custom_height):
53
  # Return the coordinates of the cropped area
54
  coordinates = f"xmin: {xmin}, ymin: {ymin}, xmax: {xmax}, ymax: {ymax}"
55
 
56
- return cropped_image, coordinates
57
 
58
- title = "ClipnCrop"
59
  description = "<p style='color:white'>Crop an image with the area containing the most detected objects while maintaining custom dimensions and adding a 10-pixel bleed. The area is centralized within the custom dimensions.</p>"
60
  examples = [['ex3.jpg', 'people', 0.96, 800, 400], ['ex2.jpg', 'smiling face', 0.85, 300, 400]]
61
- gr.Interface(fn=extract_image, inputs=[i1, i2, i3, i4, i5], outputs=[o1, o2], title=title, description=description, examples=examples, enable_queue=True).launch()
 
8
  dmodel = DetrForObjectDetection.from_pretrained("facebook/detr-resnet-101")
9
 
10
  i1 = gr.inputs.Image(type="pil", label="Input image")
11
+ i2 = gr.inputs.Number(default=400, label="Custom Width (optional)")
12
+ i3 = gr.inputs.Number(default=400, label="Custom Height (optional)")
 
 
13
  o1 = gr.outputs.Image(type="pil", label="Cropped part")
 
14
 
15
+ def extract_image(image, custom_width, custom_height):
16
  inputs = feature_extractor(images=image, return_tensors="pt")
17
  outputs = dmodel(**inputs)
 
18
 
19
  target_sizes = torch.tensor([image.size[::-1]])
20
  results = feature_extractor.post_process_object_detection(outputs, target_sizes=target_sizes, threshold=0.9)[0]
 
49
  # Return the coordinates of the cropped area
50
  coordinates = f"xmin: {xmin}, ymin: {ymin}, xmax: {xmax}, ymax: {ymax}"
51
 
52
+ return cropped_image
53
 
 
54
  description = "<p style='color:white'>Crop an image with the area containing the most detected objects while maintaining custom dimensions and adding a 10-pixel bleed. The area is centralized within the custom dimensions.</p>"
55
  examples = [['ex3.jpg', 'people', 0.96, 800, 400], ['ex2.jpg', 'smiling face', 0.85, 300, 400]]
56
+ gr.Interface(fn=extract_image, inputs=[i1, i2, i3], outputs=[o1], title=title, description=description, examples=examples, enable_queue=True).launch()