rairo commited on
Commit
cdfbca8
·
verified ·
1 Parent(s): 0a3def3

Update stories.py

Browse files
Files changed (1) hide show
  1. stories.py +27 -24
stories.py CHANGED
@@ -244,6 +244,7 @@ def generateResponse(prompt, df):
244
  # -----------------------
245
  # DataFrame-Based Story Generation (for CSV/Excel files)
246
  # -----------------------
 
247
  def generate_story_from_dataframe(df, story_type):
248
  """
249
  Generate a data-based story from a CSV/Excel file.
@@ -256,22 +257,23 @@ def generate_story_from_dataframe(df, story_type):
256
  "free_form": "You are a professional storyteller. Using the following dataset in JSON format: " + df_json +
257
  ", create an engaging and concise story. ",
258
  "children": "You are a professional storyteller writing stories for children. Using the following dataset in JSON format: " + df_json +
259
- ", create a fun, factual, and concise story appropriate for children. ",
260
  "education": "You are a professional storyteller writing educational content. Using the following dataset in JSON format: " + df_json +
261
  ", create an informative, engaging, and concise educational story. Include interesting facts while keeping it engaging. ",
262
  "business": "You are a professional storyteller specializing in business narratives. Using the following dataset in JSON format: " + df_json +
263
- ", create a professional, concise business story with practical insights. ",
264
  "entertainment": "You are a professional storyteller writing creative entertaining stories. Using the following dataset in JSON format: " + df_json +
265
- ", create an engaging and concise entertaining story. Include interesting facts while keeping it engaging. "
266
  }
267
  story_prompt = prompts.get(story_type, prompts["free_form"])
268
  full_prompt = (
269
  story_prompt +
270
- "Write a story for a narrator meaning no labels of pages or sections the story should just flow. Divide your story into exactly 5 short and concise sections separated by [break]. " +
 
271
  "For each section, provide a brief narrative analysis and include, within angle brackets <>, a clear and plain-text description of a chart visualization that would represent the data. " +
272
  "Limit the descriptions by specifying only charts. " +
273
  "Ensure that your response contains only natural language descriptions examples: 'bar chart of', 'pie chart of' , 'histogram of', 'scatterplot of', 'boxplot of' , 'heatmap of etc' and nothing else."
274
-
275
  )
276
  #
277
  try:
@@ -309,7 +311,7 @@ def generate_story_from_text(prompt_text, story_type):
309
  story_prompt = prompts.get(story_type, prompts["free_form"])
310
  response = model.generate_content(
311
  story_prompt +
312
- "Write a short story for a narrator meaning no labels of pages or sections the story should just flow and narrated in 2 minutes or less. Divide your story into exactly 5 sections separated by [break]. For each section, include an image description inside <>."
313
  )
314
  return response.text if response else None
315
 
@@ -323,18 +325,18 @@ def generate_story_from_wiki(wiki_url, story_type):
323
  "free_form": "You are a professional storyteller. Using the following Wikipedia info: " + wiki_text +
324
  ", create an engaging and concise story. ",
325
  "children": "You are a professional storyteller for children. Using the following Wikipedia info: " + wiki_text +
326
- ", create a fun and concise story. ",
327
  "education": "You are a professional storyteller. Using the following Wikipedia info: " + wiki_text +
328
  ", create an educational and engaging story. ",
329
  "business": "You are a professional storyteller. Using the following Wikipedia info: " + wiki_text +
330
- ", create a professional business story. ",
331
  "entertainment": "You are a professional storyteller. Using the following Wikipedia info: " + wiki_text +
332
- ", create an entertaining and concise story. "
333
  }
334
  story_prompt = prompts.get(story_type, prompts["free_form"])
335
  response = model.generate_content(
336
  story_prompt +
337
- "Write a short story for a narrator meaning no labels of pages or sections the story should just flow and narrated in 2 minutes or less. Divide your story into exactly 5 sections separated by [break]. For each section, include an image description inside <>."
338
  )
339
  return response.text if response else None
340
  except Exception as e:
@@ -397,18 +399,18 @@ def generate_story_from_bible(reference, story_type):
397
  "free_form": "You are a professional storyteller. Using the following Bible text: " + bible_text +
398
  ", create an engaging and concise story. ",
399
  "children": "You are a professional storyteller for children. Using the following Bible text: " + bible_text +
400
- ", create a fun and concise story. ",
401
  "education": "You are a professional storyteller. Using the following Bible text: " + bible_text +
402
  ", create an educational and engaging story. ",
403
  "business": "You are a professional storyteller. Using the following Bible text: " + bible_text +
404
- ", create a professional business story. ",
405
  "entertainment": "You are a professional storyteller. Using the following Bible text: " + bible_text +
406
- ", create an entertaining and concise story. "
407
  }
408
  story_prompt = prompts.get(story_type, prompts["free_form"])
409
  response = model.generate_content(
410
  story_prompt +
411
- "Write a short story for a narrator meaning no labels of pages or sections the story should just flow and narrated in 2 minutes or less. Divide your story into exactly 5 sections separated by [break]. For each section, include a brief image description inside <>."
412
  )
413
  return response.text if response else None
414
 
@@ -422,35 +424,36 @@ def generate_story_from_youtube(youtube_url, story_type):
422
  video_id = youtube_url.split("youtu.be/")[1].split("?")[0]
423
  else:
424
  raise ValueError("Invalid YouTube URL provided.")
425
-
426
  # Retrieve the transcript as a list of dictionaries
427
  transcript_res = supadata.youtube.transcript(
428
- video_id=video_id,
429
- text=True
430
- )
431
  transcript_text = transcript_res.content
432
  # Define story prompts based on story_type, similar to the Wikipedia function
433
  prompts = {
434
  "free_form": "You are a professional storyteller. Using the following YouTube transcript: " + transcript_text +
435
  ", create an engaging and concise story. ",
436
  "children": "You are a professional storyteller for children. Using the following YouTube transcript: " + transcript_text +
437
- ", create a fun and concise story. ",
438
  "education": "You are a professional storyteller. Using the following YouTube transcript: " + transcript_text +
439
  ", create an educational and engaging story. ",
440
  "business": "You are a professional storyteller. Using the following YouTube transcript: " + transcript_text +
441
- ", create a professional business story. ",
442
  "entertainment": "You are a professional storyteller. Using the following YouTube transcript: " + transcript_text +
443
- ", create an entertaining and concise story. "
444
  }
445
  # Use the provided story_type, defaulting to free_form if not found
446
  story_prompt = prompts.get(story_type, prompts["free_form"])
447
-
448
  # Append additional instructions for story structure
449
  full_prompt = story_prompt + (
450
- "Write a short story for a narrator meaning no labels of pages or sections the story should just flow and narrated in 2 minutes or less. Divide your story into exactly 5 sections separated by [break]. "
 
451
  "For each section, include an image description inside <>."
452
  )
453
-
454
  # Generate content using your model (assumes model.generate_content is available)
455
  response = model.generate_content(full_prompt)
456
  return response.text if response else None
 
244
  # -----------------------
245
  # DataFrame-Based Story Generation (for CSV/Excel files)
246
  # -----------------------
247
+ # -----------------------
248
  def generate_story_from_dataframe(df, story_type):
249
  """
