Spaces:
Running
Running
add inputs dict
Browse files- myapp/app.py +10 -8
myapp/app.py
CHANGED
@@ -1,8 +1,10 @@
|
|
1 |
from pathlib import Path
|
2 |
from tempfile import NamedTemporaryFile
|
|
|
3 |
|
4 |
import gradio as gr
|
5 |
import segno
|
|
|
6 |
from huggingface_hub import InferenceClient
|
7 |
from PIL import Image
|
8 |
from qrcode_artistic import write_artistic
|
@@ -39,23 +41,23 @@ with gr.Blocks() as demo:
|
|
39 |
return client.text_to_image(prompt, width=400, height=400), None
|
40 |
|
41 |
@gr.on(
|
42 |
-
triggers=[text.submit,
|
43 |
-
inputs=
|
44 |
outputs=output,
|
45 |
)
|
46 |
-
def generate_code(
|
47 |
-
if background is None:
|
48 |
return None
|
49 |
|
50 |
-
qr_code = segno.make(text, error="h")
|
51 |
-
suffix = Path(background).suffix
|
52 |
|
53 |
with NamedTemporaryFile(suffix=suffix) as temp_file:
|
54 |
write_artistic(
|
55 |
qr_code,
|
56 |
-
background=background,
|
57 |
target=temp_file,
|
58 |
-
|
|
|
59 |
)
|
60 |
|
61 |
return Image.open(temp_file.name)
|
|
|
1 |
from pathlib import Path
|
2 |
from tempfile import NamedTemporaryFile
|
3 |
+
from typing import Any
|
4 |
|
5 |
import gradio as gr
|
6 |
import segno
|
7 |
+
from gradio.components import Component
|
8 |
from huggingface_hub import InferenceClient
|
9 |
from PIL import Image
|
10 |
from qrcode_artistic import write_artistic
|
|
|
41 |
return client.text_to_image(prompt, width=400, height=400), None
|
42 |
|
43 |
@gr.on(
|
44 |
+
triggers=[text.submit, background.change, scale.change],
|
45 |
+
inputs={text, background, scale},
|
46 |
outputs=output,
|
47 |
)
|
48 |
+
def generate_code(data: dict[Component, Any]):
|
49 |
+
if data[background] is None:
|
50 |
return None
|
51 |
|
52 |
+
qr_code = segno.make(data[text], error="h")
|
53 |
+
suffix = Path(data[background]).suffix
|
54 |
|
55 |
with NamedTemporaryFile(suffix=suffix) as temp_file:
|
56 |
write_artistic(
|
57 |
qr_code,
|
|
|
58 |
target=temp_file,
|
59 |
+
background=data[background],
|
60 |
+
scale=data[scale],
|
61 |
)
|
62 |
|
63 |
return Image.open(temp_file.name)
|