File size: 2,780 Bytes
fbdabcd
e202b48
 
 
 
 
acb259b
8cca4c4
55286a3
e202b48
 
fbdabcd
e202b48
3aa6e09
 
e202b48
55286a3
 
 
ce16251
55286a3
 
 
 
26fb348
ec6297e
e202b48
26fb348
588da92
 
e202b48
 
3aa6e09
 
 
 
 
 
 
 
 
 
 
 
e202b48
488e1c7
6c2e069
a68eff3
488e1c7
fbdabcd
a68eff3
e202b48
488e1c7
e202b48
db6d58b
e202b48
 
 
6c2e069
e202b48
 
 
0d3f02c
34c165a
 
 
 
 
 
 
 
0890c5d
34c165a
 
 
 
5dcab2e
34c165a
 
 
 
 
 
 
 
 
 
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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
from fastapi import FastAPI, HTTPException
import base64
import os
import sys
import uvicorn
from imagekitio import ImageKit
from imagekitio.models.ListAndSearchFileRequestOptions import ListAndSearchFileRequestOptions
from imagekitio.models.UploadFileRequestOptions import UploadFileRequestOptions
from fastapi.middleware.cors import CORSMiddleware

import base64
from pydantic import BaseModel



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.post("/image_upload")
async def upload_image(url):
    try:

        upload = imagekit.upload(
            file=url,
            file_name="image.jpg",
            #options=options
        )

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


@app.post("/palette_upload")
async def upload_image(url):
    try:
        options = UploadFileRequestOptions(

            folder='/palette/',
            overwrite_tags=False,
            overwrite_custom_metadata=True,
           # custom_metadata={'testss': 12},
        )
        upload = imagekit.upload(
            file=url,
            file_name="palette.jpg",
            options=options
        )

        # Return the upload response
        return {"message": "Uploaded successfully, check https://aiphotographer.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)