250
  Generate a data-based story from a CSV/Excel file.
 
257
  "free_form": "You are a professional storyteller. Using the following dataset in JSON format: " + df_json +
258
  ", create an engaging and concise story. ",
259
  "children": "You are a professional storyteller writing stories for children. Using the following dataset in JSON format: " + df_json +
260
+ ", create a fun, factual, and concise story appropriate for children. ",
261
  "education": "You are a professional storyteller writing educational content. Using the following dataset in JSON format: " + df_json +
262
  ", create an informative, engaging, and concise educational story. Include interesting facts while keeping it engaging. ",
263
  "business": "You are a professional storyteller specializing in business narratives. Using the following dataset in JSON format: " + df_json +
264
+ ", create a professional, concise business story with practical insights. ",
265
  "entertainment": "You are a professional storyteller writing creative entertaining stories. Using the following dataset in JSON format: " + df_json +
266
+ ", create an engaging and concise entertaining story. Include interesting facts while keeping it engaging. "
267
  }
268
  story_prompt = prompts.get(story_type, prompts["free_form"])
269
  full_prompt = (
270
  story_prompt +
271
+ "Write a story for a narrator meaning no labels of pages or sections the story should just flow. Divide your story into exactly 5 very short and concise sections separated by [break]. " +
272
+ "Aim for a maximum of 3 sentences per section to ensure a quicker narration. " +
273
  "For each section, provide a brief narrative analysis and include, within angle brackets <>, a clear and plain-text description of a chart visualization that would represent the data. " +
274
  "Limit the descriptions by specifying only charts. " +
275
  "Ensure that your response contains only natural language descriptions examples: 'bar chart of', 'pie chart of' , 'histogram of', 'scatterplot of', 'boxplot of' , 'heatmap of etc' and nothing else."
276
+
277
  )
278
  #
279
  try:
 
311
  story_prompt = prompts.get(story_type, prompts["free_form"])
