Spaces:
Runtime error
Runtime error
Add missing files, update for gradio 4 compatibility.
Browse files- SampleCard.png +0 -0
- app.py +14 -7
- hotkeys.js +4 -5
- placeholder.png +0 -0
- scratch.html +0 -0
SampleCard.png
ADDED
app.py
CHANGED
@@ -2,6 +2,7 @@
|
|
2 |
# pip install html2image
|
3 |
import base64
|
4 |
import random
|
|
|
5 |
from io import BytesIO
|
6 |
|
7 |
import imgkit
|
@@ -125,7 +126,10 @@ Color: ['W']
|
|
125 |
if len(new_card_text) > 1:
|
126 |
new_card_text = new_card_text[1].strip()
|
127 |
else:
|
128 |
-
new_card_text = new_card_text.split('\n\n')
|
|
|
|
|
|
|
129 |
return assistant_reply, new_card_text, None
|
130 |
|
131 |
|
@@ -227,7 +231,7 @@ def format_html(text, image_data):
|
|
227 |
f'<header class="powerToughness"><div><h2 style="font-family: \'Beleren\';font-size: 19px;">{power}/{toughness}</h2></div></header>')
|
228 |
else:
|
229 |
template = template.replace("{power_toughness}", "")
|
230 |
-
pathlib.Path("
|
231 |
return template
|
232 |
|
233 |
|
@@ -290,7 +294,9 @@ def pil_to_base64(image):
|
|
290 |
def generate_card(image: str, card_text: str):
|
291 |
image_data = pil_to_base64(Image.open(image))
|
292 |
html = format_html(card_text, image_data)
|
293 |
-
|
|
|
|
|
294 |
return card
|
295 |
|
296 |
|
@@ -341,8 +347,8 @@ with gr.Blocks(title='MagicGen') as demo:
|
|
341 |
with gr.Row():
|
342 |
with gr.Column():
|
343 |
with gr.Group():
|
344 |
-
audio_in = gr.
|
345 |
-
|
346 |
prompt_in = gr.Textbox(label="Or type a text request and press Enter", interactive=True,
|
347 |
placeholder="Need an idea? Try one of these:\n- Create a creature card named 'WiFi Elemental'\n- Make it an instant\n- Change the color")
|
348 |
with gr.Accordion(label='🤖 Chat Assistant Response', open=False):
|
@@ -370,8 +376,9 @@ with gr.Blocks(title='MagicGen') as demo:
|
|
370 |
generate_card, [in_image, in_text], [out_image], None)
|
371 |
in_text.submit(generate_image, [in_text], [in_image], None).then(generate_card, [in_image, in_text], [out_image],
|
372 |
None)
|
373 |
-
run_button.click(generate_image, [in_text], [in_image], None).then(generate_card, [in_image, in_text], [out_image],
|
374 |
-
|
|
|
375 |
|
376 |
if __name__ == "__main__":
|
377 |
demo.queue().launch(favicon_path="favicon-96x96.png")
|
|
|
2 |
# pip install html2image
|
3 |
import base64
|
4 |
import random
|
5 |
+
import uuid
|
6 |
from io import BytesIO
|
7 |
|
8 |
import imgkit
|
|
|
126 |
if len(new_card_text) > 1:
|
127 |
new_card_text = new_card_text[1].strip()
|
128 |
else:
|
129 |
+
new_card_text = new_card_text.split('\n\n')
|
130 |
+
if len(new_card_text) < 2:
|
131 |
+
return assistant_reply, card_text, None
|
132 |
+
new_card_text = new_card_text[1].strip()
|
133 |
return assistant_reply, new_card_text, None
|
134 |
|
135 |
|
|
|
231 |
f'<header class="powerToughness"><div><h2 style="font-family: \'Beleren\';font-size: 19px;">{power}/{toughness}</h2></div></header>')
|
232 |
else:
|
233 |
template = template.replace("{power_toughness}", "")
|
234 |
+
pathlib.Path("scratch.html").write_text(template, encoding='utf-8')
|
235 |
return template
|
236 |
|
237 |
|
|
|
294 |
def generate_card(image: str, card_text: str):
|
295 |
image_data = pil_to_base64(Image.open(image))
|
296 |
html = format_html(card_text, image_data)
|
297 |
+
pattern = re.compile('Name: (.*)')
|
298 |
+
name = pattern.findall(card_text)[0]
|
299 |
+
card = html_to_png(name, html)
|
300 |
return card
|
301 |
|
302 |
|
|
|
347 |
with gr.Row():
|
348 |
with gr.Column():
|
349 |
with gr.Group():
|
350 |
+
audio_in = gr.Microphone(label="Record a voice request (click or press ctrl + ` to start/stop)",
|
351 |
+
type='filepath', elem_classes=["record-btn"])
|
352 |
prompt_in = gr.Textbox(label="Or type a text request and press Enter", interactive=True,
|
353 |
placeholder="Need an idea? Try one of these:\n- Create a creature card named 'WiFi Elemental'\n- Make it an instant\n- Change the color")
|
354 |
with gr.Accordion(label='🤖 Chat Assistant Response', open=False):
|
|
|
376 |
generate_card, [in_image, in_text], [out_image], None)
|
377 |
in_text.submit(generate_image, [in_text], [in_image], None).then(generate_card, [in_image, in_text], [out_image],
|
378 |
None)
|
379 |
+
run_button.click(generate_image, [in_text], [in_image], None).then(generate_card, [in_image, in_text], [out_image],
|
380 |
+
None)
|
381 |
+
demo.load(None, None, None, js=add_hotkeys())
|
382 |
|
383 |
if __name__ == "__main__":
|
384 |
demo.queue().launch(favicon_path="favicon-96x96.png")
|
hotkeys.js
CHANGED
@@ -12,11 +12,10 @@
|
|
12 |
}
|
13 |
window.addEventListener('keydown', (e) => {
|
14 |
if ((e.ctrlKey || e.metaKey) && e.key == "`") { // CTRL + ` key
|
15 |
-
const recordButtons = gradioApp().querySelectorAll(
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
}
|
20 |
}
|
21 |
}
|
22 |
});
|
|
|
12 |
}
|
13 |
window.addEventListener('keydown', (e) => {
|
14 |
if ((e.ctrlKey || e.metaKey) && e.key == "`") { // CTRL + ` key
|
15 |
+
const recordButtons = [...gradioApp().querySelectorAll('button.record.record-button')].filter(x => x.checkVisibility());
|
16 |
+
const stopButtons = [...gradioApp().querySelectorAll('button.stop-button')].filter(x => x.checkVisibility());
|
17 |
+
for (let button of recordButtons.concat(stopButtons)) {
|
18 |
+
button.click();
|
|
|
19 |
}
|
20 |
}
|
21 |
});
|
placeholder.png
ADDED
scratch.html
ADDED
The diff for this file is too large to render.
See raw diff
|
|