smas7832 commited on
Commit
36dbd75
·
verified ·
1 Parent(s): bb4817c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +126 -5
app.py CHANGED
@@ -1,7 +1,128 @@
1
- import gradio as gr
 
 
2
 
3
- def greet(name):
4
- return "Hello " + name + "!!"
5
 
6
- iface = gr.Interface(fn=greet, inputs="text", outputs="text")
7
- iface.launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import sys
3
+ import ssl
4
 
5
+ print('[System ARGV] ' + str(sys.argv))
 
6
 
7
+ root = os.path.dirname(os.path.abspath(__file__))
8
+ sys.path.append(root)
9
+ os.chdir(root)
10
+
11
+ os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
12
+ os.environ["PYTORCH_MPS_HIGH_WATERMARK_RATIO"] = "0.0"
13
+ if "GRADIO_SERVER_PORT" not in os.environ:
14
+ os.environ["GRADIO_SERVER_PORT"] = "7865"
15
+
16
+ ssl._create_default_https_context = ssl._create_unverified_context
17
+
18
+
19
+ import platform
20
+ import fooocus_version
21
+
22
+ from build_launcher import build_launcher
23
+ from modules.launch_util import is_installed, run, python, run_pip, requirements_met
24
+ from modules.model_loader import load_file_from_url
25
+
26
+
27
+ REINSTALL_ALL = False
28
+ TRY_INSTALL_XFORMERS = False
29
+
30
+
31
+ def prepare_environment():
32
+ torch_index_url = os.environ.get('TORCH_INDEX_URL', "https://download.pytorch.org/whl/cu121")
33
+ torch_command = os.environ.get('TORCH_COMMAND',
34
+ f"pip install torch==2.1.0 torchvision==0.16.0 --extra-index-url {torch_index_url}")
35
+ requirements_file = os.environ.get('REQS_FILE', "requirements_versions.txt")
36
+
37
+ print(f"Python {sys.version}")
38
+ print(f"Fooocus version: {fooocus_version.version}")
39
+
40
+ if REINSTALL_ALL or not is_installed("torch") or not is_installed("torchvision"):
41
+ run(f'"{python}" -m {torch_command}', "Installing torch and torchvision", "Couldn't install torch", live=True)
42
+
43
+ if TRY_INSTALL_XFORMERS:
44
+ if REINSTALL_ALL or not is_installed("xformers"):
45
+ xformers_package = os.environ.get('XFORMERS_PACKAGE', 'xformers==0.0.20')
46
+ if platform.system() == "Windows":
47
+ if platform.python_version().startswith("3.10"):
48
+ run_pip(f"install -U -I --no-deps {xformers_package}", "xformers", live=True)
49
+ else:
50
+ print("Installation of xformers is not supported in this version of Python.")
51
+ print(
52
+ "You can also check this and build manually: https://github.com/AUTOMATIC1111/stable-diffusion-webui/wiki/Xformers#building-xformers-on-windows-by-duckness")
53
+ if not is_installed("xformers"):
54
+ exit(0)
55
+ elif platform.system() == "Linux":
56
+ run_pip(f"install -U -I --no-deps {xformers_package}", "xformers")
57
+
58
+ if REINSTALL_ALL or not requirements_met(requirements_file):
59
+ run_pip(f"install -r \"{requirements_file}\"", "requirements")
60
+
61
+ return
62
+
63
+
64
+ vae_approx_filenames = [
65
+ ('xlvaeapp.pth', 'https://huggingface.co/lllyasviel/misc/resolve/main/xlvaeapp.pth'),
66
+ ('vaeapp_sd15.pth', 'https://huggingface.co/lllyasviel/misc/resolve/main/vaeapp_sd15.pt'),
67
+ ('xl-to-v1_interposer-v3.1.safetensors',
68
+ 'https://huggingface.co/lllyasviel/misc/resolve/main/xl-to-v1_interposer-v3.1.safetensors')
69
+ ]
70
+
71
+
72
+ def ini_args():
73
+ from args_manager import args
74
+ return args
75
+
76
+
77
+ prepare_environment()
78
+ build_launcher()
79
+ args = ini_args()
80
+
81
+
82
+ if args.gpu_device_id is not None:
83
+ os.environ['CUDA_VISIBLE_DEVICES'] = str(args.gpu_device_id)
84
+ print("Set device to:", args.gpu_device_id)
85
+
86
+
87
+ from modules import config
88
+
89
+ def download_models():
90
+ for file_name, url in vae_approx_filenames:
91
+ load_file_from_url(url=url, model_dir=config.path_vae_approx, file_name=file_name)
92
+
93
+ load_file_from_url(
94
+ url='https://huggingface.co/lllyasviel/misc/resolve/main/fooocus_expansion.bin',
95
+ model_dir=config.path_fooocus_expansion,
96
+ file_name='pytorch_model.bin'
97
+ )
98
+
99
+ if args.disable_preset_download:
100
+ print('Skipped model download.')
101
+ return
102
+
103
+ if not args.always_download_new_model:
104
+ if not os.path.exists(os.path.join(config.path_checkpoints, config.default_base_model_name)):
105
+ for alternative_model_name in config.previous_default_models:
106
+ if os.path.exists(os.path.join(config.path_checkpoints, alternative_model_name)):
107
+ print(f'You do not have [{config.default_base_model_name}] but you have [{alternative_model_name}].')
108
+ print(f'Fooocus will use [{alternative_model_name}] to avoid downloading new models, '
109
+ f'but you are not using latest models.')
110
+ print('Use --always-download-new-model to avoid fallback and always get new models.')
111
+ config.checkpoint_downloads = {}
112
+ config.default_base_model_name = alternative_model_name
113
+ break
114
+
115
+ for file_name, url in config.checkpoint_downloads.items():
116
+ load_file_from_url(url=url, model_dir=config.path_checkpoints, file_name=file_name)
117
+ for file_name, url in config.embeddings_downloads.items():
118
+ load_file_from_url(url=url, model_dir=config.path_embeddings, file_name=file_name)
119
+ for file_name, url in config.lora_downloads.items():
120
+ load_file_from_url(url=url, model_dir=config.path_loras, file_name=file_name)
121
+
122
+ return
123
+
124
+
125
+ download_models()
126
+
127
+
128
+ from webui import *