312
  response = model.generate_content(
313
  story_prompt +
314
+ "Write a short story for a narrator meaning no labels of pages or sections the story should just flow and narrated in 2 minutes or less. Divide your story into exactly 5 very short and concise sections separated by [break]. Aim for a maximum of 3 sentences per section. For each section, include a brief image description inside <>."
315
  )
316
  return response.text if response else None
317
 
 
325
  "free_form": "You are a professional storyteller. Using the following Wikipedia info: " + wiki_text +
326
  ", create an engaging and concise story. ",
327
  "children": "You are a professional storyteller for children. Using the following Wikipedia info: " + wiki_text +
328
+ ", create a fun and concise story. ",
329
  "education": "You are a professional storyteller. Using the following Wikipedia info: " + wiki_text +
330
  ", create an educational and engaging story. ",
331
  "business": "You are a professional storyteller. Using the following Wikipedia info: " + wiki_text +
332
+ ", create a professional business story. ",
333
  "entertainment": "You are a professional storyteller. Using the following Wikipedia info: " + wiki_text +
334
+ ", create an entertaining and concise story. "
335
  }
336
  story_prompt = prompts.get(story_type, prompts["free_form"])
337
  response = model.generate_content(
338
  story_prompt +
339
+ "Write a short story for a narrator meaning no labels of pages or sections the story should just flow and narrated in 2 minutes or less. Divide your story into exactly 5 very short and concise sections separated by [break]. Aim for a maximum of 3 sentences per section. For each section, include a brief image description inside <>."
340
  )
341
  return response.text if response else None
342
  except Exception as e:
 
399
  "free_form": "You are a professional storyteller. Using the following Bible text: " + bible_text +
400
  ", create an engaging and concise story. ",
401
  "children": "You are a professional storyteller for children. Using the following Bible text: " + bible_text +
402
+ ", create a fun and concise story. ",
403
  "education": "You are a professional storyteller. Using the following Bible text: " + bible_text +
404
  ", create an educational and engaging story. ",
405
  "business": "You are a professional storyteller. Using the following Bible text: " + bible_text +
406
+ ", create a professional business story. ",
407
  "entertainment": "You are a professional storyteller. Using the following Bible text: " + bible_text +
408
+ ", create an entertaining and concise story. "
409
  }
410
  story_prompt = prompts.get(story_type, prompts["free_form"])
411
  response = model.generate_content(
412
  story_prompt +
413
+ "Write a short story for a narrator meaning no labels of pages or sections the story should just flow and narrated in 2 minutes or less. Divide your story into exactly 5 very short and concise sections separated by [break]. Aim for a maximum of 3 sentences per section. For each section, include a brief image description inside <>."
414
  )
415
  return response.text if response else None
416
 
 
424
  video_id = youtube_url.split("youtu.be/")[1].split("?")[0]
425
  else:
426
  raise ValueError("Invalid YouTube URL provided.")
427
+
428
  # Retrieve the transcript as a list of dictionaries
429
  transcript_res = supadata.youtube.transcript(
430
+ video_id=video_id,
431
+ text=True
432
+ )
433
  transcript_text = transcript_res.content
434
  # Define story prompts based on story_type, similar to the Wikipedia function
435
  prompts = {
436
  "free_form": "You are a professional storyteller. Using the following YouTube transcript: " + transcript_text +
437
  ", create an engaging and concise story. ",
438
  "children": "You are a professional storyteller for children. Using the following YouTube transcript: " + transcript_text +
439
+ ", create a fun and concise story. ",
440
  "education": "You are a professional storyteller. Using the following YouTube transcript: " + transcript_text +
441
  ", create an educational and engaging story. ",
442
  "business": "You are a professional storyteller. Using the following YouTube transcript: " + transcript_text +
443
+ ", create a professional business story. ",
444
  "entertainment": "You are a professional storyteller. Using the following YouTube transcript: " + transcript_text +
445
+ ", create an entertaining and concise story. "
446
  }
447
  # Use the provided story_type, defaulting to free_form if not found
448
  story_prompt = prompts.get(story_type, prompts["free_form"])
449
+
450
  # Append additional instructions for story structure
451
  full_prompt = story_prompt + (
452
+ "Write a short story for a narrator meaning no labels of pages or sections the story should just flow and narrated in 2 minutes or less. Divide your story into exactly 5 very short and concise sections separated by [break]. "
453
+ "Aim for a maximum of 3 sentences per section. "
454
  "For each section, include an image description inside <>."
455
  )
456
+
457
  # Generate content using your model (assumes model.generate_content is available)
458
  response = model.generate_content(full_prompt)
459
  return response.text if response else None