chansung commited on
Commit
4a514f9
·
1 Parent(s): 3fdb865

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +6 -3
app.py CHANGED
@@ -203,7 +203,7 @@ def select(editor, evt: gr.SelectData):
203
  evt.index[1]
204
  ]
205
 
206
- def get_gen_txt(editor, prompt):
207
  if editor.strip() == '':
208
  ppm = get_new_ppm('Write a short paragraph to start a short story for me')
209
  else:
@@ -213,7 +213,10 @@ def get_gen_txt(editor, prompt):
213
 
214
  try:
215
  txt = gen_text(ppm.build_prompts(), hf_model=MODEL_ID, hf_token=TOKEN)
216
- return editor + txt + "\n\n"
 
 
 
217
  except ValueError as e:
218
  print(f"something went wrong - {e}")
219
  return editor
@@ -307,7 +310,7 @@ def replace_sel(editor, replace_type, selected_text, sel_index_from, sel_index_t
307
 
308
  def gen_alt(editor, num_enabled_alts, alt_btn1, alt_btn2, alt_btn3):
309
  if num_enabled_alts < 3:
310
- gen_txt = get_gen_txt(editor, "Write the next paragraph based on the following stories so far.")
311
 
312
  return [
313
  min(num_enabled_alts+1, 3),
 
203
  evt.index[1]
204
  ]
205
 
206
+ def get_gen_txt(editor, prompt, only_gen_text=False):
207
  if editor.strip() == '':
208
  ppm = get_new_ppm('Write a short paragraph to start a short story for me')
209
  else:
 
213
 
214
  try:
215
  txt = gen_text(ppm.build_prompts(), hf_model=MODEL_ID, hf_token=TOKEN)
216
+ if only_gen_text:
217
+ return txt + "\n\n"
218
+ else:
219
+ return editor + txt + "\n\n"
220
  except ValueError as e:
221
  print(f"something went wrong - {e}")
222
  return editor
 
310
 
311
  def gen_alt(editor, num_enabled_alts, alt_btn1, alt_btn2, alt_btn3):
312
  if num_enabled_alts < 3:
313
+ gen_txt = get_gen_txt(editor, "Write the next paragraph based on the following stories so far.", only_gen_text=True)
314
 
315
  return [
316
  min(num_enabled_alts+1, 3),