Beatles_Poetry / app.py
wvangils's picture
Update blog link and text
b36de8f
import transformers
from transformers import pipeline
import gradio as gr
checkpoint_choices = ['wvangils/GPT-Medium-Beatles-Lyrics-finetuned-newlyrics', 'wvangils/GPT-Neo-125m-Beatles-Lyrics-finetuned-newlyrics', 'wvangils/BLOOM-560m-Beatles-Lyrics-finetuned']
# Create function for generation
def generate_beatles(checkpoint, input_prompt, temperature, top_p):
# Create generator for different models
generator = pipeline("text-generation", model=checkpoint)
generated_lyrics = generator(input_prompt
, max_length = 100
, num_return_sequences = 1
, return_full_text = True
, verbose = 0
#, num_beams = 1
#, early_stopping = True # Werkt niet goed lijkt
, temperature = temperature # Default 1.0 # Randomness, temperature = 1 minst risicovol, 0 meest risicovol
#, top_k = 50 # Default 50
, top_p = top_p # Default 1.0
, no_repeat_ngram_size = 3 # Default = 0
, repetition_penalty = 1.0 # Default = 1.0
#, do_sample = True # Default = False
)[0]["generated_text"]
return generated_lyrics
# Create textboxes for input and output
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)
output_box = gr.Textbox(label="Lyrics by The Beatles and chosen language model:", lines=25)
# Layout and text above the App
title='Beatles lyrics generator'
description="<p style='text-align: center'>Multiple language models were fine-tuned on lyrics from The Beatles to generate Beatles-like text. Give it a try!</p>"
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>
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>.
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.
The default output contains 100 tokens and has a repetition penalty of 1.0.
</p>"""
# Let users select their own temperature and top-p
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)
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)
checkpoint = gr.Radio(checkpoint_choices, value='wvangils/GPT-Medium-Beatles-Lyrics-finetuned-newlyrics', interactive=True, label = 'Select fine-tuned model', show_label=True)
# Use generate Beatles function in demo-app Gradio
gr.Interface(fn=generate_beatles
, inputs=[checkpoint, input_box, temperature, top_p]
, outputs=output_box
#, examples=examples # output is not very fancy as you have to specify all inputs for every example
, title=title
, description=description
, article=article
, allow_flagging='never'
).launch()