Boka73 commited on
Commit
5ea150a
·
verified ·
1 Parent(s): a65b333

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +84 -4
app.py CHANGED
@@ -1,7 +1,87 @@
1
  import gradio as gr
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
 
 
 
 
 
5
 
6
- demo = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import gradio as gr
2
 
3
+ import argparse
4
+ import glob
5
+ import os
6
+ import shutil
7
+ import site
8
+ import subprocess
9
+ import sys
10
 
11
+
12
+ script_dir = os.getcwd()
13
+
14
+
15
+ def run_cmd(cmd, capture_output=False, env=None):
16
+ # Run shell commands
17
+ return subprocess.run(cmd, shell=True, capture_output=capture_output, env=env)
18
+
19
+
20
+ def check_env():
21
+ # If we have access to conda, we are probably in an environment
22
+ conda_not_exist = run_cmd("conda", capture_output=True).returncode
23
+ if conda_not_exist:
24
+ print("Conda is not installed. Exiting...")
25
+ sys.exit()
26
+
27
+ # Ensure this is a new environment and not the base environment
28
+ if os.environ["CONDA_DEFAULT_ENV"] == "base":
29
+ print("Create an environment for this project and activate it. Exiting...")
30
+ sys.exit()
31
+
32
+
33
+ def install_dependencies():
34
+ global MY_PATH
35
+
36
+ # Install Git and clone repo
37
+ run_cmd("conda install -y -k git")
38
+ run_cmd("git clone https://codeberg.org/roop-unleashed/roop-unleashed.git")
39
+ os.chdir(MY_PATH)
40
+ run_cmd("git checkout main")
41
+ # Installs dependencies from requirements.txt
42
+ run_cmd("python -m pip install -r requirements.txt")
43
+
44
+
45
+ def update_dependencies():
46
+ global MY_PATH
47
+
48
+ os.chdir(MY_PATH)
49
+ # do a hard reset for to update even if there are local changes
50
+ run_cmd("git fetch --all")
51
+ run_cmd("git reset --hard origin/main")
52
+ run_cmd("git pull")
53
+ # Installs/Updates dependencies from all requirements.txt
54
+ run_cmd("python -m pip install -r requirements.txt")
55
+
56
+
57
+ def start_app():
58
+ global MY_PATH
59
+
60
+ os.chdir(MY_PATH)
61
+ # forward commandline arguments
62
+ sys.argv.pop(0)
63
+ args = " ".join(sys.argv)
64
+ print("Launching App")
65
+ run_cmd(f"python run.py {args}")
66
+
67
+
68
+ if __name__ == "__main__":
69
+ global MY_PATH
70
+
71
+ MY_PATH = "roop-unleashed"
72
+
73
+ # Verifies we are in a conda environment
74
+ check_env()
75
+
76
+ # If webui has already been installed, skip and run
77
+ if not os.path.exists(MY_PATH):
78
+ install_dependencies()
79
+ else:
80
+ # moved update from batch to here, because of batch limitations
81
+ updatechoice = input("Check for Updates? [y/n]").lower()
82
+ if updatechoice == "y":
83
+ update_dependencies()
84
+
85
+ # Run the model with webui
86
+ os.chdir(script_dir)
87
+ start_app()