new
Browse files- app.py +4 -0
- index.html +12 -22
- main.py +55 -0
- requirements.txt +2 -0
- static/index.html +14 -0
app.py
ADDED
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import subprocess
|
2 |
+
|
3 |
+
subprocess.run("uvicorn main:app --host 0.0.0.0 --port 7860", shell=True)
|
4 |
+
|
index.html
CHANGED
@@ -1,24 +1,14 @@
|
|
1 |
-
<!DOCTYPE html>
|
2 |
<html>
|
3 |
-
|
4 |
-
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
</p>
|
16 |
-
<p>
|
17 |
-
Also don't forget to check the
|
18 |
-
<a href="https://huggingface.co/docs/hub/spaces" target="_blank"
|
19 |
-
>Spaces documentation</a
|
20 |
-
>.
|
21 |
-
</p>
|
22 |
-
</div>
|
23 |
-
</body>
|
24 |
</html>
|
|
|
|
|
1 |
<html>
|
2 |
+
<body style='padding: 10px;'>
|
3 |
+
|
4 |
+
<h1>Tubifier Application</h1>
|
5 |
+
<div>docs:
|
6 |
+
<a href='/docs' target="_blank" rel="noopener noreferrer">here</a>
|
7 |
+
</div>
|
8 |
+
|
9 |
+
<div>api:
|
10 |
+
<a href='/api' target="_blank" rel="noopener noreferrer">here</a>
|
11 |
+
</div>
|
12 |
+
|
13 |
+
</body>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
</html>
|
main.py
ADDED
@@ -0,0 +1,55 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,2 @@
|
|
|
|
|
|
|
1 |
+
fastapi==0.74.*
|
2 |
+
uvicorn[standard]==0.17.*
|
static/index.html
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<html>
|
2 |
+
<body style='padding: 10px;'>
|
3 |
+
|
4 |
+
<h1>Tubifier Application</h1>
|
5 |
+
<div>docs:
|
6 |
+
<a href='/docs' target="_blank" rel="noopener noreferrer">here</a>
|
7 |
+
</div>
|
8 |
+
|
9 |
+
<div>api:
|
10 |
+
<a href='/api' target="_blank" rel="noopener noreferrer">here</a>
|
11 |
+
</div>
|
12 |
+
|
13 |
+
</body>
|
14 |
+
</html>
|