Spaces:
Running
Running
1. improved system prompt
Browse files2. added read time estimation for triggering more image prompts per scene(hopefully)
app.py
CHANGED
@@ -5,7 +5,7 @@ from utils import get_scenes, generate_video_assets, generate_video # Import th
|
|
5 |
# Streamlit app
|
6 |
st.title("Text to Video Generator")
|
7 |
|
8 |
-
# Text input box with a max of 1500 characters
|
9 |
text_script = st.text_area("Enter your text (max 1500 characters):", max_chars=1500)
|
10 |
|
11 |
|
@@ -30,7 +30,6 @@ if st.button("Generate Video"):
|
|
30 |
# Call the function from utils.py to process the text
|
31 |
scenes = get_scenes(text_script)
|
32 |
video_assets_folder = generate_video_assets(scenes, language, selected_speaker)
|
33 |
-
st.write(video_assets_folder)
|
34 |
generated_video_path = generate_video(video_assets_folder)
|
35 |
st.video(generated_video_path)
|
36 |
|
|
|
5 |
# Streamlit app
|
6 |
st.title("Text to Video Generator")
|
7 |
|
8 |
+
# Text input box with a max of 1500 characters
|
9 |
text_script = st.text_area("Enter your text (max 1500 characters):", max_chars=1500)
|
10 |
|
11 |
|
|
|
30 |
# Call the function from utils.py to process the text
|
31 |
scenes = get_scenes(text_script)
|
32 |
video_assets_folder = generate_video_assets(scenes, language, selected_speaker)
|
|
|
33 |
generated_video_path = generate_video(video_assets_folder)
|
34 |
st.video(generated_video_path)
|
35 |
|
utils.py
CHANGED
@@ -14,15 +14,17 @@ import os
|
|
14 |
|
15 |
def get_scenes(text_script: str):
|
16 |
|
|
|
17 |
prompt = f"""
|
18 |
ROLE: Story to Scene Generator
|
19 |
Tasks: For the given story
|
20 |
1. Read it Completely and Understand the Complete Context
|
21 |
-
2. Rewrite the story in tiny
|
22 |
-
3.
|
23 |
-
4.
|
24 |
|
25 |
-
|
|
|
26 |
"""
|
27 |
|
28 |
|
@@ -393,6 +395,47 @@ def generate_video_old(audio_file, images, segments):
|
|
393 |
except Exception as e:
|
394 |
print(f"Error generating video: {e}")
|
395 |
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
396 |
|
397 |
|
398 |
|
@@ -407,13 +450,3 @@ if __name__ == "__main__":
|
|
407 |
Lily knew she had found something truly extraordinary.
|
408 |
"""
|
409 |
generate_audio(short_story, "Urdu", "Asad")
|
410 |
-
# scenes_response = get_scenes(short_story)
|
411 |
-
# scenes = scenes_response.get("scenes")
|
412 |
-
# print("total scenes: ", len(scenes))
|
413 |
-
# for scene in scenes:
|
414 |
-
# print("image prompts for this scene", len(scene.get("image_prompts")))
|
415 |
-
# print("\n\n")
|
416 |
-
# for scene_count,scene in enumerate(scenes):
|
417 |
-
# image_prompts = scene.get("image_prompts")
|
418 |
-
# for count, prompt in enumerate(image_prompts):
|
419 |
-
# generate_image(prompt=prompt, path=f"scene_{scene_count+1}_image_{count+1}.png")
|
|
|
14 |
|
15 |
def get_scenes(text_script: str):
|
16 |
|
17 |
+
read_time = calculate_read_time(text_script)
|
18 |
prompt = f"""
|
19 |
ROLE: Story to Scene Generator
|
20 |
Tasks: For the given story
|
21 |
1. Read it Completely and Understand the Complete Context
|
22 |
+
2. Rewrite the story in tiny scenes(but without even changing a word) with highly detailed and context aware image or list of image prompts to visualize each scene
|
23 |
+
3. If necessary, a scene can have more than one image prompts
|
24 |
+
4. Make sure there is an image prompt for every 4-5 sec
|
25 |
|
26 |
+
here is the Estimated Read Time of the complete story: {read_time}\n\n
|
27 |
+
and Here is the Complete Story: {text_script}
|
28 |
"""
|
29 |
|
30 |
|
|
|
395 |
except Exception as e:
|
396 |
print(f"Error generating video: {e}")
|
397 |
return None
|
398 |
+
|
399 |
+
|
400 |
+
|
401 |
+
def calculate_read_time(text: str, words_per_minute: int = 155) -> str:
|
402 |
+
"""
|
403 |
+
Calculate how long it will take to read a given text.
|
404 |
+
|
405 |
+
Args:
|
406 |
+
text (str): The input text to calculate reading time for.
|
407 |
+
words_per_minute (int): Average reading speed in words per minute. Default is 155(an uneducated guess).
|
408 |
+
|
409 |
+
Returns:
|
410 |
+
str: A string describing the reading time in seconds, minutes, or hours.
|
411 |
+
"""
|
412 |
+
try:
|
413 |
+
# Validate input
|
414 |
+
if not text or not isinstance(text, str):
|
415 |
+
return "Invalid input: Text must be a non-empty string."
|
416 |
+
|
417 |
+
# Calculate the number of words in the text
|
418 |
+
words = text.split()
|
419 |
+
word_count = len(words)
|
420 |
+
|
421 |
+
# Calculate total reading time in seconds
|
422 |
+
total_seconds = (word_count / words_per_minute) * 60
|
423 |
+
|
424 |
+
# Convert to hours, minutes, and seconds
|
425 |
+
hours = int(total_seconds // 3600)
|
426 |
+
minutes = int((total_seconds % 3600) // 60)
|
427 |
+
seconds = int(total_seconds % 60)
|
428 |
+
|
429 |
+
# Format the output based on the duration
|
430 |
+
if hours > 0:
|
431 |
+
return f"Reading time: {hours} hour(s), {minutes} minute(s), and {seconds} second(s)."
|
432 |
+
elif minutes > 0:
|
433 |
+
return f"Reading time: {minutes} minute(s) and {seconds} second(s)."
|
434 |
+
else:
|
435 |
+
return f"Reading time: {seconds} second(s)."
|
436 |
+
|
437 |
+
except Exception as e:
|
438 |
+
return f"An error occurred: {e}"
|
439 |
|
440 |
|
441 |
|
|
|
450 |
Lily knew she had found something truly extraordinary.
|
451 |
"""
|
452 |
generate_audio(short_story, "Urdu", "Asad")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|