Spaces:
Runtime error
Runtime error
Beamlnwza
commited on
Commit
·
342d3dd
1
Parent(s):
9d79026
fast check
Browse files- .dockerignore +3 -3
- .env +0 -0
- README.md +8 -8
- routes/api.py +6 -6
- src/endpoints/generate.py +86 -86
- src/endpoints/view.py +63 -63
- src/libs/image.py +15 -15
- src/libs/model.py +51 -51
- src/libs/s3.py +26 -26
- src/models/generate.py +14 -14
- src/models/main.py +13 -13
- src/models/view.py +14 -14
- test_main.http +11 -11
.dockerignore
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
.vercel
|
2 |
-
venv
|
3 |
-
.idea
|
4 |
__pycache__
|
|
|
1 |
+
.vercel
|
2 |
+
venv
|
3 |
+
.idea
|
4 |
__pycache__
|
.env
DELETED
File without changes
|
README.md
CHANGED
@@ -1,8 +1,8 @@
|
|
1 |
-
---
|
2 |
-
title: pimthaigans
|
3 |
-
emoji: 🐳
|
4 |
-
colorFrom: purple
|
5 |
-
colorTo: gray
|
6 |
-
sdk: docker
|
7 |
-
app_port: 7860
|
8 |
-
---
|
|
|
1 |
+
---
|
2 |
+
title: pimthaigans
|
3 |
+
emoji: 🐳
|
4 |
+
colorFrom: purple
|
5 |
+
colorTo: gray
|
6 |
+
sdk: docker
|
7 |
+
app_port: 7860
|
8 |
+
---
|
routes/api.py
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
-
from fastapi import APIRouter
|
2 |
-
from src.endpoints import generate, view
|
3 |
-
|
4 |
-
router = APIRouter()
|
5 |
-
router.include_router(generate.router)
|
6 |
-
router.include_router(view.router)
|
|
|
1 |
+
from fastapi import APIRouter
|
2 |
+
from src.endpoints import generate, view
|
3 |
+
|
4 |
+
router = APIRouter()
|
5 |
+
router.include_router(generate.router)
|
6 |
+
router.include_router(view.router)
|
src/endpoints/generate.py
CHANGED
@@ -1,86 +1,86 @@
|
|
1 |
-
import os
|
2 |
-
from typing import List
|
3 |
-
|
4 |
-
from fastapi import APIRouter
|
5 |
-
|
6 |
-
from src.libs.image import save_img, generate_img_index
|
7 |
-
from src.libs.model import CganCols, get_model
|
8 |
-
from src.libs.s3 import s3client
|
9 |
-
from src.models.generate import GenerateResult, ImageResult
|
10 |
-
from src.models.main import User, Method
|
11 |
-
|
12 |
-
IMAGE_STORE_PATH = os.path.abspath("./src/store")
|
13 |
-
BUCKET_NAME = "pimthaigans-image-container"
|
14 |
-
|
15 |
-
# just make sure to have IMAGE_STORE_PATH folder created
|
16 |
-
if not os.path.exists(IMAGE_STORE_PATH):
|
17 |
-
os.makedirs(IMAGE_STORE_PATH)
|
18 |
-
|
19 |
-
router = APIRouter(
|
20 |
-
prefix="/generate",
|
21 |
-
tags=["Generate"],
|
22 |
-
responses={404: {"description": "Not found"}},
|
23 |
-
)
|
24 |
-
|
25 |
-
model = CganCols()
|
26 |
-
|
27 |
-
|
28 |
-
@router.get("/")
|
29 |
-
async def info():
|
30 |
-
return {"info": "This is the generate endpoint"}
|
31 |
-
|
32 |
-
|
33 |
-
@router.get("/status")
|
34 |
-
async def status():
|
35 |
-
return {"status": "OK"}
|
36 |
-
|
37 |
-
|
38 |
-
@router.post("/")
|
39 |
-
async def generate(user: User, index: int | None = None) -> GenerateResult:
|
40 |
-
if index or index == 0:
|
41 |
-
result: GenerateResult = await generate_index(user, index)
|
42 |
-
return result
|
43 |
-
|
44 |
-
result: GenerateResult = await generate_all(user)
|
45 |
-
return result
|
46 |
-
|
47 |
-
|
48 |
-
async def generate_index(user: User, index: int) -> GenerateResult:
|
49 |
-
s3 = s3client()
|
50 |
-
|
51 |
-
img_detail = s3uploadimage(user, s3, index)
|
52 |
-
result: List[ImageResult] = [img_detail]
|
53 |
-
|
54 |
-
s3.close()
|
55 |
-
|
56 |
-
return GenerateResult(user=user, method=Method.index, result=result)
|
57 |
-
|
58 |
-
|
59 |
-
async def generate_all(user: User):
|
60 |
-
s3 = s3client()
|
61 |
-
result: List[ImageResult] = []
|
62 |
-
|
63 |
-
for index in range(0, 88):
|
64 |
-
img_detail = s3uploadimage(user, s3, index)
|
65 |
-
result.append(img_detail)
|
66 |
-
|
67 |
-
s3.close()
|
68 |
-
|
69 |
-
return GenerateResult(user=user, method=Method.all, result=result)
|
70 |
-
|
71 |
-
|
72 |
-
def s3uploadimage(user, s3, index):
|
73 |
-
output_path = os.path.join(
|
74 |
-
IMAGE_STORE_PATH, f"{user.uuid}-{str(index).zfill(2)}.png")
|
75 |
-
used_model = model.model_cols[get_model(index)]
|
76 |
-
image = generate_img_index(reloaded_model=used_model, index=index % 11)
|
77 |
-
save_img(image, output_path)
|
78 |
-
|
79 |
-
s3_path: str = f"{user.uuid}/{str(index).zfill(2)}.png"
|
80 |
-
s3.upload_file(output_path, BUCKET_NAME, s3_path)
|
81 |
-
image_url = f'https://{BUCKET_NAME}.s3.amazonaws.com/{s3_path}'
|
82 |
-
|
83 |
-
img_detail = ImageResult(index=index,
|
84 |
-
image_url=image_url)
|
85 |
-
os.remove(output_path)
|
86 |
-
return img_detail
|
|
|
1 |
+
import os
|
2 |
+
from typing import List
|
3 |
+
|
4 |
+
from fastapi import APIRouter
|
5 |
+
|
6 |
+
from src.libs.image import save_img, generate_img_index
|
7 |
+
from src.libs.model import CganCols, get_model
|
8 |
+
from src.libs.s3 import s3client
|
9 |
+
from src.models.generate import GenerateResult, ImageResult
|
10 |
+
from src.models.main import User, Method
|
11 |
+
|
12 |
+
IMAGE_STORE_PATH = os.path.abspath("./src/store")
|
13 |
+
BUCKET_NAME = "pimthaigans-image-container"
|
14 |
+
|
15 |
+
# just make sure to have IMAGE_STORE_PATH folder created
|
16 |
+
if not os.path.exists(IMAGE_STORE_PATH):
|
17 |
+
os.makedirs(IMAGE_STORE_PATH)
|
18 |
+
|
19 |
+
router = APIRouter(
|
20 |
+
prefix="/generate",
|
21 |
+
tags=["Generate"],
|
22 |
+
responses={404: {"description": "Not found"}},
|
23 |
+
)
|
24 |
+
|
25 |
+
model = CganCols()
|
26 |
+
|
27 |
+
|
28 |
+
@router.get("/")
|
29 |
+
async def info():
|
30 |
+
return {"info": "This is the generate endpoint"}
|
31 |
+
|
32 |
+
|
33 |
+
@router.get("/status")
|
34 |
+
async def status():
|
35 |
+
return {"status": "OK"}
|
36 |
+
|
37 |
+
|
38 |
+
@router.post("/")
|
39 |
+
async def generate(user: User, index: int | None = None) -> GenerateResult:
|
40 |
+
if index or index == 0:
|
41 |
+
result: GenerateResult = await generate_index(user, index)
|
42 |
+
return result
|
43 |
+
|
44 |
+
result: GenerateResult = await generate_all(user)
|
45 |
+
return result
|
46 |
+
|
47 |
+
|
48 |
+
async def generate_index(user: User, index: int) -> GenerateResult:
|
49 |
+
s3 = s3client()
|
50 |
+
|
51 |
+
img_detail = s3uploadimage(user, s3, index)
|
52 |
+
result: List[ImageResult] = [img_detail]
|
53 |
+
|
54 |
+
s3.close()
|
55 |
+
|
56 |
+
return GenerateResult(user=user, method=Method.index, result=result)
|
57 |
+
|
58 |
+
|
59 |
+
async def generate_all(user: User):
|
60 |
+
s3 = s3client()
|
61 |
+
result: List[ImageResult] = []
|
62 |
+
|
63 |
+
for index in range(0, 88):
|
64 |
+
img_detail = s3uploadimage(user, s3, index)
|
65 |
+
result.append(img_detail)
|
66 |
+
|
67 |
+
s3.close()
|
68 |
+
|
69 |
+
return GenerateResult(user=user, method=Method.all, result=result)
|
70 |
+
|
71 |
+
|
72 |
+
def s3uploadimage(user, s3, index):
|
73 |
+
output_path = os.path.join(
|
74 |
+
IMAGE_STORE_PATH, f"{user.uuid}-{str(index).zfill(2)}.png")
|
75 |
+
used_model = model.model_cols[get_model(index)]
|
76 |
+
image = generate_img_index(reloaded_model=used_model, index=index % 11)
|
77 |
+
save_img(image, output_path)
|
78 |
+
|
79 |
+
s3_path: str = f"{user.uuid}/{str(index).zfill(2)}.png"
|
80 |
+
s3.upload_file(output_path, BUCKET_NAME, s3_path)
|
81 |
+
image_url = f'https://{BUCKET_NAME}.s3.amazonaws.com/{s3_path}'
|
82 |
+
|
83 |
+
img_detail = ImageResult(index=index,
|
84 |
+
image_url=image_url)
|
85 |
+
os.remove(output_path)
|
86 |
+
return img_detail
|
src/endpoints/view.py
CHANGED
@@ -1,63 +1,63 @@
|
|
1 |
-
from fastapi import APIRouter
|
2 |
-
|
3 |
-
from src.libs.s3 import s3resource
|
4 |
-
from src.models.view import ViewResult, ViewImage
|
5 |
-
from src.models.main import User, Method
|
6 |
-
from uuid import UUID
|
7 |
-
|
8 |
-
router = APIRouter(
|
9 |
-
prefix="/view",
|
10 |
-
tags=["View"],
|
11 |
-
responses={404: {"description": "Not found"}},
|
12 |
-
)
|
13 |
-
|
14 |
-
BUCKET_NAME = "pimthaigans-image-container"
|
15 |
-
|
16 |
-
|
17 |
-
@router.get("/status")
|
18 |
-
async def status():
|
19 |
-
return {"status": "OK"}
|
20 |
-
|
21 |
-
|
22 |
-
@router.get("/")
|
23 |
-
async def view(user: UUID, index: int | None = None) -> ViewResult:
|
24 |
-
s3 = s3resource()
|
25 |
-
bucket = s3.Bucket('pimthaigans-image-container')
|
26 |
-
|
27 |
-
objs = list(bucket.objects.filter(Prefix=f'{user}/'))
|
28 |
-
path_objs = [obj.key for obj in objs]
|
29 |
-
|
30 |
-
if len(path_objs) == 0:
|
31 |
-
return ViewResult(user=User(uuid=user), method=Method.index, result=None)
|
32 |
-
|
33 |
-
if index or index == 0:
|
34 |
-
result: ViewResult = await view_index(User(uuid=user), index, path_objs)
|
35 |
-
return result
|
36 |
-
|
37 |
-
result: ViewResult = await view_all(User(uuid=user), path_objs)
|
38 |
-
return result
|
39 |
-
|
40 |
-
|
41 |
-
async def view_index(user: User, index: int, path_objs) -> ViewResult:
|
42 |
-
imgs = [obj for obj in path_objs if obj.endswith(
|
43 |
-
f'{str(index).zfill(2)}.png')]
|
44 |
-
if len(imgs) > 0:
|
45 |
-
img_url = f'https://{BUCKET_NAME}.s3.amazonaws.com/{imgs[0]}'
|
46 |
-
return ViewResult(user=user, method=Method.index, result=[ViewImage(index=index, image_url=img_url)])
|
47 |
-
|
48 |
-
return ViewResult(user=user, method=Method.index, result=None)
|
49 |
-
|
50 |
-
|
51 |
-
async def view_all(user: User, path_objs) -> ViewResult:
|
52 |
-
img_urls = []
|
53 |
-
for index in range(0, 88):
|
54 |
-
imgs = [obj for obj in path_objs if obj.endswith(
|
55 |
-
f'{str(index).zfill(2)}.png')]
|
56 |
-
if len(imgs) > 0:
|
57 |
-
img_urls.append(
|
58 |
-
f'https://{BUCKET_NAME}.s3.amazonaws.com/{imgs[0]}')
|
59 |
-
else:
|
60 |
-
return ViewResult(user=user, method=Method.all, result=None)
|
61 |
-
|
62 |
-
return ViewResult(user=user, method=Method.all,
|
63 |
-
result=[ViewImage(index=index, image_url=img_url) for index, img_url in enumerate(img_urls)])
|
|
|
1 |
+
from fastapi import APIRouter
|
2 |
+
|
3 |
+
from src.libs.s3 import s3resource
|
4 |
+
from src.models.view import ViewResult, ViewImage
|
5 |
+
from src.models.main import User, Method
|
6 |
+
from uuid import UUID
|
7 |
+
|
8 |
+
router = APIRouter(
|
9 |
+
prefix="/view",
|
10 |
+
tags=["View"],
|
11 |
+
responses={404: {"description": "Not found"}},
|
12 |
+
)
|
13 |
+
|
14 |
+
BUCKET_NAME = "pimthaigans-image-container"
|
15 |
+
|
16 |
+
|
17 |
+
@router.get("/status")
|
18 |
+
async def status():
|
19 |
+
return {"status": "OK"}
|
20 |
+
|
21 |
+
|
22 |
+
@router.get("/")
|
23 |
+
async def view(user: UUID, index: int | None = None) -> ViewResult:
|
24 |
+
s3 = s3resource()
|
25 |
+
bucket = s3.Bucket('pimthaigans-image-container')
|
26 |
+
|
27 |
+
objs = list(bucket.objects.filter(Prefix=f'{user}/'))
|
28 |
+
path_objs = [obj.key for obj in objs]
|
29 |
+
|
30 |
+
if len(path_objs) == 0:
|
31 |
+
return ViewResult(user=User(uuid=user), method=Method.index, result=None)
|
32 |
+
|
33 |
+
if index or index == 0:
|
34 |
+
result: ViewResult = await view_index(User(uuid=user), index, path_objs)
|
35 |
+
return result
|
36 |
+
|
37 |
+
result: ViewResult = await view_all(User(uuid=user), path_objs)
|
38 |
+
return result
|
39 |
+
|
40 |
+
|
41 |
+
async def view_index(user: User, index: int, path_objs) -> ViewResult:
|
42 |
+
imgs = [obj for obj in path_objs if obj.endswith(
|
43 |
+
f'{str(index).zfill(2)}.png')]
|
44 |
+
if len(imgs) > 0:
|
45 |
+
img_url = f'https://{BUCKET_NAME}.s3.amazonaws.com/{imgs[0]}'
|
46 |
+
return ViewResult(user=user, method=Method.index, result=[ViewImage(index=index, image_url=img_url)])
|
47 |
+
|
48 |
+
return ViewResult(user=user, method=Method.index, result=None)
|
49 |
+
|
50 |
+
|
51 |
+
async def view_all(user: User, path_objs) -> ViewResult:
|
52 |
+
img_urls = []
|
53 |
+
for index in range(0, 88):
|
54 |
+
imgs = [obj for obj in path_objs if obj.endswith(
|
55 |
+
f'{str(index).zfill(2)}.png')]
|
56 |
+
if len(imgs) > 0:
|
57 |
+
img_urls.append(
|
58 |
+
f'https://{BUCKET_NAME}.s3.amazonaws.com/{imgs[0]}')
|
59 |
+
else:
|
60 |
+
return ViewResult(user=user, method=Method.all, result=None)
|
61 |
+
|
62 |
+
return ViewResult(user=user, method=Method.all,
|
63 |
+
result=[ViewImage(index=index, image_url=img_url) for index, img_url in enumerate(img_urls)])
|
src/libs/image.py
CHANGED
@@ -1,16 +1,16 @@
|
|
1 |
-
import numpy as np
|
2 |
-
import matplotlib.pyplot as plt
|
3 |
-
|
4 |
-
|
5 |
-
def generate_img_index(index, reloaded_model):
|
6 |
-
noise = np.random.normal(0, 1, (1,))
|
7 |
-
label = np.array([[index]])
|
8 |
-
return reloaded_model.predict([noise, label])[0]
|
9 |
-
|
10 |
-
|
11 |
-
def save_img(image, output_path):
|
12 |
-
plt.imshow(image, cmap='gray')
|
13 |
-
plt.axis('off')
|
14 |
-
plt.grid(False)
|
15 |
-
plt.savefig(output_path, bbox_inches='tight', pad_inches=0)
|
16 |
plt.close()
|
|
|
1 |
+
import numpy as np
|
2 |
+
import matplotlib.pyplot as plt
|
3 |
+
|
4 |
+
|
5 |
+
def generate_img_index(index, reloaded_model):
|
6 |
+
noise = np.random.normal(0, 1, (1,))
|
7 |
+
label = np.array([[index]])
|
8 |
+
return reloaded_model.predict([noise, label])[0]
|
9 |
+
|
10 |
+
|
11 |
+
def save_img(image, output_path):
|
12 |
+
plt.imshow(image, cmap='gray')
|
13 |
+
plt.axis('off')
|
14 |
+
plt.grid(False)
|
15 |
+
plt.savefig(output_path, bbox_inches='tight', pad_inches=0)
|
16 |
plt.close()
|
src/libs/model.py
CHANGED
@@ -1,51 +1,51 @@
|
|
1 |
-
from huggingface_hub import from_pretrained_keras
|
2 |
-
|
3 |
-
|
4 |
-
class CganCols:
|
5 |
-
def __init__(self):
|
6 |
-
self.model_0 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-0010')
|
7 |
-
self.model_1 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-1121')
|
8 |
-
self.model_2 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-2232')
|
9 |
-
self.model_3 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-3343')
|
10 |
-
self.model_4 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-4454')
|
11 |
-
self.model_5 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-5565')
|
12 |
-
self.model_6 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-6676')
|
13 |
-
self.model_7 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-7787')
|
14 |
-
|
15 |
-
self.model_cols = [self.model_0, self.model_1, self.model_2, self.model_3, self.model_4, self.model_5,
|
16 |
-
self.model_6, self.model_7]
|
17 |
-
|
18 |
-
|
19 |
-
def get_model(index: int):
|
20 |
-
"""
|
21 |
-
Returns the model based on the given index.
|
22 |
-
|
23 |
-
Index ranges and corresponding model values:
|
24 |
-
0-10 -> 0
|
25 |
-
11-21 -> 1
|
26 |
-
22-32 -> 2
|
27 |
-
33-43 -> 3
|
28 |
-
44-54 -> 4
|
29 |
-
55-65 -> 5
|
30 |
-
66-76 -> 6
|
31 |
-
77-87 -> 7
|
32 |
-
|
33 |
-
:param index: The index value.
|
34 |
-
:return: The corresponding model value.
|
35 |
-
"""
|
36 |
-
if 0 <= index <= 10:
|
37 |
-
return 0
|
38 |
-
elif 11 <= index <= 21:
|
39 |
-
return 1
|
40 |
-
elif 22 <= index <= 32:
|
41 |
-
return 2
|
42 |
-
elif 33 <= index <= 43:
|
43 |
-
return 3
|
44 |
-
elif 44 <= index <= 54:
|
45 |
-
return 4
|
46 |
-
elif 55 <= index <= 65:
|
47 |
-
return 5
|
48 |
-
elif 66 <= index <= 76:
|
49 |
-
return 6
|
50 |
-
elif 77 <= index <= 87:
|
51 |
-
return 7
|
|
|
1 |
+
from huggingface_hub import from_pretrained_keras
|
2 |
+
|
3 |
+
|
4 |
+
class CganCols:
|
5 |
+
def __init__(self):
|
6 |
+
self.model_0 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-0010')
|
7 |
+
self.model_1 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-1121')
|
8 |
+
self.model_2 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-2232')
|
9 |
+
self.model_3 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-3343')
|
10 |
+
self.model_4 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-4454')
|
11 |
+
self.model_5 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-5565')
|
12 |
+
self.model_6 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-6676')
|
13 |
+
self.model_7 = from_pretrained_keras('SupawitMarayat/pimthaigans-cgan-7787')
|
14 |
+
|
15 |
+
self.model_cols = [self.model_0, self.model_1, self.model_2, self.model_3, self.model_4, self.model_5,
|
16 |
+
self.model_6, self.model_7]
|
17 |
+
|
18 |
+
|
19 |
+
def get_model(index: int):
|
20 |
+
"""
|
21 |
+
Returns the model based on the given index.
|
22 |
+
|
23 |
+
Index ranges and corresponding model values:
|
24 |
+
0-10 -> 0
|
25 |
+
11-21 -> 1
|
26 |
+
22-32 -> 2
|
27 |
+
33-43 -> 3
|
28 |
+
44-54 -> 4
|
29 |
+
55-65 -> 5
|
30 |
+
66-76 -> 6
|
31 |
+
77-87 -> 7
|
32 |
+
|
33 |
+
:param index: The index value.
|
34 |
+
:return: The corresponding model value.
|
35 |
+
"""
|
36 |
+
if 0 <= index <= 10:
|
37 |
+
return 0
|
38 |
+
elif 11 <= index <= 21:
|
39 |
+
return 1
|
40 |
+
elif 22 <= index <= 32:
|
41 |
+
return 2
|
42 |
+
elif 33 <= index <= 43:
|
43 |
+
return 3
|
44 |
+
elif 44 <= index <= 54:
|
45 |
+
return 4
|
46 |
+
elif 55 <= index <= 65:
|
47 |
+
return 5
|
48 |
+
elif 66 <= index <= 76:
|
49 |
+
return 6
|
50 |
+
elif 77 <= index <= 87:
|
51 |
+
return 7
|
src/libs/s3.py
CHANGED
@@ -1,26 +1,26 @@
|
|
1 |
-
import os
|
2 |
-
from dotenv import load_dotenv
|
3 |
-
import boto3
|
4 |
-
|
5 |
-
load_dotenv(dotenv_path=".env")
|
6 |
-
|
7 |
-
|
8 |
-
def s3session():
|
9 |
-
session = boto3.session.Session(
|
10 |
-
aws_access_key_id=os.environ.get("ACCESS_KEY_ID"),
|
11 |
-
aws_secret_access_key=os.environ.get("SECRET_ACCESS_KEY"),
|
12 |
-
)
|
13 |
-
|
14 |
-
return session
|
15 |
-
|
16 |
-
|
17 |
-
def s3client():
|
18 |
-
session = s3session()
|
19 |
-
s3_client = session.client("s3")
|
20 |
-
return s3_client
|
21 |
-
|
22 |
-
|
23 |
-
def s3resource():
|
24 |
-
session = s3session()
|
25 |
-
s3_resource = session.resource("s3")
|
26 |
-
return s3_resource
|
|
|
1 |
+
import os
|
2 |
+
from dotenv import load_dotenv
|
3 |
+
import boto3
|
4 |
+
|
5 |
+
load_dotenv(dotenv_path=".env")
|
6 |
+
|
7 |
+
|
8 |
+
def s3session():
|
9 |
+
session = boto3.session.Session(
|
10 |
+
aws_access_key_id=os.environ.get("ACCESS_KEY_ID"),
|
11 |
+
aws_secret_access_key=os.environ.get("SECRET_ACCESS_KEY"),
|
12 |
+
)
|
13 |
+
|
14 |
+
return session
|
15 |
+
|
16 |
+
|
17 |
+
def s3client():
|
18 |
+
session = s3session()
|
19 |
+
s3_client = session.client("s3")
|
20 |
+
return s3_client
|
21 |
+
|
22 |
+
|
23 |
+
def s3resource():
|
24 |
+
session = s3session()
|
25 |
+
s3_resource = session.resource("s3")
|
26 |
+
return s3_resource
|
src/models/generate.py
CHANGED
@@ -1,14 +1,14 @@
|
|
1 |
-
from typing import List
|
2 |
-
from src.models.main import User, Method
|
3 |
-
from pydantic import BaseModel, HttpUrl
|
4 |
-
|
5 |
-
|
6 |
-
class ImageResult(BaseModel):
|
7 |
-
index: int
|
8 |
-
image_url: HttpUrl
|
9 |
-
|
10 |
-
|
11 |
-
class GenerateResult(BaseModel):
|
12 |
-
user: User
|
13 |
-
method: Method
|
14 |
-
result: List[ImageResult]
|
|
|
1 |
+
from typing import List
|
2 |
+
from src.models.main import User, Method
|
3 |
+
from pydantic import BaseModel, HttpUrl
|
4 |
+
|
5 |
+
|
6 |
+
class ImageResult(BaseModel):
|
7 |
+
index: int
|
8 |
+
image_url: HttpUrl
|
9 |
+
|
10 |
+
|
11 |
+
class GenerateResult(BaseModel):
|
12 |
+
user: User
|
13 |
+
method: Method
|
14 |
+
result: List[ImageResult]
|
src/models/main.py
CHANGED
@@ -1,13 +1,13 @@
|
|
1 |
-
"""Main schema for the Api"""
|
2 |
-
from pydantic import BaseModel
|
3 |
-
from uuid import UUID
|
4 |
-
from enum import Enum
|
5 |
-
|
6 |
-
|
7 |
-
class User(BaseModel):
|
8 |
-
uuid: UUID
|
9 |
-
|
10 |
-
|
11 |
-
class Method(str, Enum):
|
12 |
-
all = "all"
|
13 |
-
index = "index"
|
|
|
1 |
+
"""Main schema for the Api"""
|
2 |
+
from pydantic import BaseModel
|
3 |
+
from uuid import UUID
|
4 |
+
from enum import Enum
|
5 |
+
|
6 |
+
|
7 |
+
class User(BaseModel):
|
8 |
+
uuid: UUID
|
9 |
+
|
10 |
+
|
11 |
+
class Method(str, Enum):
|
12 |
+
all = "all"
|
13 |
+
index = "index"
|
src/models/view.py
CHANGED
@@ -1,15 +1,15 @@
|
|
1 |
-
from typing import List
|
2 |
-
|
3 |
-
from pydantic import BaseModel
|
4 |
-
|
5 |
-
from src.models.main import User, Method
|
6 |
-
|
7 |
-
|
8 |
-
class ViewImage(BaseModel):
|
9 |
-
index: int
|
10 |
-
image_url: str
|
11 |
-
|
12 |
-
class ViewResult(BaseModel):
|
13 |
-
user: User
|
14 |
-
method: Method
|
15 |
result: List[ViewImage] | None
|
|
|
1 |
+
from typing import List
|
2 |
+
|
3 |
+
from pydantic import BaseModel
|
4 |
+
|
5 |
+
from src.models.main import User, Method
|
6 |
+
|
7 |
+
|
8 |
+
class ViewImage(BaseModel):
|
9 |
+
index: int
|
10 |
+
image_url: str
|
11 |
+
|
12 |
+
class ViewResult(BaseModel):
|
13 |
+
user: User
|
14 |
+
method: Method
|
15 |
result: List[ViewImage] | None
|
test_main.http
CHANGED
@@ -1,11 +1,11 @@
|
|
1 |
-
# Test your FastAPI endpoints
|
2 |
-
|
3 |
-
GET http://127.0.0.1:8000/
|
4 |
-
Accept: application/json
|
5 |
-
|
6 |
-
###
|
7 |
-
|
8 |
-
GET http://127.0.0.1:8000/hello/User
|
9 |
-
Accept: application/json
|
10 |
-
|
11 |
-
###
|
|
|
1 |
+
# Test your FastAPI endpoints
|
2 |
+
|
3 |
+
GET http://127.0.0.1:8000/
|
4 |
+
Accept: application/json
|
5 |
+
|
6 |
+
###
|
7 |
+
|
8 |
+
GET http://127.0.0.1:8000/hello/User
|
9 |
+
Accept: application/json
|
10 |
+
|
11 |
+
###
|