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="
Multiple language models were fine-tuned on lyrics from The Beatles to generate Beatles-like text. Give it a try!
" article="""These text generation models that output Beatles-like text were created by data scientists working for Cmotions. We tried several text generation models that we were able to load in Colab: a general GPT2-medium model, the Eleuther AI small-sized GPT model GPT-Neo and the new kid on the block build by the Bigscience initiative BLOOM 560m. Further we've put together a Huggingface dataset 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 location 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.
""" # 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()