Upload 3 files
Browse files- Dockerfile +13 -0
- app.py +61 -0
- requirements.txt +11 -0
Dockerfile
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
RUN useradd -m -u 1000 user
|
4 |
+
USER user
|
5 |
+
ENV PATH="/home/user/.local/bin:$PATH"
|
6 |
+
|
7 |
+
WORKDIR /app
|
8 |
+
|
9 |
+
COPY --chown=user ./requirements.txt requirements.txt
|
10 |
+
RUN pip install --no-cache-dir --upgrade -r requirements.txt
|
11 |
+
|
12 |
+
COPY --chown=user . /app
|
13 |
+
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
|
app.py
ADDED
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from fastapi.responses import StreamingResponse
|
3 |
+
import urllib.request
|
4 |
+
import io
|
5 |
+
|
6 |
+
app = FastAPI()
|
7 |
+
|
8 |
+
@app.get("/download-image")
|
9 |
+
async def download_image(path: str):
|
10 |
+
BASE_URL = "https://kwai-kolors-kolors-virtual-try-on.hf.space/file="
|
11 |
+
|
12 |
+
try:
|
13 |
+
# Download image
|
14 |
+
with urllib.request.urlopen(BASE_URL+path) as response:
|
15 |
+
image_data = response.read()
|
16 |
+
|
17 |
+
# Create a BytesIO object for streaming
|
18 |
+
image_stream = io.BytesIO(image_data)
|
19 |
+
|
20 |
+
# Return StreamingResponse with appropriate media type
|
21 |
+
return StreamingResponse(
|
22 |
+
image_stream,
|
23 |
+
media_type="image/webp",
|
24 |
+
headers={
|
25 |
+
"Content-Disposition": "inline; filename=image.webp"
|
26 |
+
}
|
27 |
+
)
|
28 |
+
except Exception as e:
|
29 |
+
return {"error": str(e)}
|
30 |
+
|
31 |
+
|
32 |
+
|
33 |
+
|
34 |
+
|
35 |
+
|
36 |
+
|
37 |
+
|
38 |
+
|
39 |
+
|
40 |
+
|
41 |
+
|
42 |
+
|
43 |
+
|
44 |
+
|
45 |
+
|
46 |
+
|
47 |
+
|
48 |
+
'''import urllib.request
|
49 |
+
|
50 |
+
url = 'https://kwai-kolors-kolors-virtual-try-on.hf.space/file=/tmp/gradio/e3f14f9d34b839a2b2a338b8e4a1827f6a1902663ddb031a8bb2e296b1bdcbf7/image.webp'
|
51 |
+
|
52 |
+
def download_image_and_log_bytes(url, save_as):
|
53 |
+
with urllib.request.urlopen(url) as response:
|
54 |
+
image_data = response.read()
|
55 |
+
print(f"[LOG] Image byte length: {len(image_data)}")
|
56 |
+
print(f"[LOG] First 100 bytes: {image_data[:100]}")
|
57 |
+
with open(save_as, 'wb') as f:
|
58 |
+
f.write(image_data)
|
59 |
+
|
60 |
+
save_as = 'imager.jpg'
|
61 |
+
download_image_and_log_bytes(url, save_as)'''
|
requirements.txt
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
fastapi
|
2 |
+
uvicorn[standard]
|
3 |
+
requests
|
4 |
+
python-multipart
|
5 |
+
gradio_client
|
6 |
+
pydantic
|
7 |
+
httpx
|
8 |
+
sse-starlette
|
9 |
+
aiohttp
|
10 |
+
urllib3
|
11 |
+
wget
|