File size: 713 Bytes
e202b48
 
 
 
 
 
 
 
 
 
 
26fb348
ec6297e
e202b48
26fb348
588da92
 
e202b48
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
e445dcb
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
from fastapi import FastAPI
import base64
import os
import sys
import uvicorn
from imagekitio import ImageKit

import base64

app = FastAPI()



imagekit = ImageKit(
    public_key=os.environ.get("public_key"),
    private_key=os.environ.get("private_key"),
    url_endpoint=os.environ.get("url_endpoint")
)

@app.get("/")
def upload_image(url):
    try:


        # Upload the image to ImageKit
        upload = imagekit.upload(
            file=url,
            file_name="image.jpg",
        )

        # Return the upload response
        return upload
    except Exception as e:
        return {"error": str(e)}

if __name__ == "__main__":
    import uvicorn

    uvicorn.run(app, host="0.0.0.0", port=7860)