long candy support

This commit is contained in:
meelstorm
2025-08-28 16:30:52 +02:00
parent bf13a5ea2d
commit d52c844b5d
24 changed files with 1714 additions and 16 deletions

View File

@@ -43,6 +43,9 @@ class Service:
return 0
def load_model(self, path, name):
if name in self.models:
# Model already loaded, skip loading
return 0
self.models[name] = tf.keras.models.load_model(path)
return 0
@@ -156,3 +159,4 @@ async def get_output_size():
raise HTTPException(status_code=500, detail=str(e))

View File

@@ -12,6 +12,8 @@
<Name>PythonModelAPI</Name>
<RootNamespace>PythonModelAPI</RootNamespace>
<PublishUrl>D:\Inspectron\Hawkeye\code\VisionBuilder5\VisionBuilder.UI\Hawkeye.VisionBuilder\bin\Debug\Data\Models</PublishUrl>
<SuppressEnvironmentCreationPrompt>True</SuppressEnvironmentCreationPrompt>
<SuppressConfigureTestFrameworkPrompt>true</SuppressConfigureTestFrameworkPrompt>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)' == 'Debug' ">
<DebugSymbols>true</DebugSymbols>
@@ -22,6 +24,7 @@
<EnableUnmanagedDebugging>false</EnableUnmanagedDebugging>
</PropertyGroup>
<ItemGroup>
<Compile Include="test.py" />
<Compile Include="PythonModelAPI.py" />
</ItemGroup>
<Import Project="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion)\Python Tools\Microsoft.PythonTools.targets" />

View File

@@ -0,0 +1 @@
docker run --gpus all -it -p 8000:8000 -v $(pwd):/app -w /app cv uvicorn --host 0.0.0.0 PythonModelAPI:app

26
PythonModelAPI/dockerfile Normal file
View File

@@ -0,0 +1,26 @@
# CUDA 11.2.2 + cuDNN 8 on Ubuntu 20.04
FROM nvidia/cuda:11.8.0-cudnn8-runtime-ubuntu22.04
ENV DEBIAN_FRONTEND=noninteractive \
PYTHONDONTWRITEBYTECODE=1 \
PYTHONUNBUFFERED=1 \
LANG=C.UTF-8
# Python 3.10 + pip
RUN apt-get update && apt-get install -y --no-install-recommends \
python3.10 python3-pip build-essential \
&& ln -sf /usr/bin/python3.10 /usr/bin/python \
&& ln -sf /usr/bin/pip3 /usr/bin/pip \
&& rm -rf /var/lib/apt/lists/*
# Python deps
RUN pip install --no-cache-dir \
fastapi \
uvicorn \
pillow \
tensorflow==2.19.0 \
python-multipart
EXPOSE 8000
CMD ["uvicorn", "app:app", "--host", "0.0.0.0", "--port", "8000"]

5
PythonModelAPI/test.py Normal file
View File

@@ -0,0 +1,5 @@
import tensorflow as tf
import time
tf.keras.models.load_model("office4_tr.h5")
# sleep for 5 seconds to simulate long loading time
time.sleep(5)