File size: 2,011 Bytes
e202b48
 
 
 
 
 
acb259b
55286a3
e202b48
 
 
3aa6e09
 
e202b48
55286a3
 
 
ce16251
55286a3
 
 
 
26fb348
ec6297e
e202b48
26fb348
588da92
 
e202b48
 
3aa6e09
 
 
 
 
 
 
 
 
 
 
 
8ca8082
e202b48
 
 
 
 
 
 
 
 
 
 
014546a
e202b48
 
 
0d3f02c
 
 
94892a4
b800426
b51d48e
fec11fc
0d3f02c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
from fastapi import FastAPI
import base64
import os
import sys
import uvicorn
from imagekitio import ImageKit
from imagekitio.models.ListAndSearchFileRequestOptions import ListAndSearchFileRequestOptions
from fastapi.middleware.cors import CORSMiddleware

import base64



app = FastAPI()
# Configure CORS
app.add_middleware(
    CORSMiddleware,
    allow_origins=["https://aiphotographer.github.io"],  # Allows only this origin
    allow_credentials=True,
    allow_methods=["*"],  # Allows all methods
    allow_headers=["*"],  # Allows all headers
)


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 read_root():
    return {
        "introduction": "Welcome to the AI Photo Creator App! Here's how to use it: "
                        "Step 1: 📸 Tell me what picture you want to take, and I will create one for you. "
                        "Step 2: 🌍 If you feel satisfied with the photo created by me, you can copy and paste "
                        "the photo address and share your photo on our crowd-sourced AI photography website."
    }

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


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

        # Return the upload response
        return {"message": "uploaded successfuly, check https://chatzl.github.io/photographer.html for your work!"}
    except Exception as e:
        return {"error": str(e)}


@app.get("/images_list")
async def get_images():
    
    list_files = imagekit.list_files(options=ListAndSearchFileRequestOptions(search_query='createdAt >= "7d"'))
    list_files_sorted=sorted(list_files.response_metadata.raw, key=lambda x: x['createdAt'],reverse=True)
    return list_files_sorted

if __name__ == "__main__":
    import uvicorn

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