commit 9f8f9839a4574f5c7830c2c7aee0f0edcc37e4f8 Author: 编码猿 Date: Thu Jan 23 01:13:29 2025 +0800 first commit diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0cafc1c --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +.venv/ \ No newline at end of file diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/checkHand.iml b/.idea/checkHand.iml new file mode 100644 index 0000000..cc13cf3 --- /dev/null +++ b/.idea/checkHand.iml @@ -0,0 +1,12 @@ + + + + + + + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/Project_Default.xml b/.idea/inspectionProfiles/Project_Default.xml new file mode 100644 index 0000000..a2cb7e7 --- /dev/null +++ b/.idea/inspectionProfiles/Project_Default.xml @@ -0,0 +1,33 @@ + + + + \ No newline at end of file diff --git a/.idea/inspectionProfiles/profiles_settings.xml b/.idea/inspectionProfiles/profiles_settings.xml new file mode 100644 index 0000000..105ce2d --- /dev/null +++ b/.idea/inspectionProfiles/profiles_settings.xml @@ -0,0 +1,6 @@ + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..2953e5e --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..1ad7375 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..003175e --- /dev/null +++ b/Dockerfile @@ -0,0 +1,6 @@ +FROM ai-modelscope:v1.0 +WORKDIR /code +COPY . /code + +# 运行网站 +CMD ["uvicorn", "main:app", "--proxy-headers","--host", "0.0.0.0", "--port", "9741"] \ No newline at end of file diff --git a/Dockerfile_base b/Dockerfile_base new file mode 100644 index 0000000..458735e --- /dev/null +++ b/Dockerfile_base @@ -0,0 +1,19 @@ +# 基本镜像,为个人ai项目提供运行环境 + +FROM python:3.10 +COPY ./requirements.txt /requirements.txt + +# 换源为清华大学 +RUN sed -i s@deb.debian.org@mirrors.tuna.tsinghua.edu.cn@g /etc/apt/sources.list.d/debian.sources + +# 解决python 库 cv2报错 libGL.so.1: cannot open shared object file: No such file or directory +RUN apt-get clean && apt-get update && apt-get install -y libgl1 + +# 更换pip下载地址为阿里云镜像源 +RUN pip config set global.index-url http://mirrors.aliyun.com/pypi/simple/ +RUN pip config set install.trusted-host mirrors.aliyun.com + +# 从 requirements.txt 安装 python依赖 +RUN pip install --no-cache-dir -r /requirements.txt + +CMD ["/bin/bash"] \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..7ab4aac --- /dev/null +++ b/README.md @@ -0,0 +1,8 @@ +# ai 手势识别接口 + +基于 modelscope + fastapi + +接口地址:http://127.0.0.1:9741/ai/check_hand +参数:url 图片地址 + +案例:http://127.0.0.1:9741/ai/check_hand?url=http://bj-mc-prod-asset.oss-cn-beijing.aliyuncs.com/wiki-pic/Gesture13.jpg \ No newline at end of file diff --git a/__pycache__/main.cpython-311.pyc b/__pycache__/main.cpython-311.pyc new file mode 100644 index 0000000..0cdb4a1 Binary files /dev/null and b/__pycache__/main.cpython-311.pyc differ diff --git a/ai/__init__.py b/ai/__init__.py new file mode 100644 index 0000000..cd09d8f --- /dev/null +++ b/ai/__init__.py @@ -0,0 +1 @@ +from .checkHandStatic import * \ No newline at end of file diff --git a/ai/__pycache__/__init__.cpython-311.pyc b/ai/__pycache__/__init__.cpython-311.pyc new file mode 100644 index 0000000..64c1337 Binary files /dev/null and b/ai/__pycache__/__init__.cpython-311.pyc differ diff --git a/ai/__pycache__/checkHandStatic.cpython-311.pyc b/ai/__pycache__/checkHandStatic.cpython-311.pyc new file mode 100644 index 0000000..04d7d7a Binary files /dev/null and b/ai/__pycache__/checkHandStatic.cpython-311.pyc differ diff --git a/ai/checkHandStatic.py b/ai/checkHandStatic.py new file mode 100644 index 0000000..b04aa29 --- /dev/null +++ b/ai/checkHandStatic.py @@ -0,0 +1,12 @@ +from modelscope.pipelines import pipeline +from modelscope.utils.constant import Tasks + +class checkHandStatic: + modelName: str = 'damo/cv_mobileface_hand-static' + + def check(self, url): + hand_static = pipeline( + task=Tasks.hand_static, + model=self.modelName + ) + return hand_static(url) \ No newline at end of file diff --git a/main.py b/main.py new file mode 100644 index 0000000..12654f3 --- /dev/null +++ b/main.py @@ -0,0 +1,9 @@ +from fastapi import FastAPI +from ai.checkHandStatic import checkHandStatic +app = FastAPI() + +# http://0.0.0.0:9741/ai/check_hand?url=http://bj-mc-prod-asset.oss-cn-beijing.aliyuncs.com/wiki-pic/Gesture13.jpg +@app.get("/ai/check_hand") +async def checkHand(url: str = ''): + hand = checkHandStatic() + return hand.check(url) diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..be52d24 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,10 @@ +fastapi==0.113.0 +pydantic==2.8.0 +uvicorn==0.27.1 + +modelscope==1.12.0 +torch==2.2.0 +numpy==1.26.4 +torch==2.2.0 +opencv-python==4.9.0.80 +torchvision \ No newline at end of file diff --git a/笔记.txt b/笔记.txt new file mode 100644 index 0000000..0bfab5f --- /dev/null +++ b/笔记.txt @@ -0,0 +1,10 @@ +启动命令:uvicorn main:app --reload --host '0.0.0.0' --port 9741 + + +打包镜像:docker build -t ai_check_hand . +打包镜像:docker build -t ai-modelscope:v1.0 . + +docker tag ai-modelscope:v1.0 bmy/ai-modelscope:v1.0 + +运行镜像:docker run -d --name ai_check_hand -p 9741:9741 ai_check_hand +运行镜像:docker run -d --name ai_check_hand -p 9741:9741 ai-hand-project \ No newline at end of file