Spaces:
Runtime error
Runtime error
RamAnanth1
commited on
Commit
•
186b58d
1
Parent(s):
af6ed95
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/usr/bin/env python
|
2 |
+
|
3 |
+
from __future__ import annotations
|
4 |
+
|
5 |
+
import os
|
6 |
+
import pathlib
|
7 |
+
import shlex
|
8 |
+
import subprocess
|
9 |
+
|
10 |
+
import gradio as gr
|
11 |
+
|
12 |
+
if os.getenv('SYSTEM') == 'spaces':
|
13 |
+
with open('patch') as f:
|
14 |
+
subprocess.run(shlex.split('patch -p1'), stdin=f, cwd='T2I-Adapter')
|
15 |
+
|
16 |
+
# base_url = 'https://huggingface.co/lllyasviel/ControlNet/resolve/main/annotator/ckpts/'
|
17 |
+
# names = [
|
18 |
+
# 'body_pose_model.pth',
|
19 |
+
# 'dpt_hybrid-midas-501f0c75.pt',
|
20 |
+
# 'hand_pose_model.pth',
|
21 |
+
# 'mlsd_large_512_fp32.pth',
|
22 |
+
# 'mlsd_tiny_512_fp32.pth',
|
23 |
+
# 'network-bsds500.pth',
|
24 |
+
# 'upernet_global_small.pth',
|
25 |
+
# ]
|
26 |
+
# for name in names:
|
27 |
+
# command = f'wget https://huggingface.co/lllyasviel/ControlNet/resolve/main/annotator/ckpts/{name} -O {name}'
|
28 |
+
# out_path = pathlib.Path(f'ControlNet/annotator/ckpts/{name}')
|
29 |
+
# if out_path.exists():
|
30 |
+
# continue
|
31 |
+
# subprocess.run(shlex.split(command), cwd='ControlNet/annotator/ckpts/')
|
32 |
+
|
33 |
+
from gradio_sketch import create_demo as create_demo_sketch
|
34 |
+
from model import Model
|
35 |
+
|
36 |
+
MAX_IMAGES = 1
|
37 |
+
DESCRIPTION = '''# This is an unofficial demo for T2I-Adapter
|
38 |
+
[Paper](https://arxiv.org/abs/2302.08453) [GitHub](https://github.com/TencentARC/T2I-Adapter)
|
39 |
+
'''
|
40 |
+
if (SPACE_ID := os.getenv('SPACE_ID')) is not None:
|
41 |
+
DESCRIPTION += f'''<p>For faster inference without waiting in queue, you may duplicate the space and upgrade to GPU in settings.<br/>
|
42 |
+
<a href="https://huggingface.co/spaces/{SPACE_ID}?duplicate=true">
|
43 |
+
<img style="margin-top: 0em; margin-bottom: 0em" src="https://bit.ly/3gLdBN6" alt="Duplicate Space"></a>
|
44 |
+
<p/>
|
45 |
+
'''
|
46 |
+
|
47 |
+
model = Model()
|
48 |
+
|
49 |
+
with gr.Blocks(css='style.css') as demo:
|
50 |
+
gr.Markdown(DESCRIPTION)
|
51 |
+
with gr.Tabs():
|
52 |
+
with gr.TabItem('Sketch'):
|
53 |
+
create_demo_sketch(model.process_sketch)
|
54 |
+
|
55 |
+
|
56 |
+
demo.queue(api_open=False).launch()
|