Spaces:
Sleeping
Sleeping
Upload 8 files
Browse files- Dockerfile +8 -4
- app.py +9 -0
- fix-dependencies.py +27 -0
- requirements.txt +1 -1
Dockerfile
CHANGED
|
@@ -13,10 +13,14 @@ USER user
|
|
| 13 |
ENV HOME=/home/user \
|
| 14 |
PATH=/home/user/.local/bin:$PATH
|
| 15 |
|
| 16 |
-
#
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
# Copy application files
|
| 22 |
COPY --chown=user:user . .
|
|
|
|
| 13 |
ENV HOME=/home/user \
|
| 14 |
PATH=/home/user/.local/bin:$PATH
|
| 15 |
|
| 16 |
+
# Copy requirements file first for better layer caching
|
| 17 |
+
COPY --chown=user:user requirements.txt .
|
| 18 |
+
|
| 19 |
+
# Install required packages from requirements.txt
|
| 20 |
+
RUN pip install --no-cache-dir --user -r requirements.txt
|
| 21 |
+
|
| 22 |
+
# Make sure python-multipart is installed
|
| 23 |
+
RUN pip install --no-cache-dir --user python-multipart>=0.0.6
|
| 24 |
|
| 25 |
# Copy application files
|
| 26 |
COPY --chown=user:user . .
|
app.py
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI, Request, HTTPException, Form
|
| 2 |
from fastapi.middleware.cors import CORSMiddleware
|
| 3 |
import numpy as np
|
|
|
|
| 1 |
+
try:
|
| 2 |
+
import multipart
|
| 3 |
+
print("python-multipart is installed: ", multipart.__version__)
|
| 4 |
+
except ImportError:
|
| 5 |
+
print("python-multipart is NOT installed. Installing now...")
|
| 6 |
+
import subprocess
|
| 7 |
+
subprocess.check_call(["pip", "install", "python-multipart"])
|
| 8 |
+
print("python-multipart has been installed")
|
| 9 |
+
|
| 10 |
from fastapi import FastAPI, Request, HTTPException, Form
|
| 11 |
from fastapi.middleware.cors import CORSMiddleware
|
| 12 |
import numpy as np
|
fix-dependencies.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
import subprocess
|
| 3 |
+
import sys
|
| 4 |
+
|
| 5 |
+
def install_package(package):
|
| 6 |
+
print(f"Installing {package}...")
|
| 7 |
+
try:
|
| 8 |
+
subprocess.check_call([sys.executable, "-m", "pip", "install", package])
|
| 9 |
+
print(f"Successfully installed {package}")
|
| 10 |
+
except Exception as e:
|
| 11 |
+
print(f"Failed to install {package}: {str(e)}")
|
| 12 |
+
|
| 13 |
+
def main():
|
| 14 |
+
print("Starting dependency fix script...")
|
| 15 |
+
|
| 16 |
+
# Install python-multipart first as it's critical
|
| 17 |
+
install_package("python-multipart>=0.0.6")
|
| 18 |
+
|
| 19 |
+
# Install other dependencies if needed
|
| 20 |
+
install_package("fastapi>=0.104.0")
|
| 21 |
+
install_package("uvicorn>=0.23.2")
|
| 22 |
+
|
| 23 |
+
print("Dependency fix completed")
|
| 24 |
+
print("Restart the Space to apply changes")
|
| 25 |
+
|
| 26 |
+
if __name__ == "__main__":
|
| 27 |
+
main()
|
requirements.txt
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
|
|
| 1 |
fastapi>=0.104.0
|
| 2 |
uvicorn>=0.23.2
|
| 3 |
scikit-learn>=1.0.0
|
| 4 |
joblib>=1.2.0
|
| 5 |
-
python-multipart>=0.0.6
|
| 6 |
numpy>=1.24.0
|
|
|
|
| 1 |
+
python-multipart>=0.0.6
|
| 2 |
fastapi>=0.104.0
|
| 3 |
uvicorn>=0.23.2
|
| 4 |
scikit-learn>=1.0.0
|
| 5 |
joblib>=1.2.0
|
|
|
|
| 6 |
numpy>=1.24.0
|