lolout1 commited on
Commit
8332d88
·
1 Parent(s): c33c883

added new files to help conflicts

Browse files
Files changed (6) hide show
  1. .dockerignore +6 -0
  2. Dockerfile +22 -14
  3. app.py +80 -27
  4. install.py +19 -0
  5. pre_install.py +52 -0
  6. setup.sh +22 -0
.dockerignore ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ __pycache__
2
+ *.pyc
3
+ *.pyo
4
+ *.pyd
5
+ .git
6
+ .gitignore
Dockerfile CHANGED
@@ -22,39 +22,47 @@ RUN useradd -m -u 1000 user
22
 
23
  WORKDIR /app
24
 
25
- # Upgrade pip
26
- RUN pip install --upgrade pip setuptools wheel
 
27
 
28
- # Install PyTorch and dependencies in the correct order
29
- RUN pip install sympy filelock jinja2 networkx requests typing-extensions
30
  RUN pip install torch==2.0.1+cpu torchvision==0.15.2+cpu --index-url https://download.pytorch.org/whl/cpu
 
31
 
32
- # Force specific numpy/pillow versions AFTER torch installation
33
- RUN pip uninstall -y numpy pillow && \
34
- pip install numpy==1.24.3 pillow==10.0.0
35
 
36
- # Install COCO API and other dependencies needed by detectron2
37
- RUN pip install pycocotools opencv-python scipy matplotlib
38
-
39
- # Clone and install detectron2 from source
40
  RUN git clone https://github.com/facebookresearch/detectron2.git /tmp/detectron2 && \
41
  cd /tmp/detectron2 && \
42
  git checkout v0.6 && \
43
- pip install -e .
 
 
 
 
 
 
 
 
 
44
 
45
- # Install additional dependencies
46
  RUN pip install \
47
  gradio \
48
  huggingface_hub \
 
49
  scikit-learn \
50
  scikit-image \
 
51
  tqdm
52
 
53
  # Switch to user
54
  USER user
55
  ENV HOME=/home/user PATH=/home/user/.local/bin:$PATH
56
 
57
- # Copy application files
58
  COPY --chown=user:user . /app
59
 
60
  # Install remaining requirements as user
 
22
 
23
  WORKDIR /app
24
 
25
+ # CRITICAL: Downgrade setuptools to avoid the deprecated warnings
26
+ RUN pip install --upgrade pip
27
+ RUN pip install setuptools==69.5.1 wheel
28
 
29
+ # Install PyTorch and core dependencies
 
30
  RUN pip install torch==2.0.1+cpu torchvision==0.15.2+cpu --index-url https://download.pytorch.org/whl/cpu
31
+ RUN pip install numpy==1.24.3 pillow==10.0.0
32
 
33
+ # Install COCO API first (required by detectron2)
34
+ RUN pip install pycocotools opencv-python
 
35
 
36
+ # Method 1: Install detectron2 without editable mode and without build isolation
 
 
 
37
  RUN git clone https://github.com/facebookresearch/detectron2.git /tmp/detectron2 && \
38
  cd /tmp/detectron2 && \
39
  git checkout v0.6 && \
40
+ pip install --no-build-isolation --no-deps . && \
41
+ pip install -r requirements.txt
42
+
43
+ # Alternative Method 2: Build wheel first
44
+ # RUN git clone https://github.com/facebookresearch/detectron2.git /tmp/detectron2 && \
45
+ # cd /tmp/detectron2 && \
46
+ # git checkout v0.6 && \
47
+ # python setup.py bdist_wheel && \
48
+ # pip install dist/*.whl && \
49
+ # pip install -r requirements.txt
50
 
51
+ # Install other dependencies
52
  RUN pip install \
53
  gradio \
54
  huggingface_hub \
55
+ scipy \
56
  scikit-learn \
57
  scikit-image \
58
+ matplotlib \
59
  tqdm
60
 
61
  # Switch to user
62
  USER user
63
  ENV HOME=/home/user PATH=/home/user/.local/bin:$PATH
64
 
65
+ # Copy application
66
  COPY --chown=user:user . /app
