api-mapper / 说明.md
tanbushi's picture
说明.md
f7313fc

项目名称:api-mapper

项目地址:git clone git@hf.co:spaces/tanbushi/api-mapper

创建环境:api-mapper

conda create -n api-mapper python=3.11.10

创建文件

  • 创建:requirements.txt
fastapi
uvicorn[standard]
  • 创建:app.py
from fastapi import FastAPI

app = FastAPI()

@app.get("/")
def greet_json():
    return {"Hello": "World!"}
  • 创建:Dockerfile
# Read the doc: https://huggingface.co/docs/hub/spaces-sdks-docker
# you will also find guides on how best to write your Dockerfile

FROM python:3.9

RUN useradd -m -u 1000 user
USER user
ENV PATH="/home/user/.local/bin:$PATH"

WORKDIR /app

COPY --chown=user ./requirements.txt requirements.txt
RUN pip install --no-cache-dir --upgrade -r requirements.txt

COPY --chown=user . /app
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "7860"]

安装依赖模块

pip install -r requirements.txt

本机测试运行

uvicorn app:app --host 0.0.0.0 --port 7860 --reload

创建 .gitignore 文件

__pycache__/

提交到 huggingface

git add requirements.txt app.py Dockerfile
git commit -m "Add application file"
git push

huggingface 里的应用 api-mapper 自动编译并运行