freddyaboulton HF Staff commited on
Commit
f8e42c7
·
1 Parent(s): 1126985
Files changed (1) hide show
  1. app.py +9 -5
app.py CHANGED
@@ -207,20 +207,24 @@ def generate_base(subject, setting):
207
  "a minute to read")},
208
  {"role": "user", "content": f"Please tell me a story about a {subject} in {setting}"}]
209
  gr.Info("Generating story", duration=3)
210
- response = client.chat_completion(messages, max_tokens=2048, seed=random.randint(1, 5000))
211
  gr.Info("Story Generated", duration=3)
212
  story = response.choices[0].message.content
213
 
214
  model_input = story.replace("\n", " ").strip()
215
  model_input_tokens = nltk.sent_tokenize(model_input)
 
 
 
216
 
217
- play_steps_in_s = 4.0
 
218
  play_steps = int(frame_rate * play_steps_in_s)
219
 
220
  description = "Jenny speaks at an average pace with a calm delivery in a very confined sounding environment with clear audio quality."
221
  description_tokens = tokenizer(description, return_tensors="pt").to(device)
222
 
223
- for i, sentence in enumerate(model_input):
224
  streamer = ParlerTTSStreamer(model, device=device, play_steps=play_steps)
225
 
226
  prompt = tokenizer(sentence, return_tensors="pt").to(device)
@@ -253,8 +257,8 @@ with gr.Blocks() as block:
253
  )
254
  with gr.Group():
255
  with gr.Row():
256
- subject = gr.Dropdown(value="Princess", choices=["Prince", "Princess", "Dog", "Cat"])
257
- setting = gr.Dropdown(value="Forest", choices=["Forest", "Kingdom", "Jungle", "Underwater"])
258
  with gr.Row():
259
  run_button = gr.Button("Generate Story", variant="primary")
260
  with gr.Row():
 
207
  "a minute to read")},
208
  {"role": "user", "content": f"Please tell me a story about a {subject} in {setting}"}]
209
  gr.Info("Generating story", duration=3)
210
+ response = client.chat_completion(messages, max_tokens=1024, seed=random.randint(1, 5000))
211
  gr.Info("Story Generated", duration=3)
212
  story = response.choices[0].message.content
213
 
214
  model_input = story.replace("\n", " ").strip()
215
  model_input_tokens = nltk.sent_tokenize(model_input)
216
+ model_input_token_pairs = []
217
+ for i in range(0, len(model_input_tokens), 2):
218
+ model_input_token_pairs.append(" ".join(model_input_tokens[i:(i + 2)]))
219
 
220
+
221
+ play_steps_in_s = 5.0
222
  play_steps = int(frame_rate * play_steps_in_s)
223
 
224
  description = "Jenny speaks at an average pace with a calm delivery in a very confined sounding environment with clear audio quality."
225
  description_tokens = tokenizer(description, return_tensors="pt").to(device)
226
 
227
+ for i, sentence in enumerate(model_input_token_pairs):
228
  streamer = ParlerTTSStreamer(model, device=device, play_steps=play_steps)
229
 
230
  prompt = tokenizer(sentence, return_tensors="pt").to(device)
 
257
  )
258
  with gr.Group():
259
  with gr.Row():
260
+ subject = gr.Dropdown(value="Princess", choices=["Prince", "Princess", "Dog", "Cat"], label="Subject")
261
+ setting = gr.Dropdown(value="Forest", choices=["Forest", "Kingdom", "Jungle", "Underwater", "Pirate Ship"], label="Setting")
262
  with gr.Row():
263
  run_button = gr.Button("Generate Story", variant="primary")
264
  with gr.Row():