Spaces:
Running
Running
add cli package
Browse files- myapp/__main__.py +1 -1
- myapp/cli.py +0 -60
- myapp/cli/__init__.py +0 -0
- myapp/cli/main.py +21 -3
- myapp/{params.py → cli/params.py} +0 -0
myapp/__main__.py
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
from myapp.cli import cli
|
| 2 |
|
| 3 |
if __name__ == "__main__":
|
| 4 |
cli()
|
|
|
|
| 1 |
+
from myapp.cli.main import cli
|
| 2 |
|
| 3 |
if __name__ == "__main__":
|
| 4 |
cli()
|
myapp/cli.py
DELETED
|
@@ -1,60 +0,0 @@
|
|
| 1 |
-
import click
|
| 2 |
-
import dotenv
|
| 3 |
-
import segno
|
| 4 |
-
from huggingface_hub import InferenceClient
|
| 5 |
-
from qrcode_artistic import write_artistic
|
| 6 |
-
from segno.consts import ERROR_MAPPING
|
| 7 |
-
|
| 8 |
-
from myapp.palette import extract_color_clusters, generate_palette_image
|
| 9 |
-
from myapp.params import ImageParamType
|
| 10 |
-
|
| 11 |
-
dotenv.load_dotenv()
|
| 12 |
-
client = InferenceClient()
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
@click.group()
|
| 16 |
-
def cli():
|
| 17 |
-
pass
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
@cli.command()
|
| 21 |
-
@click.option("--prompt", required=True)
|
| 22 |
-
@click.option("--target", type=click.File("wb"), required=True)
|
| 23 |
-
@click.option("--model", default="black-forest-labs/FLUX.1-schnell")
|
| 24 |
-
@click.option("--width", default=400)
|
| 25 |
-
@click.option("--height", default=400)
|
| 26 |
-
def generate_image(prompt, target, model, width, height):
|
| 27 |
-
image = client.text_to_image(
|
| 28 |
-
prompt=prompt,
|
| 29 |
-
model=model,
|
| 30 |
-
width=width,
|
| 31 |
-
height=height,
|
| 32 |
-
)
|
| 33 |
-
|
| 34 |
-
image.save(target)
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
@cli.command()
|
| 38 |
-
@click.option("--image", type=ImageParamType(), required=True)
|
| 39 |
-
@click.option("--target", type=click.File("wb"), required=True)
|
| 40 |
-
@click.option("--n-colors", default=4)
|
| 41 |
-
@click.option("--shade", "shades", default=(0.0,), multiple=True)
|
| 42 |
-
def generate_palette(image, target, n_colors, shades):
|
| 43 |
-
k_means = extract_color_clusters(image, n_colors)
|
| 44 |
-
palette = generate_palette_image(k_means, shades=shades)
|
| 45 |
-
palette.save(target)
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
@cli.command()
|
| 49 |
-
@click.option("--text", required=True)
|
| 50 |
-
@click.option("--background", type=click.File("rb"), required=True)
|
| 51 |
-
@click.option("--target", type=click.File("wb"), required=True)
|
| 52 |
-
@click.option("--scale", type=click.IntRange(min=3, max=15), default=9)
|
| 53 |
-
@click.option("--error", type=click.Choice(list(ERROR_MAPPING)))
|
| 54 |
-
def generate_qr_code(text, background, target, scale, error):
|
| 55 |
-
write_artistic(
|
| 56 |
-
segno.make(text, error=error),
|
| 57 |
-
background,
|
| 58 |
-
target,
|
| 59 |
-
scale=scale,
|
| 60 |
-
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
myapp/cli/__init__.py
ADDED
|
File without changes
|
myapp/cli/main.py
CHANGED
|
@@ -1,9 +1,12 @@
|
|
| 1 |
import click
|
| 2 |
import dotenv
|
|
|
|
| 3 |
from huggingface_hub import InferenceClient
|
|
|
|
|
|
|
| 4 |
|
|
|
|
| 5 |
from myapp.palette import extract_color_clusters, generate_palette_image
|
| 6 |
-
from myapp.params import ImageParamType
|
| 7 |
|
| 8 |
dotenv.load_dotenv()
|
| 9 |
client = InferenceClient()
|
|
@@ -16,7 +19,7 @@ def cli():
|
|
| 16 |
|
| 17 |
@cli.command()
|
| 18 |
@click.option("--prompt", required=True)
|
| 19 |
-
@click.option("--target", type=click.
|
| 20 |
@click.option("--model", default="black-forest-labs/FLUX.1-schnell")
|
| 21 |
@click.option("--width", default=400)
|
| 22 |
@click.option("--height", default=400)
|
|
@@ -33,10 +36,25 @@ def generate_image(prompt, target, model, width, height):
|
|
| 33 |
|
| 34 |
@cli.command()
|
| 35 |
@click.option("--image", type=ImageParamType(), required=True)
|
| 36 |
-
@click.option("--target", type=click.
|
| 37 |
@click.option("--n-colors", default=4)
|
| 38 |
@click.option("--shade", "shades", default=(0.0,), multiple=True)
|
| 39 |
def generate_palette(image, target, n_colors, shades):
|
| 40 |
k_means = extract_color_clusters(image, n_colors)
|
| 41 |
palette = generate_palette_image(k_means, shades=shades)
|
| 42 |
palette.save(target)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import click
|
| 2 |
import dotenv
|
| 3 |
+
import segno
|
| 4 |
from huggingface_hub import InferenceClient
|
| 5 |
+
from qrcode_artistic import write_artistic
|
| 6 |
+
from segno.consts import ERROR_MAPPING
|
| 7 |
|
| 8 |
+
from myapp.cli.params import ImageParamType
|
| 9 |
from myapp.palette import extract_color_clusters, generate_palette_image
|
|
|
|
| 10 |
|
| 11 |
dotenv.load_dotenv()
|
| 12 |
client = InferenceClient()
|
|
|
|
| 19 |
|
| 20 |
@cli.command()
|
| 21 |
@click.option("--prompt", required=True)
|
| 22 |
+
@click.option("--target", type=click.File("wb"), required=True)
|
| 23 |
@click.option("--model", default="black-forest-labs/FLUX.1-schnell")
|
| 24 |
@click.option("--width", default=400)
|
| 25 |
@click.option("--height", default=400)
|
|
|
|
| 36 |
|
| 37 |
@cli.command()
|
| 38 |
@click.option("--image", type=ImageParamType(), required=True)
|
| 39 |
+
@click.option("--target", type=click.File("wb"), required=True)
|
| 40 |
@click.option("--n-colors", default=4)
|
| 41 |
@click.option("--shade", "shades", default=(0.0,), multiple=True)
|
| 42 |
def generate_palette(image, target, n_colors, shades):
|
| 43 |
k_means = extract_color_clusters(image, n_colors)
|
| 44 |
palette = generate_palette_image(k_means, shades=shades)
|
| 45 |
palette.save(target)
|
| 46 |
+
|
| 47 |
+
|
| 48 |
+
@cli.command()
|
| 49 |
+
@click.option("--text", required=True)
|
| 50 |
+
@click.option("--background", type=click.File("rb"), required=True)
|
| 51 |
+
@click.option("--target", type=click.File("wb"), required=True)
|
| 52 |
+
@click.option("--scale", type=click.IntRange(min=3, max=15), default=9)
|
| 53 |
+
@click.option("--error", type=click.Choice(list(ERROR_MAPPING)))
|
| 54 |
+
def generate_qr_code(text, background, target, scale, error):
|
| 55 |
+
write_artistic(
|
| 56 |
+
segno.make(text, error=error),
|
| 57 |
+
background,
|
| 58 |
+
target,
|
| 59 |
+
scale=scale,
|
| 60 |
+
)
|
myapp/{params.py → cli/params.py}
RENAMED
|
File without changes
|