Spaces:
Running
Running
Commit ·
8ff99b5
1
Parent(s): 1d1ef92
remove crop image
Browse files- app.py +2 -10
- cropImage.py +0 -32
app.py
CHANGED
|
@@ -6,7 +6,6 @@ import gradio as gr
|
|
| 6 |
import PIL.Image
|
| 7 |
import zipfile
|
| 8 |
from genTag import genTag
|
| 9 |
-
from cropImage import cropImage
|
| 10 |
from checkIgnore import is_ignore
|
| 11 |
from createTagDom import create_tag_dom
|
| 12 |
|
|
@@ -18,8 +17,7 @@ def predict(image: PIL.Image.Image):
|
|
| 18 |
result_html = '<div>' + result_html + '</div>'
|
| 19 |
result_filter = {key: value for key, value in result_threshold.items() if not is_ignore(key, 1)}
|
| 20 |
result_text = '<div id="m5dd_result">' + ', '.join(result_filter.keys()) + '</div>'
|
| 21 |
-
|
| 22 |
-
return result_html, result_text, crop_image
|
| 23 |
|
| 24 |
def predict_batch(zip_file, progress=gr.Progress()):
|
| 25 |
result = ''
|
|
@@ -46,12 +44,6 @@ with gr.Blocks(css="style.css", js="script.js") as demo:
|
|
| 46 |
image_mode="RGBA",
|
| 47 |
sources=["upload", "clipboard"])
|
| 48 |
run_button = gr.Button('Run')
|
| 49 |
-
with gr.Accordion(label="Crop Image", open=False):
|
| 50 |
-
crop_image = gr.Image(elem_classes='m5dd_image2',
|
| 51 |
-
format='jpg',
|
| 52 |
-
show_label=False,
|
| 53 |
-
show_share_button=False,
|
| 54 |
-
container=False)
|
| 55 |
result_text = gr.HTML(value="")
|
| 56 |
with gr.Column(scale=2):
|
| 57 |
result_html = gr.HTML(value="")
|
|
@@ -71,7 +63,7 @@ with gr.Blocks(css="style.css", js="script.js") as demo:
|
|
| 71 |
run_button.click(
|
| 72 |
fn=predict,
|
| 73 |
inputs=[image],
|
| 74 |
-
outputs=[result_html, result_text
|
| 75 |
api_name='predict',
|
| 76 |
)
|
| 77 |
run_button2.click(
|
|
|
|
| 6 |
import PIL.Image
|
| 7 |
import zipfile
|
| 8 |
from genTag import genTag
|
|
|
|
| 9 |
from checkIgnore import is_ignore
|
| 10 |
from createTagDom import create_tag_dom
|
| 11 |
|
|
|
|
| 17 |
result_html = '<div>' + result_html + '</div>'
|
| 18 |
result_filter = {key: value for key, value in result_threshold.items() if not is_ignore(key, 1)}
|
| 19 |
result_text = '<div id="m5dd_result">' + ', '.join(result_filter.keys()) + '</div>'
|
| 20 |
+
return result_html, result_text
|
|
|
|
| 21 |
|
| 22 |
def predict_batch(zip_file, progress=gr.Progress()):
|
| 23 |
result = ''
|
|
|
|
| 44 |
image_mode="RGBA",
|
| 45 |
sources=["upload", "clipboard"])
|
| 46 |
run_button = gr.Button('Run')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 47 |
result_text = gr.HTML(value="")
|
| 48 |
with gr.Column(scale=2):
|
| 49 |
result_html = gr.HTML(value="")
|
|
|
|
| 63 |
run_button.click(
|
| 64 |
fn=predict,
|
| 65 |
inputs=[image],
|
| 66 |
+
outputs=[result_html, result_text],
|
| 67 |
api_name='predict',
|
| 68 |
)
|
| 69 |
run_button2.click(
|
cropImage.py
DELETED
|
@@ -1,32 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python
|
| 2 |
-
|
| 3 |
-
from __future__ import annotations
|
| 4 |
-
|
| 5 |
-
import PIL.Image
|
| 6 |
-
|
| 7 |
-
def cropImage(image: PIL.Image.Image):
|
| 8 |
-
original_width, original_height = image.size
|
| 9 |
-
scale = max(original_width, original_height) / min(original_width, original_height)
|
| 10 |
-
|
| 11 |
-
target_width = 512
|
| 12 |
-
target_height = 768
|
| 13 |
-
|
| 14 |
-
if scale < 1.1:
|
| 15 |
-
target_width = 640
|
| 16 |
-
target_height = 640
|
| 17 |
-
elif original_width > original_height:
|
| 18 |
-
target_width = 768
|
| 19 |
-
target_height = 512
|
| 20 |
-
|
| 21 |
-
if original_width / original_height > target_width / target_height:
|
| 22 |
-
new_width = int(original_height * (target_width / target_height))
|
| 23 |
-
crop_box = ((original_width - new_width) // 2, 0, (original_width + new_width) // 2, original_height)
|
| 24 |
-
else:
|
| 25 |
-
new_height = int(original_width * (target_height / target_width))
|
| 26 |
-
crop_box = (0, (original_height - new_height) // 2, original_width, (original_height + new_height) // 2)
|
| 27 |
-
|
| 28 |
-
cropped_image = image.convert("RGB")
|
| 29 |
-
cropped_image = cropped_image.crop(crop_box)
|
| 30 |
-
cropped_image = cropped_image.resize((target_width, target_height))
|
| 31 |
-
|
| 32 |
-
return cropped_image
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|