Beracles
commited on
Commit
·
e14825d
1
Parent(s):
844f9ae
init ver
Browse files- .gitignore +3 -0
- Dockerfile +14 -0
- app/database.db +0 -0
- app/main.py +52 -0
- app/requirements.txt +5 -0
- database.db +0 -0
- main.py +52 -0
- requirements.txt +5 -0
.gitignore
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
.env
|
| 2 |
+
__pycache__
|
| 3 |
+
.vscode
|
Dockerfile
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
|
| 2 |
+
# you will also find guides on how best to write your Dockerfile
|
| 3 |
+
|
| 4 |
+
FROM python:3.10.5
|
| 5 |
+
|
| 6 |
+
WORKDIR /code
|
| 7 |
+
|
| 8 |
+
COPY ./requirements.txt /code/requirements.txt
|
| 9 |
+
|
| 10 |
+
RUN pip install --no-cache-dir --upgrade -r /code/requirements.txt
|
| 11 |
+
|
| 12 |
+
COPY . .
|
| 13 |
+
|
| 14 |
+
CMD ["uvicorn", "app.main:app", "--host", "0.0.0.0", "--port", "7860"]
|
app/database.db
ADDED
|
File without changes
|
app/main.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Union, Optional
|
| 2 |
+
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
import uvicorn
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class User(BaseModel):
|
| 9 |
+
name: str
|
| 10 |
+
email: str
|
| 11 |
+
password: str
|
| 12 |
+
|
| 13 |
+
class Config:
|
| 14 |
+
orm_mode = True
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
app = FastAPI()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@app.get("/")
|
| 21 |
+
def read_root():
|
| 22 |
+
return {"Hello": "i like this"}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@app.get("/items/works")
|
| 26 |
+
def works():
|
| 27 |
+
return {"data": [{"id": 1, "name": "test1"}, {"id": 2, "name": "test2"}]}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@app.get("/items/{item_id}")
|
| 31 |
+
def read_item(item_id: int, q: Union[str, None] = None):
|
| 32 |
+
return {"item_id": item_id, "q": q}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
database = {"1": {"name": "test1", "age": 18}, "2": {"name": "test2", "age": 19}}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@app.get("/user")
|
| 39 |
+
def read_user(id: str, key: Optional[str] = None):
|
| 40 |
+
if key:
|
| 41 |
+
return {"result": database[id][key]}
|
| 42 |
+
return {"result": database[id]}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@app.post("/user")
|
| 46 |
+
def create_user(user: User):
|
| 47 |
+
print(user)
|
| 48 |
+
return {"data": f"succeed creating user {user.name}"}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
uvicorn.run(app, host="127.0.0.1", port=8000)
|
app/requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
passlib
|
| 4 |
+
bcrypt
|
| 5 |
+
python-jose
|
database.db
ADDED
|
File without changes
|
main.py
ADDED
|
@@ -0,0 +1,52 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from typing import Union, Optional
|
| 2 |
+
|
| 3 |
+
from fastapi import FastAPI
|
| 4 |
+
from pydantic import BaseModel
|
| 5 |
+
import uvicorn
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
class User(BaseModel):
|
| 9 |
+
name: str
|
| 10 |
+
email: str
|
| 11 |
+
password: str
|
| 12 |
+
|
| 13 |
+
class Config:
|
| 14 |
+
orm_mode = True
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
app = FastAPI()
|
| 18 |
+
|
| 19 |
+
|
| 20 |
+
@app.get("/")
|
| 21 |
+
def read_root():
|
| 22 |
+
return {"Hello": "i like this"}
|
| 23 |
+
|
| 24 |
+
|
| 25 |
+
@app.get("/items/works")
|
| 26 |
+
def works():
|
| 27 |
+
return {"data": [{"id": 1, "name": "test1"}, {"id": 2, "name": "test2"}]}
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
@app.get("/items/{item_id}")
|
| 31 |
+
def read_item(item_id: int, q: Union[str, None] = None):
|
| 32 |
+
return {"item_id": item_id, "q": q}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
database = {"1": {"name": "test1", "age": 18}, "2": {"name": "test2", "age": 19}}
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@app.get("/user")
|
| 39 |
+
def read_user(id: str, key: Optional[str] = None):
|
| 40 |
+
if key:
|
| 41 |
+
return {"result": database[id][key]}
|
| 42 |
+
return {"result": database[id]}
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
@app.post("/user")
|
| 46 |
+
def create_user(user: User):
|
| 47 |
+
print(user)
|
| 48 |
+
return {"data": f"succeed creating user {user.name}"}
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
if __name__ == "__main__":
|
| 52 |
+
uvicorn.run(app, host="127.0.0.1", port=8000)
|
requirements.txt
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
fastapi
|
| 2 |
+
uvicorn[standard]
|
| 3 |
+
passlib
|
| 4 |
+
bcrypt
|
| 5 |
+
python-jose
|