Spaces:
Running
Running
si.qian commited on
Commit ·
835b55f
1
Parent(s): a6fa011
优化
Browse files- app.py +22 -12
- utils/__pycache__/functions.cpython-310.pyc +0 -0
app.py
CHANGED
|
@@ -1,28 +1,29 @@
|
|
|
|
|
| 1 |
from zipfile import ZipFile
|
| 2 |
import numpy as np
|
| 3 |
-
|
| 4 |
-
import os, shutil
|
| 5 |
-
|
| 6 |
import gradio as gr
|
| 7 |
from PIL import Image
|
| 8 |
-
import sys, os
|
| 9 |
from rembg import new_session, remove
|
| 10 |
-
from
|
| 11 |
from utils.functions import complete, clean, clean_by_name, get_random_name
|
| 12 |
|
| 13 |
-
import os, sys
|
| 14 |
-
import argparse
|
| 15 |
-
|
| 16 |
-
from logging import getLogger, StreamHandler, DEBUG
|
| 17 |
logger = getLogger(__name__)
|
| 18 |
-
handler = StreamHandler()
|
|
|
|
| 19 |
logger.setLevel(DEBUG)
|
| 20 |
logger.addHandler(handler)
|
| 21 |
logger.propagate = False
|
| 22 |
-
|
| 23 |
-
|
| 24 |
|
| 25 |
def run_rembg(img):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
output = remove(img)
|
| 27 |
output_pil = Image.fromarray(output)
|
| 28 |
|
|
@@ -45,6 +46,15 @@ def run_rembg_withmodel(img, model):
|
|
| 45 |
return output_pil
|
| 46 |
|
| 47 |
def from_zip(inputs):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
work_dir = get_random_name()
|
| 49 |
os.makedirs(work_dir, exist_ok=True)
|
| 50 |
|
|
|
|
| 1 |
+
import os, shutil
|
| 2 |
from zipfile import ZipFile
|
| 3 |
import numpy as np
|
|
|
|
|
|
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
from PIL import Image
|
|
|
|
| 6 |
from rembg import new_session, remove
|
| 7 |
+
from logging import getLogger, StreamHandler, DEBUG
|
| 8 |
from utils.functions import complete, clean, clean_by_name, get_random_name
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
logger = getLogger(__name__)
|
| 11 |
+
handler = StreamHandler()
|
| 12 |
+
handler.setLevel(DEBUG)
|
| 13 |
logger.setLevel(DEBUG)
|
| 14 |
logger.addHandler(handler)
|
| 15 |
logger.propagate = False
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def run_rembg(img):
|
| 18 |
+
"""
|
| 19 |
+
Remove background from an image using U2-Net algorithm.
|
| 20 |
+
|
| 21 |
+
Args:
|
| 22 |
+
img: numpy array, input image data.
|
| 23 |
+
|
| 24 |
+
Returns:
|
| 25 |
+
A cropped PIL image object.
|
| 26 |
+
"""
|
| 27 |
output = remove(img)
|
| 28 |
output_pil = Image.fromarray(output)
|
| 29 |
|
|
|
|
| 46 |
return output_pil
|
| 47 |
|
| 48 |
def from_zip(inputs):
|
| 49 |
+
"""
|
| 50 |
+
Read images from a zip file and output a processed zip file.
|
| 51 |
+
|
| 52 |
+
Args:
|
| 53 |
+
inputs: list of file objects, input zip file.
|
| 54 |
+
|
| 55 |
+
Returns:
|
| 56 |
+
A tuple of output zip file name and a completion message.
|
| 57 |
+
"""
|
| 58 |
work_dir = get_random_name()
|
| 59 |
os.makedirs(work_dir, exist_ok=True)
|
| 60 |
|
utils/__pycache__/functions.cpython-310.pyc
ADDED
|
Binary file (1.53 kB). View file
|
|
|