Spaces:
Running
Running
Commit
·
7d06eb5
1
Parent(s):
3d1859b
update
Browse files
app.py
CHANGED
@@ -0,0 +1,80 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
import gradio as gr
|
4 |
+
import torch
|
5 |
+
|
6 |
+
import sys
|
7 |
+
pyt_version_str=torch.__version__.split("+")[0].replace(".", "")
|
8 |
+
version_str="".join([
|
9 |
+
f"py3{sys.version_info.minor}_cu",
|
10 |
+
torch.version.cuda.replace(".",""),
|
11 |
+
f"_pyt{pyt_version_str}"
|
12 |
+
])
|
13 |
+
print(f"Using version: {version_str}") # used to locate pytorch3d version in the requirements.txt for huggingface
|
14 |
+
|
15 |
+
|
16 |
+
from app_canny import create_demo as create_demo_canny
|
17 |
+
from app_texnet import create_demo as create_demo_texnet
|
18 |
+
|
19 |
+
from model import Model
|
20 |
+
from settings import ALLOW_CHANGING_BASE_MODEL, DEFAULT_MODEL_ID, SHOW_DUPLICATE_BUTTON
|
21 |
+
|
22 |
+
DESCRIPTION = "# Material Authoring Demo v0.3"
|
23 |
+
|
24 |
+
if not torch.cuda.is_available():
|
25 |
+
DESCRIPTION += "\n<p>Running on CPU 🥶 This demo does not work on CPU.</p> Check if the 'CUDA_VISIBLE_DEVICES' are set incorrectly in settings.py"
|
26 |
+
|
27 |
+
# model = Model(base_model_id=DEFAULT_MODEL_ID, task_name="Canny")
|
28 |
+
model = Model(base_model_id=DEFAULT_MODEL_ID, task_name="texnet")
|
29 |
+
|
30 |
+
with gr.Blocks() as demo:
|
31 |
+
gr.Markdown(DESCRIPTION)
|
32 |
+
gr.DuplicateButton(
|
33 |
+
value="Duplicate Space for private use",
|
34 |
+
elem_id="duplicate-button",
|
35 |
+
visible=SHOW_DUPLICATE_BUTTON,
|
36 |
+
)
|
37 |
+
|
38 |
+
with gr.Tabs():
|
39 |
+
with gr.Tab("Texnet+Matnet"):
|
40 |
+
create_demo_texnet(model.process_texnet)
|
41 |
+
|
42 |
+
with gr.Accordion(label="Base model", open=False):
|
43 |
+
with gr.Row():
|
44 |
+
with gr.Column(scale=5):
|
45 |
+
current_base_model = gr.Text(label="Current base model")
|
46 |
+
with gr.Column(scale=1):
|
47 |
+
check_base_model_button = gr.Button("Check current base model")
|
48 |
+
with gr.Row():
|
49 |
+
with gr.Column(scale=5):
|
50 |
+
new_base_model_id = gr.Text(
|
51 |
+
label="New base model",
|
52 |
+
max_lines=1,
|
53 |
+
placeholder="stable-diffusion-v1-5/stable-diffusion-v1-5",
|
54 |
+
info="The base model must be compatible with Stable Diffusion v1.5.",
|
55 |
+
interactive=ALLOW_CHANGING_BASE_MODEL,
|
56 |
+
)
|
57 |
+
with gr.Column(scale=1):
|
58 |
+
change_base_model_button = gr.Button("Change base model", interactive=ALLOW_CHANGING_BASE_MODEL)
|
59 |
+
if not ALLOW_CHANGING_BASE_MODEL:
|
60 |
+
gr.Markdown(
|
61 |
+
"""The base model is not allowed to be changed in this Space so as not to slow down the demo, but it can be changed if you duplicate the Space."""
|
62 |
+
)
|
63 |
+
|
64 |
+
check_base_model_button.click(
|
65 |
+
fn=lambda: model.base_model_id,
|
66 |
+
outputs=current_base_model,
|
67 |
+
queue=False,
|
68 |
+
api_name="check_base_model",
|
69 |
+
)
|
70 |
+
gr.on(
|
71 |
+
triggers=[new_base_model_id.submit, change_base_model_button.click],
|
72 |
+
fn=model.set_base_model,
|
73 |
+
inputs=new_base_model_id,
|
74 |
+
outputs=current_base_model,
|
75 |
+
api_name=False,
|
76 |
+
concurrency_id="main",
|
77 |
+
)
|
78 |
+
|
79 |
+
if __name__ == "__main__":
|
80 |
+
demo.queue(max_size=20).launch()
|