Spaces:
Runtime error
Runtime error
fastapi
Browse files
app.py
CHANGED
|
@@ -1,21 +1,34 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
| 3 |
from PIL import Image
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
|
|
|
|
|
|
|
|
|
| 5 |
|
| 6 |
-
|
| 7 |
-
|
| 8 |
-
|
|
|
|
|
|
|
| 9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
-
#
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
os.path.join(os.path.dirname(__file__), "workdir/lion.jpg"),
|
| 16 |
-
os.path.join(os.path.dirname(__file__), "workdir/logo.png")
|
| 17 |
-
])
|
| 18 |
|
| 19 |
-
|
| 20 |
-
|
|
|
|
| 21 |
|
|
|
|
| 1 |
+
# main.py
|
| 2 |
+
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
from PIL import Image
|
| 5 |
+
import base64
|
| 6 |
+
|
| 7 |
+
app = FastAPI()
|
| 8 |
+
|
| 9 |
|
| 10 |
+
@app.get("/")
|
| 11 |
+
async def root():
|
| 12 |
+
images = []
|
| 13 |
|
| 14 |
+
with open('image1.jpg', 'rb') as open_file:
|
| 15 |
+
byte_content = open_file.read()
|
| 16 |
+
base64_bytes = base64.b64encode(byte_content)
|
| 17 |
+
base64_string = base64_bytes.decode('utf-8')
|
| 18 |
+
images.append(base64_string)
|
| 19 |
|
| 20 |
+
with open('image2.jpg', 'rb') as open_file:
|
| 21 |
+
byte_content = open_file.read()
|
| 22 |
+
base64_bytes = base64.b64encode(byte_content)
|
| 23 |
+
base64_string = base64_bytes.decode('utf-8')
|
| 24 |
+
images.append(base64_string)
|
| 25 |
|
| 26 |
+
#image_path='lion.jpg'
|
| 27 |
+
#pilim = Image.open(image_path)
|
| 28 |
+
#pilimrot = pilim.rotate(45)
|
| 29 |
+
return {"data": images}
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
+
@app.get("/items/{item_id}")
|
| 32 |
+
async def read_item(item_id):
|
| 33 |
+
return {"item_id": item_id}
|
| 34 |
|