Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -10,19 +10,6 @@ Original file is located at
|
|
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 |
-
|
14 |
-
# Commented out IPython magic to ensure Python compatibility.
|
15 |
-
# %%capture
|
16 |
-
# !pip install transformers
|
17 |
-
|
18 |
-
# Commented out IPython magic to ensure Python compatibility.
|
19 |
-
# %%capture
|
20 |
-
# !pip install gradio
|
21 |
-
|
22 |
-
# Commented out IPython magic to ensure Python compatibility.
|
23 |
-
# %%capture
|
24 |
-
# !pip install --upgrade diffusers transformers scipy ftfy "ipywidgets>=7,<8"
|
25 |
-
|
26 |
# Import libraries
|
27 |
from transformers import pipeline
|
28 |
from numpy import random
|
@@ -98,52 +85,4 @@ def generate_beatles(input_prompt, temperature, top_p, given_input_style):
|
|
98 |
|
99 |
# Generate the image
|
100 |
image = get_image(image_input)
|
101 |
-
return (title, generated_lyrics, image, image_style)
|
102 |
-
|
103 |
-
# Create textboxes for input and output
|
104 |
-
input_box = gr.Textbox(label="Write the start of a song here", placeholder="Write the start of a new song here", value="Looking beyond the Broad Horizon", lines=2, max_lines=5)
|
105 |
-
gen_lyrics = gr.Textbox(label="Proposed song lyrics", lines=15)
|
106 |
-
gen_title = gr.Textbox(label="Proposed song title", lines=1)
|
107 |
-
gen_image = gr.Gallery(label="Proposed song cover").style(grid=1, height="auto")
|
108 |
-
gen_image_style = gr.Textbox(label="Image style", lines=1)
|
109 |
-
|
110 |
-
# Layout and text around the app
|
111 |
-
title='Beatles lyrics generator'
|
112 |
-
description="<p style='text-align: center'>We've fine-tuned multiple language models on lyrics from The Beatles to generate Beatles-like text. Below are the results we obtained fine-tuning a GPT Neo model. After generation a title is generated using <a href='https://huggingface.co/czearing/story-to-title' target='_blank'>this model</a>. On top we use the generated title to suggest an album cover using <a href='https://huggingface.co/CompVis/stable-diffusion-v1-4' target='_blank'>Stable Diffusion 1.4</a>. Give it a try!</p>"
|
113 |
-
article="""<p style='text-align: left'>These text generation models that output Beatles-like text were created by data scientists working for <a href='https://cmotions.nl/' target="_blank">Cmotions.</a>
|
114 |
-
We tried several text generation models that we were able to load in Colab: a general <a href='https://huggingface.co/gpt2-medium' target='_blank'>GPT2-medium</a> model, the Eleuther AI small-sized GPT model <a href='https://huggingface.co/EleutherAI/gpt-neo-125M' target='_blank'>GPT-Neo</a> and the new kid on the block build by the <a href='https://bigscience.notion.site/BLOOM-BigScience-176B-Model-ad073ca07cdf479398d5f95d88e218c4' target='_blank'>Bigscience</a> initiative <a href='https://huggingface.co/bigscience/bloom-560m' target='_blank'>BLOOM 560m</a>.
|
115 |
-
Further we've put together a <a href='https://huggingface.co/datasets/cmotions/Beatles_lyrics' target='_blank'> Huggingface dataset</a> containing all known lyrics created by The Beatles. Currently we are fine-tuning models and are evaluating the results. Once finished we will publish a blog at this <a href='https://www.theanalyticslab.nl/blogs/' target='_blank'>location </a> with all the steps we took including a Python notebook using Huggingface.
|
116 |
-
The default output contains 100 tokens and has a repetition penalty of 1.0.
|
117 |
-
</p>"""
|
118 |
-
css = """
|
119 |
-
.gr-button-primary {
|
120 |
-
text-indent: -9999px;
|
121 |
-
line-height: 0;
|
122 |
-
}
|
123 |
-
.gr-button-primary:after {
|
124 |
-
content: "Beatlify!";
|
125 |
-
text-indent: 0;
|
126 |
-
display: block;
|
127 |
-
line-height: initial;
|
128 |
-
}
|
129 |
-
"""
|
130 |
-
|
131 |
-
# Let users select their own temperature and top-p
|
132 |
-
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
|
133 |
-
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)
|
134 |
-
given_input_style = gr.Dropdown(choices=image_input_styles, value="Random", label="Choose the art style for the song cover", show_label=True)
|
135 |
-
#checkpoint = gr.Radio(checkpoint_choices, value='wvangils/GPT-Medium-Beatles-Lyrics-finetuned-newlyrics', interactive=True, label = 'Select fine-tuned model', show_label=True)
|
136 |
-
|
137 |
-
# Use generate Beatles function in demo-app Gradio
|
138 |
-
gr.Interface(fn=generate_beatles
|
139 |
-
, inputs=[input_box, temperature, top_p, given_input_style]
|
140 |
-
, outputs=[gen_title, gen_lyrics, gen_image, gen_image_style]
|
141 |
-
, title=title
|
142 |
-
, css=css
|
143 |
-
, description=description
|
144 |
-
, article=article
|
145 |
-
, allow_flagging='never'
|
146 |
-
).launch()
|
147 |
-
|
148 |
-
# Uncomment the line below for testing
|
149 |
-
#generate_beatles(input_prompt="When I look out my window", temperature=0.7, top_p=0.5)
|
|
|
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
|
|
|
85 |
|
86 |
# Generate the image
|
87 |
image = get_image(image_input)
|
88 |
+
return (title, generated_lyrics, image, image_style)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|