wvangils commited on
Commit
7f4e78b
·
1 Parent(s): 95a20c1

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -0
app.py ADDED
@@ -0,0 +1,47 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ import gradio as gr
3
+
4
+ # Available models for pipeline
5
+ # checkpoint = 'wvangils/CTRL-Beatles-Lyrics-finetuned-newlyrics'
6
+ checkpoint = 'wvangils/GPT-Medium-Beatles-Lyrics-finetuned-newlyrics'
7
+ # checkpoint = 'wvangils/GPT-Neo-125m-Beatles-Lyrics-finetuned-newlyrics'
8
+ # checkpoint = 'wvangils/GPT2-Beatles-Lyrics-finetuned-newlyrics'
9
+ # checkpoint = 'wvangils/DistilGPT2-Beatles-Lyrics-finetuned-newlyrics'
10
+
11
+ # Create generator
12
+ generator = pipeline("text-generation", model=checkpoint)
13
+
14
+ # Create function for generation
15
+ def generate_beatles(input_prompt, temperature):
16
+ generated_lyrics = generator(input_prompt
17
+ , max_length = 100
18
+ , num_return_sequences = 1
19
+ , return_full_text = True
20
+ , verbose = 0
21
+ #, num_beams = 1
22
+ #, early_stopping = True # Werkt niet goed lijkt
23
+ , temperature = temperature # Default 1.0 # Randomness, temperature = 1 minst risicovol, 0 meest risicovol
24
+ #, top_k = 50 # Default 50
25
+ , top_p = 0.5 # Default 1.0
26
+ , no_repeat_ngram_size = 3 # Default = 0
27
+ , repetition_penalty = 1.0 # Default = 1.0
28
+ #, do_sample = True # Default = False
29
+ )[0]["generated_text"]
30
+ return generated_lyrics
31
+
32
+ # Create textboxes for input and output
33
+ input_box = gr.Textbox(label="Input prompt:", placeholder="Write the start of a song here", lines=2)
34
+ output_box = gr.Textbox(label="Lyrics by The Beatles and GPT:", lines=20)
35
+ examples = [['In my dream I am', 0.7], ['I don\'t feel alive', 0.7]]
36
+ title='Beatles lyrics generator based on GPT2'
37
+ description='A medium class GPT2 model was fine-tuned on lyrics from The Beatles to generate Beatles-like text. Give it a try!'
38
+ temperature = gr.Slider(minimum=0.0, maximum=1.0, step=0.1, label="Temperature (high = sensitive for low probability tokens)", value=0.7, show_label=True)
39
+
40
+ # Use generate Beatles function in demo-app Gradio
41
+ gr.Interface(fn=generate_beatles
42
+ , inputs=[input_box, temperature]
43
+ , outputs=output_box
44
+ , examples=examples
45
+ , title=title
46
+ , description=description
47
+ ).launch()