wvangils commited on
Commit
bf62490
1 Parent(s): fd10d16

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +3 -19
app.py CHANGED
@@ -1,15 +1,3 @@
1
- # -*- coding: utf-8 -*-
2
- """20221027_Generate_Beatles_with_Gradio_faster_version (2).ipynb
3
-
4
- Automatically generated by Colaboratory.
5
-
6
- Original file is located at
7
- https://colab.research.google.com/drive/1B2KVLt04uBMgr2ejW19FYaEgk9lnNS0E
8
-
9
- # Build a demo
10
-
11
- Put together a Gradio App bases on the Huggingface tutorials so that users can generate Beatles-like poetry based on an input prompt.
12
- """
13
  # Import libraries
14
  from transformers import pipeline
15
  from numpy import random
@@ -46,8 +34,9 @@ checkpoint = 'wvangils/BLOOM-560m-Beatles-Lyrics-finetuned'
46
  # Setup all the pipelines we need
47
  title_generator = pipeline('summarization', model='czearing/story-to-title')
48
  lyrics_generator = pipeline("text-generation", model=checkpoint)
49
- # For the image generator we use stable diffusion from an existing HuggingFace space
50
- stable_diffusion = gr.Blocks.load(name="spaces/stabilityai/stable-diffusion-2")
 
51
 
52
  # Create 4 images for the given prompt and receive the first one
53
  # This function uses an existing HuggingFace space where the number of created images cannot be modified
@@ -63,14 +52,10 @@ def generate_beatles(input_prompt, temperature, top_p, given_input_style):
63
  , max_length = 100
64
  , num_return_sequences = 1
65
  , return_full_text = True
66
- #, num_beams = 1
67
- #, early_stopping = True # Werkt niet goed lijkt
68
  , temperature = temperature
69
- #, top_k = 50 # Default 50
70
  , top_p = top_p # Default 1.0
71
  , no_repeat_ngram_size = 3 # Default = 0
72
  , repetition_penalty = 1.0 # Default = 1.0
73
- #, do_sample = True # Default = False
74
  )[0]["generated_text"]
75
 
76
  # Put lyrics in the right form
@@ -118,7 +103,6 @@ css = """
118
  temperature = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, label="Change the temperature \r\n (higher temperature = more creative in lyrics generation, but posibbly less Beatly)", value=0.7, show_label=True) #high = sensitive for low probability tokens
119
  top_p = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, label="Change top probability of the next word \n (higher top probability = more words to choose from for the next word, but possibly less Beatly)", value=0.5, show_label=True)
120
  given_input_style = gr.Dropdown(choices=image_input_styles, value="Random", label="Choose the art style for the lyrics cover", show_label=True)
121
- #checkpoint = gr.Radio(checkpoint_choices, value='wvangils/GPT-Medium-Beatles-Lyrics-finetuned-newlyrics', interactive=True, label = 'Select fine-tuned model', show_label=True)
122
 
123
  # Use generate Beatles function in demo-app Gradio
124
  gr.Interface(fn=generate_beatles
 
 
 
 
 
 
 
 
 
 
 
 
1
  # Import libraries
2
  from transformers import pipeline
3
  from numpy import random
34
  # Setup all the pipelines we need
35
  title_generator = pipeline('summarization', model='czearing/story-to-title')
36
  lyrics_generator = pipeline("text-generation", model=checkpoint)
37
+
38
+ # For the image generator we use stable diffusion from an existing HuggingFace space, Gradio accelerated backend
39
+ stable_diffusion = gr.Blocks.load(name="spaces/stabilityai/stable-diffusion-1")
40
 
41
  # Create 4 images for the given prompt and receive the first one
42
  # This function uses an existing HuggingFace space where the number of created images cannot be modified
52
  , max_length = 100
53
  , num_return_sequences = 1
54
  , return_full_text = True
 
 
55
  , temperature = temperature
 
56
  , top_p = top_p # Default 1.0
57
  , no_repeat_ngram_size = 3 # Default = 0
58
  , repetition_penalty = 1.0 # Default = 1.0
 
59
  )[0]["generated_text"]
60
 
61
  # Put lyrics in the right form
103
  temperature = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, label="Change the temperature \r\n (higher temperature = more creative in lyrics generation, but posibbly less Beatly)", value=0.7, show_label=True) #high = sensitive for low probability tokens
104
  top_p = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, label="Change top probability of the next word \n (higher top probability = more words to choose from for the next word, but possibly less Beatly)", value=0.5, show_label=True)
105
  given_input_style = gr.Dropdown(choices=image_input_styles, value="Random", label="Choose the art style for the lyrics cover", show_label=True)
 
106
 
107
  # Use generate Beatles function in demo-app Gradio
108
  gr.Interface(fn=generate_beatles