67
 
68
  # Install remaining requirements as user
app.py CHANGED
@@ -1,38 +1,91 @@
1
  #!/usr/bin/env python3
2
  """
3
- Minimal OneFormer Demo for HuggingFace Spaces
4
  """
5
 
6
  import os
7
- os.environ['CUDA_VISIBLE_DEVICES'] = ''
8
-
9
- import gradio as gr
10
- import torch
11
- import numpy as np
12
- from PIL import Image
13
 
14
- # Force CPU
15
- device = torch.device("cpu")
 
16
 
17
- def process_image(image):
18
- """Simple image processing function"""
19
- if image is None:
20
- return None
 
 
 
21
 
22
- # For now, just return the image with a message
23
- # Replace this with actual OneFormer inference
24
- return image
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
 
26
- # Create simple interface
27
- iface = gr.Interface(
28
- fn=process_image,
29
- inputs=gr.Image(type="numpy"),
30
- outputs=gr.Image(type="numpy"),
31
- title="OneFormer Demo",
32
- description="OneFormer: Universal Image Segmentation (CPU Mode)",
33
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
34
 
35
  if __name__ == "__main__":
36
- print(f"PyTorch version: {torch.__version__}")
37
- print(f"Running on: CPU")
38
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
1
  #!/usr/bin/env python3
2
  """
3
+ NeuroNest Hugging Face Spaces App with Robust Detectron2 Support
4
  """
5
 
6
  import os
7
+ import sys
8
+ import subprocess
 
 
 
 
9
 
10
+ # Force CPU mode
11
+ os.environ['CUDA_VISIBLE_DEVICES'] = ''
12
+ os.environ['FORCE_CUDA'] = '0'
13
 
14
+ def ensure_detectron2():
15
+ """Ensure detectron2 is installed with multiple fallback methods"""
16
+ try:
17
+ import detectron2
18
+ return True
19
+ except ImportError:
20
+ print("Detectron2 not found, attempting installation...")
21
 
22
+ # Method 1: Install from GitHub with no build isolation
23
+ try:
24
+ subprocess.run([
25
+ sys.executable, "-m", "pip", "install",
26
+ "--no-build-isolation",
27
+ "git+https://github.com/facebookresearch/detectron2.git@v0.6"
28
+ ], check=True)
29
+ import detectron2
30
+ return True
31
+ except:
32
+ pass
33
+
34
+ # Method 2: Clone and build
35
+ try:
36
+ import tempfile
37
+ with tempfile.TemporaryDirectory() as tmpdir:
38
+ subprocess.run([
39
+ "git", "clone", "--depth", "1", "--branch", "v0.6",
40
+ "https://github.com/facebookresearch/detectron2.git",
41
+ f"{tmpdir}/detectron2"
42
+ ], check=True)
43
+
44
+ subprocess.run([
45
+ sys.executable, "-m", "pip", "install",
46
+ "--no-build-isolation", f"{tmpdir}/detectron2"
47
+ ], check=True)
48
+
49
+ import detectron2
50
+ return True
51
+ except:
52
+ return False
53
 
54
+ def main():
55
+ # Ensure detectron2 is available
56
+ if not ensure_detectron2():
57
+ print("WARNING: Could not install detectron2, running in limited mode")
58
+
59
+ # Run minimal version without detectron2
60
+ import gradio as gr
61
+
62
+ def minimal_interface(image):
63
+ return "Detectron2 not available. Please check deployment logs."
64
+
65
+ demo = gr.Interface(
66
+ fn=minimal_interface,
67
+ inputs=gr.Image(type="filepath"),
68
+ outputs="text",
69
+ title="NeuroNest - Limited Mode"
70
+ )
71
+ demo.launch(server_name="0.0.0.0", server_port=7860)
72
+ return
73
+
74
+ # Normal operation with detectron2
75
+ try:
76
+ from gradio_test import create_gradio_interface
77
+
78
+ print("Starting NeuroNest application...")
79
+ interface = create_gradio_interface()
80
+ interface.launch(
81
+ server_name="0.0.0.0",
82
+ server_port=7860,
83
+ share=False
84
+ )
85
+ except Exception as e:
86
+ print(f"Error: {e}")
87
+ import traceback
88
+ traceback.print_exc()
89
 
90
  if __name__ == "__main__":
91
+ main()
 
 
install.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import subprocess
2
+ import sys
3
+ import os
4
+
5
+ # Install torch first
6
+ subprocess.check_call([sys.executable, "-m", "pip", "install", "torch>=2.0.0", "torchvision>=0.15.0"])
7
+
8
+ # Clone and install detectron2
9
+ if not os.path.exists('detectron2'):
10
+ subprocess.check_call(["git", "clone", "https://github.com/facebookresearch/detectron2"])
11
+
12
+ # Install detectron2 dependencies
13
+ import distutils.core
14
+ dist = distutils.core.run_setup("./detectron2/setup.py")
15
+ deps = ' '.join([f"'{x}'" for x in dist.install_requires if 'torch' not in x])
16
+ subprocess.check_call(f"{sys.executable} -m pip install {deps}", shell=True)
17
+
18
+ # Add detectron2 to path
19
+ sys.path.insert(0, os.path.abspath('./detectron2'))
pre_install.py ADDED
@@ -0,0 +1,52 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """
3
+ Pre-installation setup for Hugging Face Spaces
4
+ Run this before main app to ensure detectron2 is properly installed
5
+ """
6
+
7
+ import subprocess
8
+ import sys
9
+ import os
10
+
11
+ # Downgrade setuptools first
12
+ subprocess.run([sys.executable, "-m", "pip", "install", "setuptools==69.5.1"], check=True)
13
+
14
+ # Set environment variables
15
+ os.environ['CUDA_VISIBLE_DEVICES'] = ''
16
+ os.environ['FORCE_CUDA'] = '0'
17
+
18
+ # Install torch first
19
+ subprocess.run([
20
+ sys.executable, "-m", "pip", "install",
21
+ "torch==2.0.1+cpu", "torchvision==0.15.2+cpu",
22
+ "--index-url", "https://download.pytorch.org/whl/cpu"
23
+ ], check=True)
24
+
25
+ # Install detectron2 dependencies
26
+ subprocess.run([
27
+ sys.executable, "-m", "pip", "install",
28
+ "numpy==1.24.3", "pillow==10.0.0", "pycocotools", "opencv-python"
29
+ ], check=True)
30
+
31
+ # Clone and install detectron2
32
+ import tempfile
33
+ import shutil
34
+
35
+ with tempfile.TemporaryDirectory() as tmpdir:
36
+ # Clone repo
37
+ subprocess.run([
38
+ "git", "clone", "https://github.com/facebookresearch/detectron2.git",
39
+ os.path.join(tmpdir, "detectron2")
40
+ ], check=True)
41
+
42
+ # Checkout stable version
43
+ os.chdir(os.path.join(tmpdir, "detectron2"))
44
+ subprocess.run(["git", "checkout", "v0.6"], check=True)
45
+
46
+ # Install without build isolation
47
+ subprocess.run([
48
+ sys.executable, "-m", "pip", "install",
49
+ "--no-build-isolation", "."
50
+ ], check=True)
51
+
52
+ print("Pre-installation complete!")
setup.sh ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/bin/bash
2
+ # Setup script for Hugging Face Spaces
3
+
4
+ # Install system dependencies
5
+ apt-get update && apt-get install -y git build-essential
6
+
7
+ # Downgrade setuptools
8
+ pip install setuptools==69.5.1
9
+
10
+ # Install PyTorch
11
+ pip install torch==2.0.1+cpu torchvision==0.15.2+cpu --index-url https://download.pytorch.org/whl/cpu
12
+
13
+ # Install detectron2 from source
14
+ git clone https://github.com/facebookresearch/detectron2.git
15
+ cd detectron2
16
+ git checkout v0.6
17
+ pip install --no-build-isolation .
18
+ cd ..
19
+ rm -rf detectron2
20
+
21
+ # Install other requirements
22
+ pip install -r requirements.txt