chansung commited on
Commit
81f6d41
·
1 Parent(s): 9f2284c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +43 -1
app.py CHANGED
@@ -1,12 +1,15 @@
1
  import os
 
2
  import json
3
  import random
4
  import string
5
  import requests
 
6
  import torch
7
 
8
  import gradio as gr
9
  from PIL import Image
 
10
  from diffusers import StableDiffusionPipeline
11
 
12
  from pingpong import PingPong
@@ -453,6 +456,32 @@ def fill_with_gen(alt_txt, editor):
453
  gr.update(visible=False)
454
  ]
455
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
456
  with gr.Blocks(css=STYLES) as demo:
457
 
458
  num_enabled_alts = gr.State(0)
@@ -531,7 +560,7 @@ with gr.Blocks(css=STYLES) as demo:
531
  clear_btn = gr.Button("clear", interactive=False, elem_classes=['control-label-font', 'control-button'])
532
  regen_btn = gr.Button("regenerate", interactive=False, elem_classes=['control-label-font', 'control-button'])
533
 
534
- with gr.Tab("Exporting"):
535
  with gr.Column(elem_classes=['group-border']):
536
  gr.Markdown("generate cover art with [`nota-ai/bk-sdm-base`](https://huggingface.co/nota-ai/bk-sdm-base) model. "
537
  "design your own prompt in the textbox below, or just hit 'generate prompt for cover art` button. LLaMA2 "
@@ -544,8 +573,21 @@ with gr.Blocks(css=STYLES) as demo:
544
  gen_pdf_btn = gr.Button("export as PDF", elem_classes=['control-label-font', 'control-button'])
545
  pdf_file = gr.File(visible=False)
546
 
 
 
 
 
 
 
 
547
  progress_bar = gr.Textbox(elem_classes=['no-label'])
548
 
 
 
 
 
 
 
549
  gen_pdf_btn.click(
550
  lambda t, e, c: generate_pdf(t, e, c),
551
  inputs=[title, editor, cover_art],
 
1
  import os
2
+ import io
3
  import json
4
  import random
5
  import string
6
  import requests
7
+ import base64
8
  import torch
9
 
10
  import gradio as gr
11
  from PIL import Image
12
+ from datasets import load_dataset
13
  from diffusers import StableDiffusionPipeline
14
 
15
  from pingpong import PingPong
 
456
  gr.update(visible=False)
457
  ]
458
 
459
+ def share(title, editor, cover_art):
460
+ if title.strip() == '':
461
+ title = 'Untitled'
462
+
463
+ dataset = load_dataset("chansung/llama2-stories")
464
+
465
+ buffered = io.BytesIO()
466
+ cover_art.save(buffered, format="PNG")
467
+ img_str = base64.b64encode(buffered.getvalue())
468
+
469
+ dataset['train'] = dataset['train'].add_item({
470
+ 'title': title,
471
+ 'story': story,
472
+ 'image': img_str
473
+ })
474
+
475
+ dataset.push_to_hub("chansung/llama2-stories", token=TOKEN)
476
+
477
+ return [
478
+ " "
479
+ ]
480
+
481
+ fn=share
482
+ inputs=[title, editor, cover_art],
483
+ outputs=[progress_bar]
484
+
485
  with gr.Blocks(css=STYLES) as demo:
486
 
487
  num_enabled_alts = gr.State(0)
 
560
  clear_btn = gr.Button("clear", interactive=False, elem_classes=['control-label-font', 'control-button'])
561
  regen_btn = gr.Button("regenerate", interactive=False, elem_classes=['control-label-font', 'control-button'])
562
 
563
+ with gr.Tab("Exporting/Sharing"):
564
  with gr.Column(elem_classes=['group-border']):
565
  gr.Markdown("generate cover art with [`nota-ai/bk-sdm-base`](https://huggingface.co/nota-ai/bk-sdm-base) model. "
566
  "design your own prompt in the textbox below, or just hit 'generate prompt for cover art` button. LLaMA2 "
 
573
  gen_pdf_btn = gr.Button("export as PDF", elem_classes=['control-label-font', 'control-button'])
574
  pdf_file = gr.File(visible=False)
575
 
576
+ with gr.Column(elem_classes=['group-border']):
577
+ gr.Markdown("by clicking the button below, your stories will be shared within community. All shared stories will be "
578
+ "archived in [llama2-stories](https://huggingface.co/datasets/chansung/llama2-stories) dataset repository, and "
579
+ "they will be displayed in [chansung/LLaMA2-Story-Showcase](https://huggingface.co/spaces/chansung/LLaMA2-Story-Showcase) space.")
580
+
581
+ share_btn = gr.Button("share", elem_classes=['control-label-font', 'control-button'])
582
+
583
  progress_bar = gr.Textbox(elem_classes=['no-label'])
584
 
585
+ share_btn.click(
586
+ fn=share
587
+ inputs=[title, editor, cover_art],
588
+ outputs=[progress_bar]
589
+ )
590
+
591
  gen_pdf_btn.click(
592
  lambda t, e, c: generate_pdf(t, e, c),
593
  inputs=[title, editor, cover_art],