Skip to content

Commit

Permalink
added documentation and also openapi export. Removed the cuda contain…
Browse files Browse the repository at this point in the history
…er, since they still dont work properly
  • Loading branch information
Dan committed Jul 31, 2023
1 parent c7188dd commit a7ec66a
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 67 deletions.
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
.idea
models
temp
workdir
__pycache__
9 changes: 6 additions & 3 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
FROM python:3.10

ENV EXECUTION_PROVIDER=CPU
ENV TEMP_FRAME_FORMAT=png
ENV TEMP_FRAME_QUALITY=0
ENV OUTPUT_VIDEO_QUALITY=0

RUN apt-get update && apt-get install -y ffmpeg
RUN pip install --upgrade pip
#RUN git clone https://github.com/s0md3v/roop.git /roop \
RUN git clone https://github.com/danikhani/roop /roop
#RUN git clone https://github.com/s0md3v/roop.git /roop
RUN git clone https://github.com/danikhani/roop.git /roop
RUN pip install -r roop/requirements-docker.txt

CMD ["python", "/roop/run_api.py"]
CMD ["python", "/roop/api.py"]
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,16 @@ options:
```

Using the `-s/--source`, `-t/--target` and `-o/--output` argument will run the program in headless mode.
## Docker
FastAPI allows the communication with the Docker container. The OpenAPI export of endpoints are under [Openapi.json](openapi.json).


### Start and Stop the container (CPU version)
Clone the repository. Build an Image and start the container by writing
```docker-compose -f docker-compose.yml up -d```.
The container can get stopped by
```docker-compose -f docker-compose.yml down```.
The models will be saved in a docker volume. First start of the roop container might take longer, since the models will be downloaded for the first time.
## Credits

- [henryruhs](https://github.com/henryruhs): for being an irreplaceable contributor to the project
Expand Down
12 changes: 5 additions & 7 deletions run_api.py → api.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,7 @@ class RoopModel(BaseModel):
reference_face_position: Optional[int] = 0
reference_frame_number: Optional[int] = 0
similar_face_distance: Optional[float] = 0.85
temp_frame_format: Optional[Literal['png','jpg']] = 'png'
temp_frame_quality: Optional[int] = 0
output_video_encoder: Optional[Literal['libx264', 'libx265', 'libvpx-vp9', 'h264_nvenc', 'hevc_nvenc']] = 'libx264'
output_video_quality: Optional[int] = 0
max_memory: Optional[int] = 0
execution_threads: Optional[int] = suggest_execution_threads()
@app.get('/get_execution_providers')
Expand Down Expand Up @@ -58,6 +55,10 @@ async def image_file(
execution_provider_list = ['cpu']
print(execution_provider_list)

roop.globals.temp_frame_format = os.getenv('TEMP_FRAME_FORMAT')
roop.globals.temp_frame_quality = os.getenv('TEMP_FRAME_QUALITY')
roop.globals.output_video_quality = os.getenv('OUTPUT_VIDEO_QUALITY')

# setting paths
src_saving_path_complete = os.path.join(saving_path, src_file.filename)
target_saving_path_complete = os.path.join(saving_path, target_file.filename)
Expand All @@ -82,10 +83,7 @@ async def image_file(
roop.globals.reference_face_position = roop_parameters.reference_face_position
roop.globals.reference_frame_number = roop_parameters.reference_frame_number
roop.globals.similar_face_distance = roop_parameters.similar_face_distance
roop.globals.temp_frame_format = roop_parameters.temp_frame_format
roop.globals.temp_frame_quality = roop_parameters.temp_frame_quality
roop.globals.output_video_encoder = roop_parameters.output_video_encoder
roop.globals.output_video_quality = roop_parameters.output_video_quality
roop.globals.max_memory = roop_parameters.max_memory
roop.globals.execution_providers = decode_execution_providers(execution_provider_list)
roop.globals.execution_threads = roop_parameters.execution_threads
Expand All @@ -100,6 +98,6 @@ async def image_file(
if __name__ == "__main__":
if os.getenv('EXECUTION_PROVIDER') is None:
print('Env variable for execution provider is not set. Setting default to CPU.')
os.environ['EXECUTION_PROVIDER'] = 'CUDA'
os.environ['EXECUTION_PROVIDER'] = 'CPU'
print(os.getenv('EXECUTION_PROVIDER'))
uvicorn.run(app, host="0.0.0.0", port=8000)
26 changes: 0 additions & 26 deletions cuda.Dockerfile

This file was deleted.

24 changes: 0 additions & 24 deletions docker-compose.cuda.yml

This file was deleted.

8 changes: 3 additions & 5 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
version: '3.8'

services:
roopapi:
roop-api:
build:
context: .
dockerfile: Dockerfile
restart: unless-stopped
restart: always
volumes:
- roop-data:/roop
- open-nsfw:/root/.opennsfw2
ports:
- 8000:8000

volumes:
roop-data:
open-nsfw:
roop-data:
Loading

0 comments on commit a7ec66a

Please sign in to comment.