Update main.py
Browse files
main.py
CHANGED
@@ -6,6 +6,13 @@ import aiofiles
|
|
6 |
import aiohttp
|
7 |
import os
|
8 |
from bs4 import BeautifulSoup
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
from akenoai import OldAkenoXToJs
|
10 |
from akenoai.runner import run_fast
|
11 |
from akenoai.clients import create_pyrogram
|
@@ -29,6 +36,9 @@ logger.setLevel(logging.DEBUG)
|
|
29 |
js = OldAkenoXToJs()
|
30 |
fast_app = js.get_app()
|
31 |
|
|
|
|
|
|
|
32 |
origins = [
|
33 |
"https://randydev-meta-ai.hf.space"
|
34 |
]
|
@@ -107,6 +117,23 @@ async def upload_to_catbox(dl_path: str) -> str:
|
|
107 |
response.raise_for_status()
|
108 |
return (await response.text()).strip()
|
109 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
110 |
@fast_app.get("/image/share/{filename}")
|
111 |
async def get_image(filename: str):
|
112 |
file_path = f"image/{filename}"
|
|
|
6 |
import aiohttp
|
7 |
import os
|
8 |
from bs4 import BeautifulSoup
|
9 |
+
|
10 |
+
from pydantic import BaseModel
|
11 |
+
import base64
|
12 |
+
from rembg import remove
|
13 |
+
from io import BytesIO
|
14 |
+
from PIL import Image
|
15 |
+
|
16 |
from akenoai import OldAkenoXToJs
|
17 |
from akenoai.runner import run_fast
|
18 |
from akenoai.clients import create_pyrogram
|
|
|
36 |
js = OldAkenoXToJs()
|
37 |
fast_app = js.get_app()
|
38 |
|
39 |
+
os.environ["U2NET_HOME"] = "/usr/src/app/.u2net"
|
40 |
+
os.environ["XDG_CACHE_HOME"] = "/usr/src/app/.cache"
|
41 |
+
|
42 |
origins = [
|
43 |
"https://randydev-meta-ai.hf.space"
|
44 |
]
|
|
|
117 |
response.raise_for_status()
|
118 |
return (await response.text()).strip()
|
119 |
|
120 |
+
class ImageInput(BaseModel):
|
121 |
+
image_base64: str
|
122 |
+
|
123 |
+
@fast_app.post("/remove-bg-base64")
|
124 |
+
async def remove_bg_base64(data: ImageInput):
|
125 |
+
try:
|
126 |
+
image_data = base64.b64decode(data.image_base64)
|
127 |
+
input_image = Image.open(BytesIO(image_data))
|
128 |
+
output_image = remove(input_image)
|
129 |
+
|
130 |
+
buffer = BytesIO()
|
131 |
+
output_image.save(buffer, format="PNG")
|
132 |
+
output_base64 = base64.b64encode(buffer.getvalue()).decode("utf-8")
|
133 |
+
return {"output_image_base64": output_base64}
|
134 |
+
except Exception as e:
|
135 |
+
return {"error": str(e)}
|
136 |
+
|
137 |
@fast_app.get("/image/share/{filename}")
|
138 |
async def get_image(filename: str):
|
139 |
file_path = f"image/{filename}"
|