mikegarts commited on
Commit
953e78b
1 Parent(s): 7ecd55b

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -9
app.py CHANGED
@@ -38,18 +38,20 @@ summarizer = pipeline("summarization")
38
 
39
  #######################################################
40
 
41
- def break_until_dot(txt):
42
- return txt.rsplit('.', 1)[0] + '.'
43
-
44
  def generate(prompt):
45
- generated = text_generation_pipe(prompt, max_length=140)[0]['generated_text']
46
- return break_until_dot(generated)
 
47
 
 
 
 
 
 
48
 
49
  def generate_story(prompt):
50
  story = generate(prompt=prompt)
51
  summary = summarizer(story, min_length=5, max_length=15)[0]['summary_text']
52
- summary = break_until_dot(summary)
53
  return story, summary, gr.update(visible=True)
54
 
55
  def on_change_event(app_state):
@@ -101,8 +103,8 @@ with gr.Blocks() as demo:
101
  })
102
  title = gr.Markdown('## Lord of the rings app')
103
  description = gr.Markdown(f'#### A Lord of the rings inspired app that combines text and image generation.'
104
- f' The language modeling is done by fine tuning distilgpt2 on the LOTR trilogy ({SAVED_CHECKPOINT}).'
105
- f' The text2img model is {model_id}. The summarization is done using the default distilbart.')
106
  prompt = gr.Textbox(label="Your prompt", value="Frodo took the sword and")
107
  story = gr.Textbox(label="Your story")
108
  summary = gr.Textbox(label="Summary")
@@ -138,4 +140,4 @@ with gr.Blocks() as demo:
138
  if READ_TOKEN:
139
  demo.queue().launch()
140
  else:
141
- demo.queue().launch(share=True, debug=True)
 
38
 
39
  #######################################################
40
 
 
 
 
41
  def generate(prompt):
42
+ res = text_generation_pipe(prompt,
43
+ max_length=140,
44
+ repetition_penalty=1.1)[0]['generated_text']
45
 
46
+ i=0
47
+ while res[-1] != '.' and i < 30:
48
+ res = text_generation_pipe(res, max_length=1)[0]['generated_text']
49
+ i += 1
50
+ return res
51
 
52
  def generate_story(prompt):
53
  story = generate(prompt=prompt)
54
  summary = summarizer(story, min_length=5, max_length=15)[0]['summary_text']
 
55
  return story, summary, gr.update(visible=True)
56
 
57
  def on_change_event(app_state):
 
103
  })
104
  title = gr.Markdown('## Lord of the rings app')
105
  description = gr.Markdown(f'#### A Lord of the rings inspired app that combines text and image generation.'
106
+ f' The language modeling is done by fine tuning distilgpt2 on the LOTR trilogy {SAVED_CHECKPOINT}.'
107
+ f' The text2img model is {model_id}. The summarization is done using distilbart.')
108
  prompt = gr.Textbox(label="Your prompt", value="Frodo took the sword and")
109
  story = gr.Textbox(label="Your story")
110
  summary = gr.Textbox(label="Summary")
 
140
  if READ_TOKEN:
141
  demo.queue().launch()
142
  else:
143
+ demo.queue().launch(share=True, debug=True)