-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt_to_video_cli.py
More file actions
executable file
Β·192 lines (157 loc) Β· 6.46 KB
/
prompt_to_video_cli.py
File metadata and controls
executable file
Β·192 lines (157 loc) Β· 6.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
#!/usr/bin/env python3
"""
Prompt-to-Video CLI Tool
Generate videos from text prompts by first creating an image with DALL-E,
then animating it with Runway AI.
Note: This is a workaround for DALL-E image access restrictions.
The images are generated and then you need to manually download and host them
or use the suggested working URLs instead.
"""
import argparse
import json
import sys
import time
def generate_image_suggestions(prompt: str) -> None:
"""Generate image suggestions for the given prompt."""
print(f"π¨ For the prompt: '{prompt}'")
print(" Here are some similar working image URLs you can use:")
print()
# Suggest relevant working images based on keywords
suggestions = []
prompt_lower = prompt.lower()
if any(word in prompt_lower for word in ['mountain', 'peak', 'landscape', 'nature']):
suggestions.append({
"url": "https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800&q=80&fit=crop",
"description": "Mountain landscape with sky"
})
if any(word in prompt_lower for word in ['forest', 'tree', 'wood', 'leaves']):
suggestions.append({
"url": "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?w=800&q=80&fit=crop",
"description": "Forest scene with trees"
})
if any(word in prompt_lower for word in ['ocean', 'sea', 'water', 'wave', 'beach']):
suggestions.append({
"url": "https://images.unsplash.com/photo-1439066615861-d1af74d74000?w=800&q=80&fit=crop",
"description": "Ocean waves and water"
})
if any(word in prompt_lower for word in ['city', 'urban', 'building', 'skyline']):
suggestions.append({
"url": "https://images.unsplash.com/photo-1449824913935-59a10b8d2000?w=800&q=80&fit=crop",
"description": "City skyline and buildings"
})
# Always add the random option
suggestions.append({
"url": "https://picsum.photos/800/600",
"description": "Random high-quality image"
})
if not suggestions:
suggestions = [
{
"url": "https://picsum.photos/800/600",
"description": "Random high-quality image"
}
]
for i, suggestion in enumerate(suggestions, 1):
print(f"{i}. {suggestion['description']}")
print(f" URL: {suggestion['url']}")
print()
def generate_curl_command(image_url: str, video_prompt: str, duration: int, ratio: str) -> str:
"""Generate a curl command for video generation."""
return f"""curl -X POST "http://localhost:8000/generate-video" \\
-H "Content-Type: application/json" \\
-d '{{
"image_url": "{image_url}",
"prompt_text": "{video_prompt}",
"ratio": "{ratio}",
"duration": {duration}
}}'"""
def main():
"""Main CLI function."""
parser = argparse.ArgumentParser(
description="Generate video from text prompt (via image suggestions)",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Examples:
# Get suggestions for a mountain scene
python prompt_to_video_cli.py "A serene mountain landscape with snow-capped peaks"
# Generate suggestions with custom video prompt
python prompt_to_video_cli.py \\
--image-prompt "A peaceful forest clearing" \\
--video-prompt "Gentle wind moving through the trees"
# Get suggestions and generate curl command
python prompt_to_video_cli.py \\
--image-prompt "Ocean waves on a beach" \\
--video-prompt "Waves gently washing on shore" \\
--generate-curl
"""
)
parser.add_argument(
"image_prompt",
nargs="?",
help="Text description for the image you want to generate"
)
parser.add_argument(
"--image-prompt", "-i",
help="Text description for the image (alternative to positional argument)"
)
parser.add_argument(
"--video-prompt", "-v",
help="Text description for video animation (optional)"
)
parser.add_argument(
"--duration", "-d",
type=int,
default=5,
choices=[5, 10],
help="Video duration in seconds (5 or 10)"
)
parser.add_argument(
"--ratio", "-r",
default="1280:720",
help="Video aspect ratio (e.g., '1280:720', '1024:1024')"
)
parser.add_argument(
"--generate-curl", "-c",
action="store_true",
help="Generate curl commands for the suggested images"
)
args = parser.parse_args()
# Get image prompt from positional or named argument
image_prompt = args.image_prompt or getattr(args, 'image_prompt', None)
if not image_prompt:
parser.print_help()
sys.exit(1)
video_prompt = args.video_prompt or f"Cinematic animation of: {image_prompt}"
print("π¬ Prompt-to-Video Generation Assistant")
print("=" * 50)
print()
print("π‘ Due to DALL-E image access restrictions, we'll suggest")
print(" working image URLs that match your prompt instead.")
print()
# Generate suggestions
generate_image_suggestions(image_prompt)
if args.generate_curl:
print("π Example CURL Commands:")
print("-" * 30)
print()
# Get the first suggested URL for the example
prompt_lower = image_prompt.lower()
example_url = "https://picsum.photos/800/600" # Default
if any(word in prompt_lower for word in ['mountain', 'peak', 'landscape']):
example_url = "https://images.unsplash.com/photo-1506905925346-21bda4d32df4?w=800&q=80&fit=crop"
elif any(word in prompt_lower for word in ['forest', 'tree', 'wood']):
example_url = "https://images.unsplash.com/photo-1441974231531-c6227db76b6e?w=800&q=80&fit=crop"
elif any(word in prompt_lower for word in ['ocean', 'sea', 'water']):
example_url = "https://images.unsplash.com/photo-1439066615861-d1af74d74000?w=800&q=80&fit=crop"
curl_cmd = generate_curl_command(example_url, video_prompt, args.duration, args.ratio)
print(curl_cmd)
print()
print("π Next Steps:")
print("1. Choose an image URL from the suggestions above")
print("2. Use the regular /generate-video endpoint with that URL")
print("3. Or use the curl command if --generate-curl was specified")
print()
print("π‘ Pro Tip: The 'Random high-quality image' option often works great!")
print(" Just refresh the URL to get different images: https://picsum.photos/800/600")
if __name__ == "__main__":
main()