wldmr commited on
Commit
e0f6d34
·
1 Parent(s): b055987
Files changed (1) hide show
  1. app.py +27 -14
app.py CHANGED
@@ -1,21 +1,34 @@
1
- import gradio as gr
2
- import os
 
3
  from PIL import Image
 
 
 
 
4
 
 
 
 
5
 
6
- def image_mod(image_path):
7
- image = Image.open(image_path)
8
- return image.rotate(45)
 
 
9
 
 
 
 
 
 
10
 
11
- #demo = gr.Interface(image_mod, gr.Image(type="pil"), "image",
12
- demo = gr.Interface(image_mod, "text", "image",
13
- flagging_options=["blurry", "incorrect", "other"], examples=[
14
- os.path.join(os.path.dirname(__file__), "workdir/cheetah.jpg"),
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
- if __name__ == "__main__":
20
- demo.launch()
 
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