fastapi demo
Browse files- Dockerfile +11 -0
- __pycache__/main.cpython-39.pyc +0 -0
- main.py +21 -0
- requirements.txt +3 -0
Dockerfile
ADDED
@@ -0,0 +1,11 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.9
|
2 |
+
|
3 |
+
WORKDIR /code
|
4 |
+
|
5 |
+
COPY ./requirements.txt /code/requirements.txt
|
6 |
+
|
7 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
8 |
+
|
9 |
+
COPY . .
|
10 |
+
|
11 |
+
CMD ["uvicorn", "main:app", "--host", "0.0.0.0", "--port", "7860"]
|
__pycache__/main.cpython-39.pyc
ADDED
Binary file (572 Bytes). View file
|
|
main.py
ADDED
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from fastapi.responses import HTMLResponse
|
3 |
+
import httpx
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
|
8 |
+
@app.get("/", response_class=HTMLResponse)
|
9 |
+
def server():
|
10 |
+
|
11 |
+
sentence = httpx.get("https://international.v1.hitokoto.cn/?encode=text").text
|
12 |
+
|
13 |
+
return f"""
|
14 |
+
<html>
|
15 |
+
<body>
|
16 |
+
<h1>{sentence}</h1>
|
17 |
+
</body>
|
18 |
+
</html>
|
19 |
+
"""
|
20 |
+
|
21 |
+
|
requirements.txt
ADDED
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
1 |
+
httpx
|
2 |
+
fastapi
|
3 |
+
uvicorn
|