prithivMLmods commited on
Commit
5a2d3cf
·
verified ·
1 Parent(s): a2fbc30

Upload 6 files

Browse files
Files changed (6) hide show
  1. app.py +58 -0
  2. flake8.txt +3 -0
  3. gitignore.txt +4 -0
  4. mypy.ini +7 -0
  5. requirements-headless.txt +27 -0
  6. requirements.txt +27 -0
app.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # -* coding:UTF-8 -*
2
+ # !/usr/bin/env python
3
+ import numpy as np
4
+ import roop.globals
5
+ from roop.core import (
6
+ start,
7
+ decode_execution_providers,
8
+ suggest_max_memory,
9
+ suggest_execution_threads,
10
+ )
11
+ from roop.processors.frame.core import get_frame_processors_modules
12
+ from roop.utilities import normalize_output_path
13
+ from PIL import Image
14
+ import gradio as gr
15
+ import os
16
+
17
+ def swap_face(source_file, target_file):
18
+ source_image = Image.fromarray(source_file)
19
+ source_path = "input.jpg"
20
+ source_image.save(source_path, format="JPEG", quality=95)
21
+
22
+
23
+ output_path = "output.mp4"
24
+
25
+ roop.globals.source_path = source_path
26
+ roop.globals.target_path = target_file
27
+
28
+
29
+
30
+ roop.globals.output_path = normalize_output_path(
31
+ roop.globals.source_path, roop.globals.target_path, output_path
32
+ )
33
+ roop.globals.frame_processors = ["face_swapper", "face_enhancer"]
34
+ roop.globals.headless = True
35
+ roop.globals.keep_fps = True
36
+ roop.globals.keep_audio = True
37
+ roop.globals.keep_frames = False
38
+ roop.globals.many_faces = False
39
+ roop.globals.video_encoder = "libx264"
40
+ roop.globals.video_quality = 50
41
+ roop.globals.max_memory = suggest_max_memory()
42
+ roop.globals.execution_providers = decode_execution_providers(["cpu"])
43
+ roop.globals.execution_threads = suggest_execution_threads()
44
+ for frame_processor in get_frame_processors_modules(
45
+ roop.globals.frame_processors
46
+ ):
47
+ if not frame_processor.pre_check():
48
+ return
49
+
50
+ start()
51
+
52
+ return os.path.join(os.getcwd(), output_path)
53
+
54
+ app = gr.Interface(
55
+ fn=swap_face, inputs=[gr.Image(), gr.Video()], outputs=[gr.Video()], description="This model is running on CPU an might be slow. To run in gpu, contact the space owner. To suport the space owner please: https://donate.stripe.com/3csg0D0tadXU4mYcMM"
56
+ )
57
+
58
+ app.launch()
flake8.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ [flake8]
2
+ select = E3, E4, F
3
+ per-file-ignores = roop/core.py:E402,F401
gitignore.txt ADDED
@@ -0,0 +1,4 @@
 
 
 
 
 
1
+ .idea
2
+ models
3
+ temp
4
+ __pycache__
mypy.ini ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ [mypy]
2
+ check_untyped_defs = True
3
+ disallow_any_generics = True
4
+ disallow_untyped_calls = True
5
+ disallow_untyped_defs = True
6
+ ignore_missing_imports = True
7
+ strict_optional = False
requirements-headless.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu118
2
+
3
+ numpy==1.23.5
4
+ opencv-python==4.7.0.72
5
+ onnx==1.14.0
6
+ insightface==0.7.3
7
+ psutil==5.9.5
8
+ tk==0.1.0
9
+ customtkinter==5.1.3
10
+ pillow==9.5.0
11
+ torch==2.0.1+cu118; sys_platform != 'darwin'
12
+ torch==2.0.1; sys_platform == 'darwin'
13
+ torchvision==0.15.2+cu118; sys_platform != 'darwin'
14
+ torchvision==0.15.2; sys_platform == 'darwin'
15
+ onnxruntime==1.15.0; sys_platform == 'darwin' and platform_machine != 'arm64'
16
+ onnxruntime-silicon==1.13.1; sys_platform == 'darwin' and platform_machine == 'arm64'
17
+ onnxruntime-gpu==1.15.0; sys_platform != 'darwin'
18
+ tensorflow==2.13.0rc1; sys_platform == 'darwin'
19
+ tensorflow==2.12.0; sys_platform != 'darwin'
20
+ opennsfw2==0.10.2
21
+ protobuf==4.23.2
22
+ tqdm==4.65.0
23
+ gfpgan==1.3.8
24
+ gradio==3.40.1
25
+ tkinterdnd2==0.3.0; sys_platform != 'darwin' and platform_machine != 'arm64'
26
+ tkinterdnd2-universal==1.7.3; sys_platform == 'darwin' and platform_machine == 'arm64'
27
+ onnxruntime-coreml==1.13.1; python_version == '3.9' and sys_platform == 'darwin' and platform_machine != 'arm64'
requirements.txt ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ --extra-index-url https://download.pytorch.org/whl/cu118
2
+
3
+ numpy==1.23.5
4
+ opencv-python==4.7.0.72
5
+ onnx==1.14.0
6
+ insightface==0.7.3
7
+ psutil==5.9.5
8
+ tk==0.1.0
9
+ customtkinter==5.1.3
10
+ pillow==9.5.0
11
+ torch==2.0.1+cu118; sys_platform != 'darwin'
12
+ torch==2.0.1; sys_platform == 'darwin'
13
+ torchvision==0.15.2+cu118; sys_platform != 'darwin'
14
+ torchvision==0.15.2; sys_platform == 'darwin'
15
+ onnxruntime==1.15.0; sys_platform == 'darwin' and platform_machine != 'arm64'
16
+ onnxruntime-silicon==1.13.1; sys_platform == 'darwin' and platform_machine == 'arm64'
17
+ onnxruntime-gpu==1.15.0; sys_platform != 'darwin'
18
+ tensorflow==2.13.0rc1; sys_platform == 'darwin'
19
+ tensorflow==2.12.0; sys_platform != 'darwin'
20
+ opennsfw2==0.10.2
21
+ protobuf==4.23.2
22
+ tqdm==4.65.0
23
+ gfpgan==1.3.8
24
+ gradio==3.40.1
25
+ tkinterdnd2==0.3.0; sys_platform != 'darwin' and platform_machine != 'arm64'
26
+ tkinterdnd2-universal==1.7.3; sys_platform == 'darwin' and platform_machine == 'arm64'
27
+ onnxruntime-coreml==1.13.1; python_version == '3.9' and sys_platform == 'darwin' and platform_machine != 'arm64'