From 9f8f9839a4574f5c7830c2c7aee0f0edcc37e4f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=BC=96=E7=A0=81=E7=8C=BF?= Date: Thu, 23 Jan 2025 01:13:29 +0800 Subject: [PATCH] first commit --- .gitignore | 1 + .idea/.gitignore | 8 +++++ .idea/checkHand.iml | 12 +++++++ .idea/inspectionProfiles/Project_Default.xml | 33 ++++++++++++++++++ .../inspectionProfiles/profiles_settings.xml | 6 ++++ .idea/misc.xml | 4 +++ .idea/modules.xml | 8 +++++ Dockerfile | 6 ++++ Dockerfile_base | 19 ++++++++++ README.md | 8 +++++ __pycache__/main.cpython-311.pyc | Bin 0 -> 689 bytes ai/__init__.py | 1 + ai/__pycache__/__init__.cpython-311.pyc | Bin 0 -> 191 bytes .../checkHandStatic.cpython-311.pyc | Bin 0 -> 951 bytes ai/checkHandStatic.py | 12 +++++++ main.py | 9 +++++ requirements.txt | 10 ++++++ 笔记.txt | 10 ++++++ 18 files changed, 147 insertions(+) create mode 100644 .gitignore create mode 100644 .idea/.gitignore create mode 100644 .idea/checkHand.iml create mode 100644 .idea/inspectionProfiles/Project_Default.xml create mode 100644 .idea/inspectionProfiles/profiles_settings.xml create mode 100644 .idea/misc.xml create mode 100644 .idea/modules.xml create mode 100644 Dockerfile create mode 100644 Dockerfile_base create mode 100644 README.md create mode 100644 __pycache__/main.cpython-311.pyc create mode 100644 ai/__init__.py create mode 100644 ai/__pycache__/__init__.cpython-311.pyc create mode 100644 ai/__pycache__/checkHandStatic.cpython-311.pyc create mode 100644 ai/checkHandStatic.py create mode 100644 main.py create mode 100644 requirements.txt create mode 100644 笔记.txt 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 0000000000000000000000000000000000000000..0cdb4a138647c3706be6c2ae79f02430108408c9 GIT binary patch literal 689 zcmZ8f%}X0m5TAK(cawCR3VIL|50;+xlD$h&1QEp|g7lJ0+3s88VphZ3O{t;~KR^`0 zdTNiJl;S@V!9#f0($d~ia`V)A8%?v$zL}kQ^YxqI-4u&2faq8LvbKN#KeX{g#-q~v zM9NnXAg~S*RuQ$%>MY__j=&(mYl^si%7dyA7+2=N98v_orY^U{eG++L2G%+g*0K4l zMo#3`z$yIEfexzNf)^)qt4pMg_#1)0x#(?)wZuz8fA^K^g>HKJVS{cJDBhHHf6#?0 zaN;B4-a8V@fHY4s0qp?LihlA;cAjNxdp%rVz-ov}I^0F(Y+q>fw$1 zJ`QB;evEe9c)Kb6ppRD%;YMD#RcY*~!eB0GQ<|<4zb5gUz83tnOLz9ryvnW9uDnJl_0($A3oC=l{f+hUa<9=)ycQ&i$B9gP zeh2xIa-@C~5BayzwrJLa897F#-behIM3*CC2g>d2=|H8OJsqpqsvU&KVT*SyVCKpA i;dr|+afhXQEOi;fau-N^8%uxx#a|AroC!&NDYAbO@RiR1 literal 0 HcmV?d00001 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 0000000000000000000000000000000000000000..64c13377b4a6d64417b16ea4c02c6befd3f60c69 GIT binary patch literal 191 zcmZ3^%ge<81j+0Z)8&BlV-N=hn4pZ$d_cx@h7^Vr#vFzah7_h?22JLdj6gw6##@Y9 zen65xIU_YW+aobACAcK9Br|y>!)K7@Ut0R1#i>Qb`boK!`o;OBMail9aFzOrnfmeZ wnR%Hd@$q^EmA^P_a`RJ4b5iY!IDlF~#utkNi4V+-jEpxJ6Co}ZA{MG5aj3Wg2XZNukU6YedrQ;$5xfpkOOSHl zkRu1A@(YSk`7x=~L$p#)T;P@}J@o>!c488h@%r=3&UogV+5NV-SOk<`e?Gr`NdSII zV=CH289zbg2t4qJ4*{_Wk-Fk5foiJ+6nF-n`UyPkSOGY}Hxpa)^i41ezolssVYFLq z=C?wIy8g=H``n#GrXO`;j31zK1PpBAfvs#|Ra<2m(>-MaJ+hKr@HEViJST`O_dN}w?Uv7W9GB5ubU)&$U)%^HkNHg}U~bM6lgdtI{qbvrBS>%( zQ%Ppx_Hw-odsDvfgUt8+QBk0)bjdMhImt62U!`d(LQAl7p{G1dEtXkgSzeSRPnz+J z7jVZ^g~pk`Bh*gp$0gk1GP+i)T|Kt8IE%Tp9UNFZ>clRy@<~`u>z|R0rQSXedKz%J zlE+P4sV&R#b%Y+ASJuv#D`(61hqo(V>LXpfTf6{-O9}nb$bhAL{SRN)Ps`P_a&=%- z$M_pG%>`jl8scCn6-A2k_d34RZ&LcMEO8=wOM_7A9;ET zVs*yVNm@RyyT~kY!X!PQj88?9$~j&c8(E`I<5hIX!{%=gMk*m>2OV literal 0 HcmV?d00001 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