-
Notifications
You must be signed in to change notification settings - Fork 287
Add Dockerfile and Gradio Web UI #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yt-koike
wants to merge
3
commits into
apple:main
Choose a base branch
from
yt-koike:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+124
−0
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| .dockerignore | ||
| .gitignore | ||
| *.md | ||
| Dockerfile | ||
| compose.yml | ||
| data/ | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,30 @@ | ||
| FROM nvidia/cuda:12.9.1-cudnn-devel-ubuntu24.04 | ||
|
|
||
| # Install Python 3.13 | ||
| RUN apt-get update && apt-get install -y wget software-properties-common build-essential && apt-get clean && rm -rf /var/lib/apt/lists/* | ||
| RUN add-apt-repository ppa:deadsnakes/ppa | ||
| RUN apt-get update && apt-get install -y python3.13 python3.13-venv python3.13-dev ninja-build && apt-get clean && rm -rf /var/lib/apt/lists/* | ||
|
|
||
| # Install Sharp and dependencies | ||
| RUN mkdir /app | ||
| COPY pyproject.toml requirements.txt requirements.in /app/ | ||
| COPY src/ /app/src/ | ||
| WORKDIR /app | ||
| RUN python3.13 -m venv .venv | ||
| ENV TORCH_CUDA_ARCH_LIST="8.0;8.6;8.7;8.9;9.0+PTX" | ||
| ENV FORCE_CUDA="1" | ||
| RUN .venv/bin/pip install ninja | ||
| RUN .venv/bin/pip install -r requirements.txt | ||
| RUN .venv/bin/pip install gradio | ||
| RUN ln -s /app/.venv/bin/sharp /usr/local/bin/sharp | ||
|
|
||
| # Test run to download model and check if it works | ||
| RUN wget https://apple.github.io/ml-sharp/thumbnails/Unsplash_-5wkyNA2BPc_0000-0001.jpg -O /tmp/test.jpg | ||
| RUN sharp predict -i /tmp/test.jpg -o /tmp/test | ||
| RUN rm /tmp/test.jpg /tmp/test -rf | ||
|
|
||
| # Copy other files | ||
| COPY . /app | ||
|
|
||
| # Start Gradio web server | ||
| CMD [".venv/bin/python3.13", "-u", "/app/gradio_web.py"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| services: | ||
| sharp: | ||
| build: | ||
| context: . | ||
| dockerfile: Dockerfile | ||
| volumes: | ||
| - ./data:/app/data | ||
| ports: | ||
| - "7860:7860" | ||
| deploy: | ||
| resources: | ||
| reservations: | ||
| devices: | ||
| - driver: nvidia | ||
| count: 1 | ||
| capabilities: [gpu] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,61 @@ | ||
|
|
||
| import gradio as gr | ||
| import subprocess | ||
| import os | ||
| import shutil | ||
| import time | ||
| import glob | ||
|
|
||
| def predict(image): | ||
| # Ensure data directory exists | ||
| os.makedirs("/app/data", exist_ok=True) | ||
|
|
||
| input_path = "/app/data/input.jpg" | ||
|
|
||
| # Save/Copy input image | ||
| # image provided by gradio (type='filepath') is a temp path | ||
| shutil.copy(image, input_path) | ||
|
|
||
| # Run sharp command | ||
| # sharp predict -i /app/data/input.jpg -o /app/data/output --render | ||
| cmd = [ | ||
| "sharp", "predict", | ||
| "-i", input_path, | ||
| "-o", "/app/data/output", | ||
| "--render" | ||
| ] | ||
|
|
||
| # Execute command | ||
| try: | ||
| t = time.time() | ||
| print("Sharp started") | ||
| subprocess.run(cmd, check=True, capture_output=True) | ||
| print(f"Sharp command took {round(time.time() - t, 3)} seconds") | ||
| except subprocess.CalledProcessError as e: | ||
| print(f"Error running sharp: {e}") | ||
| print(f"Stdout: {e.stdout.decode()}") | ||
| print(f"Stderr: {e.stderr.decode()}") | ||
| return None | ||
|
|
||
| # Find output videos | ||
| rgb_video = "/app/data/output/input.mp4" | ||
| depth_video = "/app/data/output/input.depth.mp4" | ||
|
|
||
| if os.path.exists(rgb_video) and os.path.exists(depth_video): | ||
| return rgb_video, depth_video | ||
| elif os.path.exists(rgb_video): | ||
| return rgb_video, None | ||
|
|
||
| return None, None | ||
|
|
||
| demo = gr.Interface( | ||
| fn=predict, | ||
| inputs=gr.Image(type="filepath", label="Input Image"), | ||
| outputs=[gr.Video(label="RGB Video"), gr.Video(label="Depth Video")], | ||
| title="Sharp 3D View Synthesis", | ||
| description="Upload an image to generate a 3D view synthesis video." | ||
| ) | ||
|
|
||
| if __name__ == "__main__": | ||
| print("Sharp Monocular View Synthesis in Less Than a Second (https://github.com/apple/ml-sharp)") | ||
| demo.launch(server_name="0.0.0.0", server_port=7860) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
docker