File size: 1,449 Bytes
cc00fa2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
from fastapi import FastAPI
from fastapi.responses import StreamingResponse
import urllib.request
import io

app = FastAPI()

@app.get("/download-image")
async def download_image(path: str):
    BASE_URL = "https://kwai-kolors-kolors-virtual-try-on.hf.space/file="
    
    try:
        # Download image
        with urllib.request.urlopen(BASE_URL+path) as response:
            image_data = response.read()
        
        # Create a BytesIO object for streaming
        image_stream = io.BytesIO(image_data)
        
        # Return StreamingResponse with appropriate media type
        return StreamingResponse(
            image_stream,
            media_type="image/webp",
            headers={
                "Content-Disposition": "inline; filename=image.webp"
            }
        )
    except Exception as e:
        return {"error": str(e)}


















'''import urllib.request

url = 'https://kwai-kolors-kolors-virtual-try-on.hf.space/file=/tmp/gradio/e3f14f9d34b839a2b2a338b8e4a1827f6a1902663ddb031a8bb2e296b1bdcbf7/image.webp'

def download_image_and_log_bytes(url, save_as):
    with urllib.request.urlopen(url) as response:
        image_data = response.read()
        print(f"[LOG] Image byte length: {len(image_data)}")
        print(f"[LOG] First 100 bytes: {image_data[:100]}")
        with open(save_as, 'wb') as f:
            f.write(image_data)

save_as = 'imager.jpg'
download_image_and_log_bytes(url, save_as)'''