Spaces:
Runtime error
Runtime error
New version with top_p, no examples to choose from and article text below the App.
Browse files
app.py
CHANGED
@@ -5,7 +5,7 @@ import gradio as gr
|
|
5 |
# Available models for pipeline
|
6 |
# checkpoint = 'wvangils/CTRL-Beatles-Lyrics-finetuned-newlyrics'
|
7 |
checkpoint = 'wvangils/GPT-Medium-Beatles-Lyrics-finetuned-newlyrics'
|
8 |
-
#
|
9 |
# checkpoint = 'wvangils/GPT2-Beatles-Lyrics-finetuned-newlyrics'
|
10 |
# checkpoint = 'wvangils/DistilGPT2-Beatles-Lyrics-finetuned-newlyrics'
|
11 |
|
@@ -13,7 +13,7 @@ checkpoint = 'wvangils/GPT-Medium-Beatles-Lyrics-finetuned-newlyrics'
|
|
13 |
generator = pipeline("text-generation", model=checkpoint)
|
14 |
|
15 |
# Create function for generation
|
16 |
-
def generate_beatles(input_prompt, temperature):
|
17 |
generated_lyrics = generator(input_prompt
|
18 |
, max_length = 100
|
19 |
, num_return_sequences = 1
|
@@ -23,7 +23,7 @@ def generate_beatles(input_prompt, temperature):
|
|
23 |
#, early_stopping = True # Werkt niet goed lijkt
|
24 |
, temperature = temperature # Default 1.0 # Randomness, temperature = 1 minst risicovol, 0 meest risicovol
|
25 |
#, top_k = 50 # Default 50
|
26 |
-
, top_p =
|
27 |
, no_repeat_ngram_size = 3 # Default = 0
|
28 |
, repetition_penalty = 1.0 # Default = 1.0
|
29 |
#, do_sample = True # Default = False
|
@@ -31,18 +31,35 @@ def generate_beatles(input_prompt, temperature):
|
|
31 |
return generated_lyrics
|
32 |
|
33 |
# Create textboxes for input and output
|
34 |
-
input_box = gr.Textbox(label="Input prompt:", placeholder="Write the start of a song here", lines=2)
|
35 |
-
output_box = gr.Textbox(label="Lyrics by The Beatles and GPT:", lines=
|
36 |
-
|
|
|
|
|
|
|
|
|
37 |
title='Beatles lyrics generator based on GPT2'
|
38 |
-
description='A medium class GPT2 model was fine-tuned on lyrics from The Beatles to generate Beatles-like text. Give it a try
|
39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
40 |
|
41 |
# Use generate Beatles function in demo-app Gradio
|
42 |
gr.Interface(fn=generate_beatles
|
43 |
-
, inputs=[input_box, temperature]
|
44 |
, outputs=output_box
|
45 |
-
|
46 |
, title=title
|
47 |
, description=description
|
|
|
|
|
48 |
).launch()
|
|
|
5 |
# Available models for pipeline
|
6 |
# checkpoint = 'wvangils/CTRL-Beatles-Lyrics-finetuned-newlyrics'
|
7 |
checkpoint = 'wvangils/GPT-Medium-Beatles-Lyrics-finetuned-newlyrics'
|
8 |
+
#checkpoint = 'wvangils/GPT-Neo-125m-Beatles-Lyrics-finetuned-newlyrics'
|
9 |
# checkpoint = 'wvangils/GPT2-Beatles-Lyrics-finetuned-newlyrics'
|
10 |
# checkpoint = 'wvangils/DistilGPT2-Beatles-Lyrics-finetuned-newlyrics'
|
11 |
|
|
|
13 |
generator = pipeline("text-generation", model=checkpoint)
|
14 |
|
15 |
# Create function for generation
|
16 |
+
def generate_beatles(input_prompt, temperature, top_p):
|
17 |
generated_lyrics = generator(input_prompt
|
18 |
, max_length = 100
|
19 |
, num_return_sequences = 1
|
|
|
23 |
#, early_stopping = True # Werkt niet goed lijkt
|
24 |
, temperature = temperature # Default 1.0 # Randomness, temperature = 1 minst risicovol, 0 meest risicovol
|
25 |
#, top_k = 50 # Default 50
|
26 |
+
, top_p = top_p # Default 1.0
|
27 |
, no_repeat_ngram_size = 3 # Default = 0
|
28 |
, repetition_penalty = 1.0 # Default = 1.0
|
29 |
#, do_sample = True # Default = False
|
|
|
31 |
return generated_lyrics
|
32 |
|
33 |
# Create textboxes for input and output
|
34 |
+
input_box = gr.Textbox(label="Input prompt:", placeholder="Write the start of a song here", value="In my dreams I am", lines=2, max_lines=5)
|
35 |
+
output_box = gr.Textbox(label="Lyrics by The Beatles and GPT:", lines=25)
|
36 |
+
|
37 |
+
# Specify examples
|
38 |
+
examples = [['In my dreams I am', 0.7], ['I don\'t feel alive when', 0.7]]
|
39 |
+
|
40 |
+
# Layout and text above the App
|
41 |
title='Beatles lyrics generator based on GPT2'
|
42 |
+
description="<p style='text-align: center'>A medium class GPT2 model was fine-tuned on lyrics from The Beatles to generate Beatles-like text. Give it a try!</p>"
|
43 |
+
article="""<p style='text-align: left'>A couple of data scientists working for <a href='https://cmotions.nl/' targeet="_blank">Cmotions</a> came together to construct a Language Generation model that will ouput Beatles-like text.
|
44 |
+
We used several models that were able to load in Colab and choose <a href='https://huggingface.co/gpt2-medium' target='_blank'>GPT2-medium</a> as the winner. 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
|
45 |
+
The Beatles. <a href='https://www.theanalyticslab.nl/blogs/' target='_blank'>Read this blog </a> to see how this model was build in a Python the notebook using Huggingface.
|
46 |
+
The default output contains 100 tokens and has a repetition penalty of 1.0.
|
47 |
+
</p>"""
|
48 |
+
|
49 |
+
# Let users select their own temperature and top-p
|
50 |
+
temperature = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, label="Temperature (high = sensitive for low probability tokens)", value=0.7, show_label=True)
|
51 |
+
top_p = gr.Slider(minimum=0.1, maximum=1.0, step=0.1, label="Top-p (sample next possible words from given probability p)", value=0.5, show_label=True)
|
52 |
+
|
53 |
+
# Can I put examples in an input dropdown box?
|
54 |
+
#examples_dropdown = gr.Dropdown(choises=examples, value = 'In my dreams I am', label='Examples', show_label=True)
|
55 |
|
56 |
# Use generate Beatles function in demo-app Gradio
|
57 |
gr.Interface(fn=generate_beatles
|
58 |
+
, inputs=[input_box, temperature, top_p]
|
59 |
, outputs=output_box
|
60 |
+
#, examples=examples # output is not very fancy as you have to specify all inputs for every example
|
61 |
, title=title
|
62 |
, description=description
|
63 |
+
, article=article
|
64 |
+
, allow_flagging='never'
|
65 |
).launch()
|