tanbushi commited on
Commit
6d1fe81
·
1 Parent(s): 710eb42

Add application file

Browse files
Files changed (5) hide show
  1. .gitignore +1 -0
  2. Dockerfile +16 -0
  3. app.py +9 -0
  4. requirements.txt +2 -0
  5. 说明.md +57 -0
.gitignore ADDED
@@ -0,0 +1 @@
 
 
1
+ __pycache__/
Dockerfile ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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.9
5
+
6
+ RUN useradd -m -u 1000 user
7
+ USER user
8
+ ENV PATH="/home/user/.local/bin:$PATH"
9
+
10
+ WORKDIR /app
11
+
12
+ COPY --chown=user ./requirements.txt requirements.txt
13
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
14
+
15
+ COPY --chown=user . /app
16
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
app.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ # uvicorn app:app --host 0.0.0.0 --port 7860 --reload
2
+
3
+ from fastapi import FastAPI
4
+
5
+ app = FastAPI()
6
+
7
+ @app.get("/")
8
+ def greet_json():
9
+ return {"Hello": "World!"}
requirements.txt ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ fastapi
2
+ uvicorn[standard]
说明.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ### 项目名称:api-mapper
2
+ ### 项目地址:git clone [email protected]:spaces/tanbushi/api-mapper
3
+ ### 创建环境:api-mapper
4
+ conda create -n api-mapper python=3.11.10
5
+
6
+ ### 创建文件
7
+ - 创建:requirements.txt
8
+ ```text
9
+ fastapi
10
+ uvicorn[standard]
11
+ ```
12
+ - 创建:app.py
13
+ ```python
14
+ from fastapi import FastAPI
15
+
16
+ app = FastAPI()
17
+
18
+ @app.get("/")
19
+ def greet_json():
20
+ return {"Hello": "World!"}
21
+ ```
22
+ - 创建:Dockerfile
23
+ ```dockerfile
24
+ # Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
25
+ # you will also find guides on how best to write your Dockerfile
26
+
27
+ FROM python:3.9
28
+
29
+ RUN useradd -m -u 1000 user
30
+ USER user
31
+ ENV PATH="/home/user/.local/bin:$PATH"
32
+
33
+ WORKDIR /app
34
+
35
+ COPY --chown=user ./requirements.txt requirements.txt
36
+ RUN pip install --no-cache-dir --upgrade -r requirements.txt
37
+
38
+ COPY --chown=user . /app
39
+ CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]
40
+ ```
41
+
42
+ ### 安装依赖模块
43
+ pip install -r requirements.txt
44
+
45
+ ### 本机测试运行
46
+ uvicorn app:app --host 0.0.0.0 --port 7860 --reload
47
+
48
+ ### 创建 .gitignore 文件
49
+ ```txt
50
+ __pycache__/
51
+ ```
52
+ ### 提交到 huggingface
53
+ ```bash
54
+ git add requirements.txt app.py Dockerfile
55
+ git commit -m "Add application file"
56
+ git push
57
+ ```