app file
Browse files
README.md
CHANGED
@@ -4,7 +4,7 @@ emoji: π
|
|
4 |
colorFrom: purple
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
-
app_file:
|
8 |
pinned: false
|
9 |
license: gpl-3.0
|
10 |
---
|
|
|
4 |
colorFrom: purple
|
5 |
colorTo: red
|
6 |
sdk: gradio
|
7 |
+
app_file: server.py
|
8 |
pinned: false
|
9 |
license: gpl-3.0
|
10 |
---
|
app.py
CHANGED
@@ -1,4 +1,55 @@
|
|
1 |
-
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
4 |
|
|
|
1 |
+
# main.py
|
2 |
|
3 |
+
from fastapi import FastAPI
|
4 |
+
from PIL import Image
|
5 |
+
import base64
|
6 |
+
from fastapi.responses import HTMLResponse, FileResponse
|
7 |
+
|
8 |
+
app = FastAPI()
|
9 |
+
|
10 |
+
|
11 |
+
@app.get("/")
|
12 |
+
async def root():
|
13 |
+
return FileResponse(path="static/index.html", media_type="text/html")
|
14 |
+
|
15 |
+
@app.get("/html")
|
16 |
+
async def root():
|
17 |
+
"""Basic HTML response."""
|
18 |
+
body = (
|
19 |
+
"<html>"
|
20 |
+
"<body style='padding: 10px;'>"
|
21 |
+
"<h1>Welcome to the API</h1>"
|
22 |
+
"<div>"
|
23 |
+
"Check the docs: <a href='/docs'>here</a>"
|
24 |
+
"</div>"
|
25 |
+
"</body>"
|
26 |
+
"</html>"
|
27 |
+
)
|
28 |
+
|
29 |
+
return HTMLResponse(content=body)
|
30 |
+
|
31 |
+
@app.get("/api")
|
32 |
+
async def cal_api():
|
33 |
+
images = []
|
34 |
+
|
35 |
+
with open('workdir/lion.jpg', 'rb') as open_file:
|
36 |
+
byte_content = open_file.read()
|
37 |
+
base64_bytes = base64.b64encode(byte_content)
|
38 |
+
base64_string = base64_bytes.decode('utf-8')
|
39 |
+
images.append(base64_string)
|
40 |
+
|
41 |
+
with open('workdir/cheetah.jpg', 'rb') as open_file:
|
42 |
+
byte_content = open_file.read()
|
43 |
+
base64_bytes = base64.b64encode(byte_content)
|
44 |
+
base64_string = base64_bytes.decode('utf-8')
|
45 |
+
images.append(base64_string)
|
46 |
+
|
47 |
+
#image_path='lion.jpg'
|
48 |
+
#pilim = Image.open(image_path)
|
49 |
+
#pilimrot = pilim.rotate(45)
|
50 |
+
return {"data": images}
|
51 |
+
|
52 |
+
@app.get("/items/{item_id}")
|
53 |
+
async def read_item(item_id):
|
54 |
+
return {"item_id": item_id}
|
55 |
|
main.py
DELETED
@@ -1,55 +0,0 @@
|
|
1 |
-
# main.py
|
2 |
-
|
3 |
-
from fastapi import FastAPI
|
4 |
-
from PIL import Image
|
5 |
-
import base64
|
6 |
-
from fastapi.responses import HTMLResponse, FileResponse
|
7 |
-
|
8 |
-
app = FastAPI()
|
9 |
-
|
10 |
-
|
11 |
-
@app.get("/")
|
12 |
-
async def root():
|
13 |
-
return FileResponse(path="static/index.html", media_type="text/html")
|
14 |
-
|
15 |
-
@app.get("/html")
|
16 |
-
async def root():
|
17 |
-
"""Basic HTML response."""
|
18 |
-
body = (
|
19 |
-
"<html>"
|
20 |
-
"<body style='padding: 10px;'>"
|
21 |
-
"<h1>Welcome to the API</h1>"
|
22 |
-
"<div>"
|
23 |
-
"Check the docs: <a href='/docs'>here</a>"
|
24 |
-
"</div>"
|
25 |
-
"</body>"
|
26 |
-
"</html>"
|
27 |
-
)
|
28 |
-
|
29 |
-
return HTMLResponse(content=body)
|
30 |
-
|
31 |
-
@app.get("/api")
|
32 |
-
async def cal_api():
|
33 |
-
images = []
|
34 |
-
|
35 |
-
with open('workdir/lion.jpg', 'rb') as open_file:
|
36 |
-
byte_content = open_file.read()
|
37 |
-
base64_bytes = base64.b64encode(byte_content)
|
38 |
-
base64_string = base64_bytes.decode('utf-8')
|
39 |
-
images.append(base64_string)
|
40 |
-
|
41 |
-
with open('workdir/cheetah.jpg', 'rb') as open_file:
|
42 |
-
byte_content = open_file.read()
|
43 |
-
base64_bytes = base64.b64encode(byte_content)
|
44 |
-
base64_string = base64_bytes.decode('utf-8')
|
45 |
-
images.append(base64_string)
|
46 |
-
|
47 |
-
#image_path='lion.jpg'
|
48 |
-
#pilim = Image.open(image_path)
|
49 |
-
#pilimrot = pilim.rotate(45)
|
50 |
-
return {"data": images}
|
51 |
-
|
52 |
-
@app.get("/items/{item_id}")
|
53 |
-
async def read_item(item_id):
|
54 |
-
return {"item_id": item_id}
|
55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
server.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
|
3 |
+
subprocess.run("uvicorn app:app --host 0.0.0.0 --port 7860", shell=True)
|
4 |
+
|