Update app.py
Browse files
app.py
CHANGED
|
@@ -6,7 +6,7 @@ from fastapi import FastAPI, HTTPException
|
|
| 6 |
from fastapi.responses import StreamingResponse
|
| 7 |
import requests
|
| 8 |
from io import BytesIO
|
| 9 |
-
from PIL import Image, ImageFilter
|
| 10 |
import rembg
|
| 11 |
import onnxruntime as ort
|
| 12 |
|
|
@@ -26,14 +26,6 @@ def resize_image(image, max_size=512):
|
|
| 26 |
image = image.resize(new_size, Image.Resampling.LANCZOS)
|
| 27 |
return image
|
| 28 |
|
| 29 |
-
def adjust_brightness_contrast(image, brightness=1.2, contrast=1.2):
|
| 30 |
-
"""Ajusta o brilho e o contraste da imagem."""
|
| 31 |
-
enhancer = ImageEnhance.Brightness(image)
|
| 32 |
-
image = enhancer.enhance(brightness)
|
| 33 |
-
enhancer = ImageEnhance.Contrast(image)
|
| 34 |
-
image = enhancer.enhance(contrast)
|
| 35 |
-
return image
|
| 36 |
-
|
| 37 |
@app.get("/remove-background")
|
| 38 |
async def remove_background(image_url: str):
|
| 39 |
try:
|
|
@@ -44,9 +36,8 @@ async def remove_background(image_url: str):
|
|
| 44 |
# Abre a imagem usando Pillow
|
| 45 |
image = Image.open(BytesIO(response.content))
|
| 46 |
|
| 47 |
-
# Pré-processamento: redimensiona para 512px
|
| 48 |
image = resize_image(image, max_size=512)
|
| 49 |
-
image = adjust_brightness_contrast(image)
|
| 50 |
|
| 51 |
# Remove o fundo da imagem usando rembg
|
| 52 |
output = rembg.remove(image, session_options=options)
|
|
|
|
| 6 |
from fastapi.responses import StreamingResponse
|
| 7 |
import requests
|
| 8 |
from io import BytesIO
|
| 9 |
+
from PIL import Image, ImageFilter
|
| 10 |
import rembg
|
| 11 |
import onnxruntime as ort
|
| 12 |
|
|
|
|
| 26 |
image = image.resize(new_size, Image.Resampling.LANCZOS)
|
| 27 |
return image
|
| 28 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 29 |
@app.get("/remove-background")
|
| 30 |
async def remove_background(image_url: str):
|
| 31 |
try:
|
|
|
|
| 36 |
# Abre a imagem usando Pillow
|
| 37 |
image = Image.open(BytesIO(response.content))
|
| 38 |
|
| 39 |
+
# Pré-processamento: apenas redimensiona para 512px
|
| 40 |
image = resize_image(image, max_size=512)
|
|
|
|
| 41 |
|
| 42 |
# Remove o fundo da imagem usando rembg
|
| 43 |
output = rembg.remove(image, session_options=options)
|