-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpreview_prompts_cli.py
More file actions
executable file
Β·105 lines (91 loc) Β· 3.33 KB
/
Copy pathpreview_prompts_cli.py
File metadata and controls
executable file
Β·105 lines (91 loc) Β· 3.33 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
#!/usr/bin/env python3
"""
CLI tool to preview prompts that will be sent to APIs before generating content.
Shows exactly what text will be used for image, video, and voice generation.
"""
import sys
import json
from src.text_extractor import TextExtractor
def main():
if len(sys.argv) < 2:
print("π Prompt Preview CLI Tool")
print("=" * 40)
print()
print("Usage: python preview_prompts_cli.py \"Your prompt here\" [options]")
print()
print("Examples:")
print(" # Simple preview")
print(" python preview_prompts_cli.py \"A beautiful mountain landscape\"")
print()
print(" # With audio")
print(" python preview_prompts_cli.py \"Historical map of Portugal\" --voice male_deep --style explainer")
print()
print(" # Custom script")
print(" python preview_prompts_cli.py \"City skyline\" --voice female --script \"Urban development analysis.\"")
print()
return
# Parse arguments
image_prompt = sys.argv[1]
voice_type = None
style = None
custom_script = None
duration = 5
# Simple argument parsing
args = sys.argv[2:]
i = 0
while i < len(args):
if args[i] == '--voice' and i + 1 < len(args):
voice_type = args[i + 1]
i += 2
elif args[i] == '--style' and i + 1 < len(args):
style = args[i + 1]
i += 2
elif args[i] == '--script' and i + 1 < len(args):
custom_script = args[i + 1]
i += 2
elif args[i] == '--duration' and i + 1 < len(args):
duration = int(args[i + 1])
i += 2
else:
i += 1
# Initialize extractor
extractor = TextExtractor()
print(f"π Previewing prompts for: \"{image_prompt}\"")
print()
try:
# Generate preview (this will print prompts to console automatically)
result = extractor.generate_video_from_prompt(
image_prompt=image_prompt,
voice_type=voice_type,
style=style,
voice_script_preview=custom_script,
duration=duration,
merge_audio=bool(voice_type),
preview_only=True # β This triggers the console output
)
# Parse result for additional info
result_data = json.loads(result)
if result_data.get('status') == 'preview':
print("π‘ To generate content, remove 'preview_only' or set it to False")
print()
print("π API Example:")
print('curl -X POST "http://localhost:8000/generate-video-from-prompt" \\')
print(' -H "Content-Type: application/json" \\')
request_data = {
"image_prompt": image_prompt,
"duration": duration
}
if voice_type:
request_data["voice_type"] = voice_type
request_data["merge_audio"] = True
if style:
request_data["style"] = style
if custom_script:
request_data["voice_script_preview"] = custom_script
print(f' -d \'{json.dumps(request_data, indent=2)}\'')
else:
print(f"β Preview failed: {result_data.get('error')}")
except Exception as e:
print(f"β Error: {str(e)}")
if __name__ == "__main__":
main()