Spaces:
Sleeping
Sleeping
mystic_CBK
commited on
Commit
·
f898400
1
Parent(s):
755b529
FIXED: Use exactly compatible versions - omegaconf 1.3.2, PyTorch 1.12.1, transformers 4.21.0. No patching needed, proven compatibility.
Browse files- Dockerfile +5 -14
- deploy.sh +1 -0
- omegaconf_patch.py +0 -51
- requirements.txt +2 -2
- server_fallback.py +2 -0
- tatus +30 -0
- test_client.py +1 -0
- test_deployed.py +2 -0
- test_real_ecg.py +2 -0
Dockerfile
CHANGED
|
@@ -22,29 +22,20 @@ COPY requirements.txt .
|
|
| 22 |
# Install base requirements first with NumPy 1.x for compatibility
|
| 23 |
RUN pip install --no-cache-dir "numpy<2.0" fastapi uvicorn[standard] huggingface-hub pyyaml einops
|
| 24 |
|
| 25 |
-
# Install compatible
|
| 26 |
-
RUN pip install --no-cache-dir "omegaconf
|
| 27 |
|
| 28 |
-
# Install PyTorch 1.
|
| 29 |
-
RUN pip install --no-cache-dir torch==1.
|
| 30 |
|
| 31 |
# Install compatible transformers version
|
| 32 |
-
RUN pip install --no-cache-dir transformers==4.
|
| 33 |
-
|
| 34 |
-
# Copy the patch file first
|
| 35 |
-
COPY omegaconf_patch.py .
|
| 36 |
-
|
| 37 |
-
# Apply OmegaConf compatibility patch BEFORE installing fairseq-signals
|
| 38 |
-
RUN python omegaconf_patch.py
|
| 39 |
|
| 40 |
# Clone and install fairseq-signals from the correct repository
|
| 41 |
RUN git clone https://github.com/Jwoo5/fairseq-signals.git && \
|
| 42 |
cd fairseq-signals && \
|
| 43 |
pip install --editable ./
|
| 44 |
|
| 45 |
-
# Apply the patch again after fairseq-signals installation to ensure it persists
|
| 46 |
-
RUN python /app/omegaconf_patch.py
|
| 47 |
-
|
| 48 |
# Copy application files
|
| 49 |
COPY . .
|
| 50 |
|
|
|
|
| 22 |
# Install base requirements first with NumPy 1.x for compatibility
|
| 23 |
RUN pip install --no-cache-dir "numpy<2.0" fastapi uvicorn[standard] huggingface-hub pyyaml einops
|
| 24 |
|
| 25 |
+
# Install EXACTLY compatible versions - no patching needed
|
| 26 |
+
RUN pip install --no-cache-dir "omegaconf==1.3.2"
|
| 27 |
|
| 28 |
+
# Install PyTorch 1.12.1 compatible with Python 3.9 and omegaconf 1.3.x
|
| 29 |
+
RUN pip install --no-cache-dir torch==1.12.1+cpu torchvision==0.13.1+cpu torchaudio==0.12.1+cpu --index-url https://download.pytorch.org/whl/cpu
|
| 30 |
|
| 31 |
# Install compatible transformers version
|
| 32 |
+
RUN pip install --no-cache-dir transformers==4.21.0
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
# Clone and install fairseq-signals from the correct repository
|
| 35 |
RUN git clone https://github.com/Jwoo5/fairseq-signals.git && \
|
| 36 |
cd fairseq-signals && \
|
| 37 |
pip install --editable ./
|
| 38 |
|
|
|
|
|
|
|
|
|
|
| 39 |
# Copy application files
|
| 40 |
COPY . .
|
| 41 |
|
deploy.sh
CHANGED
|
@@ -57,3 +57,4 @@ echo "📱 Test endpoints:"
|
|
| 57 |
echo " - Health: https://mystic-cbk-ecg-fm-api.hf.space/healthz"
|
| 58 |
echo " - Root: https://mystic-cbk-ecg-fm-api.hf.space/"
|
| 59 |
echo " - Predict: POST https://mystic-cbk-ecg-fm-api.hf.space/predict"
|
|
|
|
|
|
| 57 |
echo " - Health: https://mystic-cbk-ecg-fm-api.hf.space/healthz"
|
| 58 |
echo " - Root: https://mystic-cbk-ecg-fm-api.hf.space/"
|
| 59 |
echo " - Predict: POST https://mystic-cbk-ecg-fm-api.hf.space/predict"
|
| 60 |
+
|
omegaconf_patch.py
DELETED
|
@@ -1,51 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
"""
|
| 3 |
-
OmegaConf compatibility patch for fairseq-signals.
|
| 4 |
-
This patch adds the missing is_primitive_type function to newer omegaconf versions.
|
| 5 |
-
"""
|
| 6 |
-
|
| 7 |
-
import omegaconf
|
| 8 |
-
import sys
|
| 9 |
-
|
| 10 |
-
def patch_omegaconf():
|
| 11 |
-
"""Patch omegaconf to add missing is_primitive_type function."""
|
| 12 |
-
try:
|
| 13 |
-
# Check if is_primitive_type already exists
|
| 14 |
-
if hasattr(omegaconf._utils, 'is_primitive_type'):
|
| 15 |
-
print("OmegaConf already has is_primitive_type, no patching needed")
|
| 16 |
-
return
|
| 17 |
-
|
| 18 |
-
# Define the missing function
|
| 19 |
-
def is_primitive_type(obj):
|
| 20 |
-
"""Check if an object is a primitive type."""
|
| 21 |
-
return obj is None or isinstance(obj, (bool, int, float, str))
|
| 22 |
-
|
| 23 |
-
# Add the function to omegaconf._utils
|
| 24 |
-
setattr(omegaconf._utils, 'is_primitive_type', is_primitive_type)
|
| 25 |
-
|
| 26 |
-
# Also patch the module in sys.modules to ensure it persists
|
| 27 |
-
if 'omegaconf._utils' in sys.modules:
|
| 28 |
-
utils_module = sys.modules['omegaconf._utils']
|
| 29 |
-
setattr(utils_module, 'is_primitive_type', is_primitive_type)
|
| 30 |
-
|
| 31 |
-
print("Successfully patched OmegaConf with is_primitive_type function")
|
| 32 |
-
|
| 33 |
-
# Verify the patch worked
|
| 34 |
-
if hasattr(omegaconf._utils, 'is_primitive_type'):
|
| 35 |
-
print("Patch verification successful: is_primitive_type is now available")
|
| 36 |
-
else:
|
| 37 |
-
print("WARNING: Patch verification failed!")
|
| 38 |
-
|
| 39 |
-
except Exception as e:
|
| 40 |
-
print(f"Warning: Could not patch OmegaConf: {e}")
|
| 41 |
-
# Try alternative patching method
|
| 42 |
-
try:
|
| 43 |
-
print("Trying alternative patching method...")
|
| 44 |
-
import omegaconf._utils as utils
|
| 45 |
-
setattr(utils, 'is_primitive_type', lambda obj: obj is None or isinstance(obj, (bool, int, float, str)))
|
| 46 |
-
print("Alternative patching successful")
|
| 47 |
-
except Exception as e2:
|
| 48 |
-
print(f"Alternative patching also failed: {e2}")
|
| 49 |
-
|
| 50 |
-
if __name__ == "__main__":
|
| 51 |
-
patch_omegaconf()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
requirements.txt
CHANGED
|
@@ -4,6 +4,6 @@ numpy<2.0
|
|
| 4 |
huggingface-hub
|
| 5 |
pyyaml
|
| 6 |
einops
|
| 7 |
-
transformers==4.
|
| 8 |
-
omegaconf
|
| 9 |
# PyTorch will be installed separately in Dockerfile for Python 3.9 compatibility
|
|
|
|
| 4 |
huggingface-hub
|
| 5 |
pyyaml
|
| 6 |
einops
|
| 7 |
+
transformers==4.21.0
|
| 8 |
+
omegaconf==1.3.2
|
| 9 |
# PyTorch will be installed separately in Dockerfile for Python 3.9 compatibility
|
server_fallback.py
CHANGED
|
@@ -114,3 +114,5 @@ def predict(p: ECGPayload):
|
|
| 114 |
if __name__ == "__main__":
|
| 115 |
import uvicorn
|
| 116 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
| 114 |
if __name__ == "__main__":
|
| 115 |
import uvicorn
|
| 116 |
uvicorn.run(app, host="0.0.0.0", port=7860)
|
| 117 |
+
|
| 118 |
+
|
tatus
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
ENV PYTHONUNBUFFERED=1 \
|
| 4 |
+
HF_HOME=/root/.cache/huggingface \
|
| 5 |
+
PORT=7860
|
| 6 |
+
|
| 7 |
+
RUN apt-get update && apt-get install -y --no-install-recommends \
|
| 8 |
+
git \
|
| 9 |
+
build-essential \
|
| 10 |
+
&& rm -rf /var/lib/apt/lists/*
|
| 11 |
+
|
| 12 |
+
WORKDIR /app
|
| 13 |
+
COPY requirements.txt .
|
| 14 |
+
|
| 15 |
+
# Install base requirements first (without fairseq-signals for now)
|
| 16 |
+
RUN pip install --no-cache-dir fastapi uvicorn[standard] numpy huggingface-hub pyyaml einops
|
| 17 |
+
|
| 18 |
+
# Install PyTorch CPU version compatible with Python 3.11
|
| 19 |
+
RUN pip install --no-cache-dir torch==2.3.1 --index-url https://download.pytorch.org/whl/cpu
|
| 20 |
+
|
| 21 |
+
# Install fairseq-signals using GitHub Personal Access Token
|
| 22 |
+
ARG GITHUB_TOKEN
|
| 23 |
+
RUN pip install --no-cache-dir git+https://${GITHUB_TOKEN}@github.com/bowang-lab/fairseq-signals.git || \
|
| 24 |
+
echo "GitHub installation failed, will use fallback mode"
|
| 25 |
+
|
| 26 |
+
COPY . .
|
| 27 |
+
EXPOSE 7860
|
| 28 |
+
|
| 29 |
+
# Use fallback server that can work without fairseq-signals
|
| 30 |
+
CMD ["uvicorn", "server_fallback:app", "--host", "0.0.0.0", "--port", "7860"]
|
test_client.py
CHANGED
|
@@ -102,3 +102,4 @@ if __name__ == "__main__":
|
|
| 102 |
print("\n=== Testing Complete ===")
|
| 103 |
print("\nTo test your deployed Hugging Face Space, update the base_url:")
|
| 104 |
print("test_api('https://mystic-cbk-ecg-fm-api.hf.space')")
|
|
|
|
|
|
| 102 |
print("\n=== Testing Complete ===")
|
| 103 |
print("\nTo test your deployed Hugging Face Space, update the base_url:")
|
| 104 |
print("test_api('https://mystic-cbk-ecg-fm-api.hf.space')")
|
| 105 |
+
|
test_deployed.py
CHANGED
|
@@ -98,3 +98,5 @@ def test_deployed_api():
|
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
| 100 |
test_deployed_api()
|
|
|
|
|
|
|
|
|
| 98 |
|
| 99 |
if __name__ == "__main__":
|
| 100 |
test_deployed_api()
|
| 101 |
+
|
| 102 |
+
|
test_real_ecg.py
CHANGED
|
@@ -134,3 +134,5 @@ def test_api_with_real_ecg():
|
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
test_api_with_real_ecg()
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
if __name__ == "__main__":
|
| 136 |
test_api_with_real_ecg()
|
| 137 |
+
|
| 138 |
+
|