gstaff commited on
Commit
29350b7
·
1 Parent(s): b2773c1

Block execution if name is blank, hide HTML output

Browse files
Files changed (1) hide show
  1. app.py +13 -6
app.py CHANGED
@@ -242,7 +242,7 @@ def format_monster_card(monster_text, image_data):
242
  else:
243
  card = card.replace('{actions}', f'<div class="monster-action"><p>{actions}</p></div>')
244
 
245
- # TODO: Legendary actions, reactions, make column count for format an option (1 or 2 column layout), add examples
246
 
247
  card = card.replace('Melee Weapon Attack:', '<i>Melee Weapon Attack:</i>')
248
  card = card.replace('Ranged Weapon Attack:', '<i>Ranged Weapon Attack:</i>')
@@ -295,6 +295,9 @@ def html_to_png(html):
295
  def run(name: str) -> (Image, str, Image, str):
296
  start = time.time()
297
  print(f'BEGINNING RUN FOR {name}')
 
 
 
298
  text = gen_monster_text(name)
299
  description = parse_monster_description(text)
300
  pil = gen_image(description)
@@ -311,11 +314,15 @@ app_description = (
311
  # Create your own D&D monster!
312
  Enter a name, click Submit, and wait for about 4 minutes to see the result.
313
  """).strip()
314
- input_box = gr.inputs.Textbox(label="Enter a monster name", placeholder="Jabberwock")
315
- output_monster_card = gr.outputs.Image(label="Monster Card", type='pil')
316
- output_text_box = gr.outputs.Textbox(label="Monster Text")
317
- output_monster_image = gr.outputs.Image(label="Monster Image", type='pil')
318
- output_monster_html = gr.outputs.HTML(label="Monster HTML")
 
319
  iface = gr.Interface(title="MonsterGen", theme="default", description=app_description, fn=run, inputs=[input_box],
320
  outputs=[output_monster_card, output_text_box, output_monster_image, output_monster_html])
321
  iface.launch()
 
 
 
 
242
  else:
243
  card = card.replace('{actions}', f'<div class="monster-action"><p>{actions}</p></div>')
244
 
245
+ # TODO: Legendary actions, reactions, make column count for format an option (1 or 2 column layout)
246
 
247
  card = card.replace('Melee Weapon Attack:', '<i>Melee Weapon Attack:</i>')
248
  card = card.replace('Ranged Weapon Attack:', '<i>Ranged Weapon Attack:</i>')
 
295
  def run(name: str) -> (Image, str, Image, str):
296
  start = time.time()
297
  print(f'BEGINNING RUN FOR {name}')
298
+ if not name:
299
+ placeholder_image = Image.new(mode="RGB", size=(256, 256))
300
+ return placeholder_image, 'No name provided; enter a name and try again', placeholder_image, ''
301
  text = gen_monster_text(name)
302
  description = parse_monster_description(text)
303
  pil = gen_image(description)
 
314
  # Create your own D&D monster!
315
  Enter a name, click Submit, and wait for about 4 minutes to see the result.
316
  """).strip()
317
+ input_box = gr.Textbox(label="Enter a monster name", placeholder="Jabberwock")
318
+ output_monster_card = gr.Image(label="Monster Card", type='pil')
319
+ output_text_box = gr.Textbox(label="Monster Text")
320
+ output_monster_image = gr.Image(label="Monster Image", type='pil')
321
+ output_monster_html = gr.HTML(label="Monster HTML", visible=False, show_label=False)
322
+ x = gr.components.Textbox()
323
  iface = gr.Interface(title="MonsterGen", theme="default", description=app_description, fn=run, inputs=[input_box],
324
  outputs=[output_monster_card, output_text_box, output_monster_image, output_monster_html])
325
  iface.launch()
326
+ # https://gradio.app/sharing_your_app/#api-page
327
+ # Looks like API page improvements are in progress: https://github.com/gradio-app/gradio/issues/1325
328
+ # TODO: Add examples