Spaces:
Running
Running
Commit
·
e151ad4
0
Parent(s):
v1
Browse files- .gitattributes +35 -0
- Dockerfile +38 -0
- InstallFromReadme.sh +5 -0
- README.md +14 -0
- app.py +162 -0
- docker-compose.yml +17 -0
- requirements.txt +3 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
Dockerfile
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# copiado do build do hugging face em 27/12/2025
|
| 2 |
+
|
| 3 |
+
FROM docker.io/library/python:3.10@sha256:ad84630de0e8b6f2ee92b4e2996b08c269efa96be13558d0233ed08a0e190606
|
| 4 |
+
|
| 5 |
+
# COPY --from=root / /
|
| 6 |
+
COPY requirements.txt .
|
| 7 |
+
|
| 8 |
+
WORKDIR /app
|
| 9 |
+
|
| 10 |
+
|
| 11 |
+
RUN apt-get update && apt-get install -y git git-lfs ffmpeg libsm6 libxext6 cmake rsync libgl1 \
|
| 12 |
+
&& rm -rf /var/lib/apt/lists/* \
|
| 13 |
+
&& git lfs install
|
| 14 |
+
RUN pip install --no-cache-dir pip -U && pip install --no-cache-dir datasets "huggingface-hub>=0.30" "hf-transfer>=0.1.4" "protobuf<4" "click<8.1" "pydantic~=1.0"
|
| 15 |
+
RUN apt-get update && apt-get install -y curl && \
|
| 16 |
+
curl -fsSL https://deb.nodesource.com/setup_20.x | bash - && \
|
| 17 |
+
apt-get install -y nodejs && \
|
| 18 |
+
rm -rf /var/lib/apt/lists/* && \
|
| 19 |
+
apt-get clean
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
RUN --mount=target=/tmp/requirements.txt,source=requirements.txt pip install --no-cache-dir -r /tmp/requirements.txt
|
| 23 |
+
|
| 24 |
+
# instala o gradio a partir do readm!
|
| 25 |
+
COPY InstallFromReadme.sh .
|
| 26 |
+
COPY README.md .
|
| 27 |
+
RUN chmod +x InstallFromReadme.sh
|
| 28 |
+
RUN ./InstallFromReadme.sh
|
| 29 |
+
|
| 30 |
+
RUN pip install --no-cache-dir "uvicorn>=0.14.0" spaces
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
RUN mkdir -p /home/user && ( [ -e /home/user/app ] || ln -s /app/ /home/user/app ) || true
|
| 34 |
+
|
| 35 |
+
# -- o hf faz um --link.
|
| 36 |
+
COPY . /app
|
| 37 |
+
|
| 38 |
+
CMD ["python","app.py"]
|
InstallFromReadme.sh
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version=$(cat README.md | grep -E "sdk_version\: (.+)" | cut -d " " -f 2)
|
| 2 |
+
|
| 3 |
+
echo "Installing gradio version $version";
|
| 4 |
+
|
| 5 |
+
pip install gradio==$version
|
README.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
title: SQL ONNX Info
|
| 3 |
+
emoji: ➡️
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: yellow
|
| 6 |
+
sdk: gradio
|
| 7 |
+
sdk_version: 6.2.0
|
| 8 |
+
pinned: false
|
| 9 |
+
app_port: 8080
|
| 10 |
+
---
|
| 11 |
+
|
| 12 |
+
Returns information about supported ONNX models in SQL Server!
|
| 13 |
+
|
| 14 |
+
|
app.py
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import onnx
|
| 3 |
+
from huggingface_hub import HfApi
|
| 4 |
+
import json
|
| 5 |
+
import sys
|
| 6 |
+
import os
|
| 7 |
+
import io
|
| 8 |
+
import requests
|
| 9 |
+
from urllib.parse import urlparse
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
HfClient = HfApi();
|
| 13 |
+
|
| 14 |
+
ONNX_PREFERED = [
|
| 15 |
+
"model.onnx",
|
| 16 |
+
"onnx/model.onnx"
|
| 17 |
+
]
|
| 18 |
+
|
| 19 |
+
ONNX_CACHE = {
|
| 20 |
+
'models': {
|
| 21 |
+
|
| 22 |
+
}
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
def is_url(path):
|
| 26 |
+
try:
|
| 27 |
+
result = urlparse(path)
|
| 28 |
+
return all([result.scheme, result.netloc])
|
| 29 |
+
except ValueError:
|
| 30 |
+
return False
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def load_model(path):
|
| 34 |
+
if is_url(path):
|
| 35 |
+
print(f"Downloading model from: {path}...", file=sys.stderr)
|
| 36 |
+
try:
|
| 37 |
+
response = requests.get(path)
|
| 38 |
+
response.raise_for_status() # Check for HTTP errors
|
| 39 |
+
# Load from binary stream
|
| 40 |
+
return onnx.load(io.BytesIO(response.content))
|
| 41 |
+
except requests.exceptions.RequestException as e:
|
| 42 |
+
print(f"Error downloading model: {e}", file=sys.stderr)
|
| 43 |
+
sys.exit(1)
|
| 44 |
+
else:
|
| 45 |
+
# Check if local file exists before loading
|
| 46 |
+
if not os.path.exists(path):
|
| 47 |
+
print(f"Error: File not found at {path}", file=sys.stderr)
|
| 48 |
+
sys.exit(1)
|
| 49 |
+
|
| 50 |
+
return onnx.load(path)
|
| 51 |
+
|
| 52 |
+
def CheckSqlOnnx(path):
|
| 53 |
+
|
| 54 |
+
OnnxModel = load_model(path);
|
| 55 |
+
|
| 56 |
+
initializer_names = {init.name for init in OnnxModel.graph.initializer}
|
| 57 |
+
inputs = [inp.name for inp in OnnxModel.graph.input if inp.name not in initializer_names]
|
| 58 |
+
outputs = [out.name for out in OnnxModel.graph.output]
|
| 59 |
+
|
| 60 |
+
required_inputs = {"input_ids", "attention_mask"}
|
| 61 |
+
required_outputs = {"token_embeddings", "sentence_embedding"}
|
| 62 |
+
|
| 63 |
+
is_supported = (
|
| 64 |
+
required_inputs.issubset(inputs) and
|
| 65 |
+
required_outputs.issubset(outputs)
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
+
OnnxInouts = {
|
| 69 |
+
"supported": is_supported,
|
| 70 |
+
"inputs": inputs,
|
| 71 |
+
"outputs": outputs
|
| 72 |
+
}
|
| 73 |
+
|
| 74 |
+
return OnnxInouts;
|
| 75 |
+
|
| 76 |
+
def CheckModel(repo_id: str, path: str | None = None):
|
| 77 |
+
|
| 78 |
+
MODELS_CACHE = ONNX_CACHE['models'];
|
| 79 |
+
|
| 80 |
+
CacheSlot = MODELS_CACHE.get(repo_id);
|
| 81 |
+
|
| 82 |
+
if CacheSlot:
|
| 83 |
+
return json.dumps(CacheSlot, indent = 2);
|
| 84 |
+
|
| 85 |
+
|
| 86 |
+
|
| 87 |
+
model_info = HfClient.model_info(repo_id=repo_id)
|
| 88 |
+
|
| 89 |
+
# Extract filenames from RepoSibling objects
|
| 90 |
+
sibling_files = [s.rfilename for s in model_info.siblings]
|
| 91 |
+
|
| 92 |
+
onnx_path = None
|
| 93 |
+
|
| 94 |
+
if path:
|
| 95 |
+
if path in sibling_files:
|
| 96 |
+
onnx_path = path
|
| 97 |
+
else:
|
| 98 |
+
return f"Error: ONNX file not found: {path}"
|
| 99 |
+
else:
|
| 100 |
+
for p in ONNX_PREFERED:
|
| 101 |
+
if p in sibling_files:
|
| 102 |
+
onnx_path = p
|
| 103 |
+
break
|
| 104 |
+
|
| 105 |
+
if not onnx_path:
|
| 106 |
+
onnx_path = next(
|
| 107 |
+
(f for f in sibling_files if f.lower().endswith(".onnx")),
|
| 108 |
+
None
|
| 109 |
+
)
|
| 110 |
+
|
| 111 |
+
if not onnx_path:
|
| 112 |
+
raise "Error: No ONNX model found in repository";
|
| 113 |
+
|
| 114 |
+
# Build Hugging Face raw file URL
|
| 115 |
+
file_url = f"https://huggingface.co/{repo_id}/resolve/main/{onnx_path}"
|
| 116 |
+
|
| 117 |
+
# Check SQL ONNX compatibility
|
| 118 |
+
OnnxInfo = CheckSqlOnnx(file_url)
|
| 119 |
+
|
| 120 |
+
CacheSlot = {
|
| 121 |
+
'url': file_url
|
| 122 |
+
,'onnx': OnnxInfo
|
| 123 |
+
}
|
| 124 |
+
|
| 125 |
+
MODELS_CACHE[repo_id] = CacheSlot
|
| 126 |
+
|
| 127 |
+
return json.dumps({**CacheSlot, 'cached': False}, indent = 2);
|
| 128 |
+
|
| 129 |
+
|
| 130 |
+
with gr.Blocks() as demo:
|
| 131 |
+
|
| 132 |
+
gr.Markdown("""
|
| 133 |
+
This sample app test if a given model repository can be used with SQL Server ONNX.
|
| 134 |
+
In some tests, discovered that is not any ONNX model that works with sql server CREATE EXTERNAL MODEL.
|
| 135 |
+
For works, the input parameters of neural network must contains specific names, and output also.
|
| 136 |
+
I dont know if this behavior will be ketp in future verisons of SQL 2025...
|
| 137 |
+
|
| 138 |
+
But, while we dont have official doc about this, this repo can help discovery if a given model will work with sql server if you plan download to use with ONNX.
|
| 139 |
+
Just input the model name bellow in format user/model-name (check examples).
|
| 140 |
+
|
| 141 |
+
Look at JSON output. If "supported" is True, then you can use with SQL...
|
| 142 |
+
|
| 143 |
+
Soon bring a default tested list!
|
| 144 |
+
|
| 145 |
+
**IMPORTANT**: To check, this space will attempt donwload the model onnx file. If is big can take several minutes.
|
| 146 |
+
""")
|
| 147 |
+
|
| 148 |
+
ModelPath = gr.Textbox(label="Model Repository", submit_btn = True);
|
| 149 |
+
ModelInfoOut = gr.Textbox(label="Model Info", lines = 10)
|
| 150 |
+
|
| 151 |
+
ModelPath.submit(fn=CheckModel, inputs=ModelPath, outputs=ModelInfoOut)
|
| 152 |
+
|
| 153 |
+
gr.Examples([
|
| 154 |
+
["intfloat/multilingual-e5-large"]
|
| 155 |
+
,["mixedbread-ai/mxbai-embed-xsmall-v1"]
|
| 156 |
+
,["nsense/all-MiniLM-L6-v2-onnx"]
|
| 157 |
+
|
| 158 |
+
], ModelPath)
|
| 159 |
+
|
| 160 |
+
demo.launch(
|
| 161 |
+
server_name = '0.0.0.0'
|
| 162 |
+
)
|
docker-compose.yml
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
volumes:
|
| 2 |
+
hfdata:
|
| 3 |
+
|
| 4 |
+
services:
|
| 5 |
+
app:
|
| 6 |
+
build: .
|
| 7 |
+
ports:
|
| 8 |
+
- 8080:7860
|
| 9 |
+
stdin_open: true # docker run -i
|
| 10 |
+
tty: true # docker run -t
|
| 11 |
+
deploy:
|
| 12 |
+
resources:
|
| 13 |
+
reservations:
|
| 14 |
+
devices:
|
| 15 |
+
- driver: nvidia
|
| 16 |
+
count: all
|
| 17 |
+
capabilities: [gpu]
|
requirements.txt
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
huggingface_hub
|
| 2 |
+
gradio-client
|
| 3 |
+
onnx
|