Spaces:
Running
on
Zero
Running
on
Zero
Update
Browse files- .pre-commit-config.yaml +2 -2
- README.md +1 -1
- app.py +101 -107
- model.py +3 -2
.pre-commit-config.yaml
CHANGED
|
@@ -21,11 +21,11 @@ repos:
|
|
| 21 |
- id: docformatter
|
| 22 |
args: ['--in-place']
|
| 23 |
- repo: https://github.com/pycqa/isort
|
| 24 |
-
rev: 5.
|
| 25 |
hooks:
|
| 26 |
- id: isort
|
| 27 |
- repo: https://github.com/pre-commit/mirrors-mypy
|
| 28 |
-
rev: v0.
|
| 29 |
hooks:
|
| 30 |
- id: mypy
|
| 31 |
args: ['--ignore-missing-imports']
|
|
|
|
| 21 |
- id: docformatter
|
| 22 |
args: ['--in-place']
|
| 23 |
- repo: https://github.com/pycqa/isort
|
| 24 |
+
rev: 5.12.0
|
| 25 |
hooks:
|
| 26 |
- id: isort
|
| 27 |
- repo: https://github.com/pre-commit/mirrors-mypy
|
| 28 |
+
rev: v0.991
|
| 29 |
hooks:
|
| 30 |
- id: mypy
|
| 31 |
args: ['--ignore-missing-imports']
|
README.md
CHANGED
|
@@ -4,7 +4,7 @@ emoji: 🏢
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
-
sdk_version: 3.
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
|
|
|
| 4 |
colorFrom: blue
|
| 5 |
colorTo: pink
|
| 6 |
sdk: gradio
|
| 7 |
+
sdk_version: 3.19.1
|
| 8 |
app_file: app.py
|
| 9 |
pinned: false
|
| 10 |
---
|
app.py
CHANGED
|
@@ -2,14 +2,14 @@
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
-
import os
|
| 6 |
-
|
| 7 |
import gradio as gr
|
| 8 |
|
| 9 |
from model import Model
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
DETAILS = '''
|
| 15 |
- To run the Semi Resolution-Dependent sampler, use the format: `<jane(number)>`.
|
|
@@ -19,112 +19,106 @@ DETAILS = '''
|
|
| 19 |
For this demo, only `<jane>`, `<gta5-artwork>` and `<cat-toy>` are available.
|
| 20 |
Also, `number` should be an integer in [0, 9].
|
| 21 |
'''
|
| 22 |
-
FOOTER = '<img id="visitor-badge" src="https://visitor-badge.glitch.me/badge?page_id=hysts.multires-textual-inversion" alt="visitor badge" />'
|
| 23 |
|
| 24 |
#CACHE_EXAMPLES = os.getenv('SYSTEM') == 'spaces'
|
| 25 |
CACHE_EXAMPLES = False
|
| 26 |
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
gr.
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
with gr.
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
)
|
| 80 |
-
with gr.Row():
|
| 81 |
-
gr.Examples(
|
| 82 |
-
label='Examples 2',
|
| 83 |
-
examples=[
|
| 84 |
-
[
|
| 85 |
-
'an image of a cat in the style of <gta5-artwork(0)>'
|
| 86 |
-
],
|
| 87 |
-
['a painting of a dog in the style of <jane(0)>'],
|
| 88 |
-
['a painting of a dog in the style of <jane(5)>'],
|
| 89 |
-
[
|
| 90 |
-
'a painting of a <cat-toy(0)> in the style of <jane(3)>'
|
| 91 |
-
],
|
| 92 |
],
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
)
|
| 98 |
-
with gr.Row():
|
| 99 |
-
gr.Examples(
|
| 100 |
-
label='Examples 3',
|
| 101 |
-
examples=[
|
| 102 |
-
['an image of <jane[0]>'],
|
| 103 |
-
['an image of <jane|0|>'],
|
| 104 |
-
['an image of <jane|3|>'],
|
| 105 |
],
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
from __future__ import annotations
|
| 4 |
|
|
|
|
|
|
|
| 5 |
import gradio as gr
|
| 6 |
|
| 7 |
from model import Model
|
| 8 |
|
| 9 |
+
DESCRIPTION = '''# Multiresolution Textual Inversion
|
| 10 |
+
|
| 11 |
+
An unofficial demo for [https://github.com/giannisdaras/multires_textual_inversion](https://github.com/giannisdaras/multires_textual_inversion).
|
| 12 |
+
'''
|
| 13 |
|
| 14 |
DETAILS = '''
|
| 15 |
- To run the Semi Resolution-Dependent sampler, use the format: `<jane(number)>`.
|
|
|
|
| 19 |
For this demo, only `<jane>`, `<gta5-artwork>` and `<cat-toy>` are available.
|
| 20 |
Also, `number` should be an integer in [0, 9].
|
| 21 |
'''
|
|
|
|
| 22 |
|
| 23 |
#CACHE_EXAMPLES = os.getenv('SYSTEM') == 'spaces'
|
| 24 |
CACHE_EXAMPLES = False
|
| 25 |
|
| 26 |
+
model = Model()
|
| 27 |
+
|
| 28 |
+
with gr.Blocks(css='style.css') as demo:
|
| 29 |
+
gr.Markdown(DESCRIPTION)
|
| 30 |
+
|
| 31 |
+
with gr.Row():
|
| 32 |
+
with gr.Group():
|
| 33 |
+
with gr.Row():
|
| 34 |
+
prompt = gr.Textbox(label='Prompt')
|
| 35 |
+
with gr.Row():
|
| 36 |
+
num_images = gr.Slider(1,
|
| 37 |
+
9,
|
| 38 |
+
value=1,
|
| 39 |
+
step=1,
|
| 40 |
+
label='Number of images')
|
| 41 |
+
with gr.Row():
|
| 42 |
+
num_steps = gr.Slider(1,
|
| 43 |
+
50,
|
| 44 |
+
value=10,
|
| 45 |
+
step=1,
|
| 46 |
+
label='Number of inference steps')
|
| 47 |
+
with gr.Row():
|
| 48 |
+
seed = gr.Slider(0, 100000, value=100, step=1, label='Seed')
|
| 49 |
+
with gr.Row():
|
| 50 |
+
run_button = gr.Button('Run')
|
| 51 |
+
|
| 52 |
+
with gr.Column():
|
| 53 |
+
result = gr.Gallery(label='Result')
|
| 54 |
+
|
| 55 |
+
with gr.Row():
|
| 56 |
+
with gr.Group():
|
| 57 |
+
fn = lambda x: model.run(x, 2, 10, 100)
|
| 58 |
+
with gr.Row():
|
| 59 |
+
gr.Examples(
|
| 60 |
+
label='Examples 1',
|
| 61 |
+
examples=[
|
| 62 |
+
['an image of <gta5-artwork(0)>'],
|
| 63 |
+
['an image of <jane(0)>'],
|
| 64 |
+
['an image of <jane(3)>'],
|
| 65 |
+
['an image of <cat-toy(0)>'],
|
| 66 |
+
],
|
| 67 |
+
inputs=prompt,
|
| 68 |
+
outputs=result,
|
| 69 |
+
fn=fn,
|
| 70 |
+
cache_examples=CACHE_EXAMPLES,
|
| 71 |
+
)
|
| 72 |
+
with gr.Row():
|
| 73 |
+
gr.Examples(
|
| 74 |
+
label='Examples 2',
|
| 75 |
+
examples=[
|
| 76 |
+
[
|
| 77 |
+
'an image of a cat in the style of <gta5-artwork(0)>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
],
|
| 79 |
+
['a painting of a dog in the style of <jane(0)>'],
|
| 80 |
+
['a painting of a dog in the style of <jane(5)>'],
|
| 81 |
+
[
|
| 82 |
+
'a painting of a <cat-toy(0)> in the style of <jane(3)>'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 83 |
],
|
| 84 |
+
],
|
| 85 |
+
inputs=prompt,
|
| 86 |
+
outputs=result,
|
| 87 |
+
fn=fn,
|
| 88 |
+
cache_examples=CACHE_EXAMPLES,
|
| 89 |
+
)
|
| 90 |
+
with gr.Row():
|
| 91 |
+
gr.Examples(
|
| 92 |
+
label='Examples 3',
|
| 93 |
+
examples=[
|
| 94 |
+
['an image of <jane[0]>'],
|
| 95 |
+
['an image of <jane|0|>'],
|
| 96 |
+
['an image of <jane|3|>'],
|
| 97 |
+
],
|
| 98 |
+
inputs=prompt,
|
| 99 |
+
outputs=result,
|
| 100 |
+
fn=fn,
|
| 101 |
+
cache_examples=CACHE_EXAMPLES,
|
| 102 |
+
)
|
| 103 |
+
|
| 104 |
+
inputs = [
|
| 105 |
+
prompt,
|
| 106 |
+
num_images,
|
| 107 |
+
num_steps,
|
| 108 |
+
seed,
|
| 109 |
+
]
|
| 110 |
+
prompt.submit(
|
| 111 |
+
fn=model.run,
|
| 112 |
+
inputs=inputs,
|
| 113 |
+
outputs=result,
|
| 114 |
+
)
|
| 115 |
+
run_button.click(
|
| 116 |
+
fn=model.run,
|
| 117 |
+
inputs=inputs,
|
| 118 |
+
outputs=result,
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
with gr.Accordion('About available prompts', open=False):
|
| 122 |
+
gr.Markdown(DETAILS)
|
| 123 |
+
|
| 124 |
+
demo.queue().launch(show_api=False)
|
model.py
CHANGED
|
@@ -1,6 +1,7 @@
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import os
|
|
|
|
| 4 |
import subprocess
|
| 5 |
import sys
|
| 6 |
|
|
@@ -10,7 +11,7 @@ from diffusers import DPMSolverMultistepScheduler
|
|
| 10 |
|
| 11 |
if os.getenv('SYSTEM') == 'spaces':
|
| 12 |
with open('patch') as f:
|
| 13 |
-
subprocess.run('patch -p1'
|
| 14 |
cwd='multires_textual_inversion',
|
| 15 |
stdin=f)
|
| 16 |
|
|
@@ -18,7 +19,7 @@ sys.path.insert(0, 'multires_textual_inversion')
|
|
| 18 |
|
| 19 |
from pipeline import MultiResPipeline, load_learned_concepts
|
| 20 |
|
| 21 |
-
HF_TOKEN = os.
|
| 22 |
|
| 23 |
|
| 24 |
class Model:
|
|
|
|
| 1 |
from __future__ import annotations
|
| 2 |
|
| 3 |
import os
|
| 4 |
+
import shlex
|
| 5 |
import subprocess
|
| 6 |
import sys
|
| 7 |
|
|
|
|
| 11 |
|
| 12 |
if os.getenv('SYSTEM') == 'spaces':
|
| 13 |
with open('patch') as f:
|
| 14 |
+
subprocess.run(shlex.split('patch -p1'),
|
| 15 |
cwd='multires_textual_inversion',
|
| 16 |
stdin=f)
|
| 17 |
|
|
|
|
| 19 |
|
| 20 |
from pipeline import MultiResPipeline, load_learned_concepts
|
| 21 |
|
| 22 |
+
HF_TOKEN = os.getenv('HF_TOKEN')
|
| 23 |
|
| 24 |
|
| 25 |
class Model:
|