Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
fengzch-das
nunchaku
Commits
4e668794
"tools/vscode:/vscode.git/clone" did not exist on "48b9bf3f93f47f6173e101bc81343d55eedf242d"
Commit
4e668794
authored
Nov 07, 2024
by
Muyang Li
Browse files
add use count in the demo
parent
0ffe1607
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
3 deletions
+26
-3
app/i2i/run_gradio.py
app/i2i/run_gradio.py
+11
-0
app/i2i/utils.py
app/i2i/utils.py
+1
-3
app/t2i/run_gradio.py
app/t2i/run_gradio.py
+14
-0
No files found.
app/i2i/run_gradio.py
View file @
4e668794
# Changed from https://github.com/GaParmar/img2img-turbo/blob/main/gradio_sketch2image.py
import
os
import
random
import
tempfile
import
time
...
...
@@ -73,6 +74,16 @@ def run(image, prompt: str, prompt_template: str, sketch_guidance: float, seed:
if
is_unsafe_prompt
:
latency_str
+=
" (Unsafe prompt detected)"
torch
.
cuda
.
empty_cache
()
if
args
.
count_use
:
if
os
.
path
.
exists
(
"use_count.txt"
):
with
open
(
"use_count.txt"
,
"r"
)
as
f
:
count
=
int
(
f
.
read
())
else
:
count
=
0
count
+=
1
print
(
f
"Use count:
{
count
}
"
)
with
open
(
"use_count.txt"
,
"w"
)
as
f
:
f
.
write
(
str
(
count
))
return
result_image
,
latency_str
...
...
app/i2i/utils.py
View file @
4e668794
...
...
@@ -6,13 +6,11 @@ import argparse
def
get_args
()
->
argparse
.
Namespace
:
parser
=
argparse
.
ArgumentParser
()
# parser.add_argument(
# "-m", "--model", type=str, default="pretrained/converted/sketch.safetensors", help="Path to the model"
# )
parser
.
add_argument
(
"-p"
,
"--precision"
,
type
=
str
,
default
=
"int4"
,
choices
=
[
"int4"
,
"bf16"
],
help
=
"Which precisions to use"
)
parser
.
add_argument
(
"--use-qencoder"
,
action
=
"store_true"
,
help
=
"Whether to use 4-bit text encoder"
)
parser
.
add_argument
(
"--no-safety-checker"
,
action
=
"store_true"
,
help
=
"Disable safety checker"
)
parser
.
add_argument
(
"--count-use"
,
action
=
"store_true"
,
help
=
"Whether to count the number of uses"
)
args
=
parser
.
parse_args
()
return
args
app/t2i/run_gradio.py
View file @
4e668794
# Changed from https://huggingface.co/spaces/playgroundai/playground-v2.5/blob/main/app.py
import
argparse
import
os
import
random
import
time
...
...
@@ -30,6 +31,7 @@ def get_args() -> argparse.Namespace:
)
parser
.
add_argument
(
"--use-qencoder"
,
action
=
"store_true"
,
help
=
"Whether to use 4-bit text encoder"
)
parser
.
add_argument
(
"--no-safety-checker"
,
action
=
"store_true"
,
help
=
"Disable safety checker"
)
parser
.
add_argument
(
"--count-use"
,
action
=
"store_true"
,
help
=
"Whether to count the number of uses"
)
return
parser
.
parse_args
()
...
...
@@ -124,6 +126,18 @@ def generate(
for
i
in
range
(
len
(
latency_strs
)):
latency_strs
[
i
]
+=
" (Unsafe prompt detected)"
torch
.
cuda
.
empty_cache
()
if
args
.
count_use
:
if
os
.
path
.
exists
(
"use_count.txt"
):
with
open
(
"use_count.txt"
,
"r"
)
as
f
:
count
=
int
(
f
.
read
())
else
:
count
=
0
count
+=
1
print
(
f
"Use count:
{
count
}
"
)
with
open
(
"use_count.txt"
,
"w"
)
as
f
:
f
.
write
(
str
(
count
))
return
*
images
,
*
latency_strs
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment