Spaces:
Runtime error
Runtime error
File size: 1,676 Bytes
a5fc5ac |
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 |
from openai import OpenAI
from dotenv import load_dotenv
# Env variable
load_dotenv()
# Initialize OpenAI client
client = OpenAI()
def generate_video_prompt_with_template(role: str, setting: str, emotion: str, shot: str, duration: str) -> str:
system_prompt = (
"You are a video director who converts structured metadata into detailed, natural language video prompts.\n"
"Here are examples:\n\n"
"Example 1:\n"
"- Role: Product demo\n"
"- Setting: Urban bar\n"
"- Emotion: Energetic\n"
"- Shot: Front-facing, 5s loop\n"
"Output: \"Create a short 5-second video of a product demo in an energetic tone. "
"The scene takes place in an urban bar setting, using a front-facing camera to capture the vibrant atmosphere.\"\n\n"
"Example 2:\n"
"- Role: Storytelling\n"
"- Setting: Forest, misty\n"
"- Emotion: Mysterious\n"
"- Shot: Wide shot\n"
"Output: \"Create a video showing a mysterious scene in a misty forest. Use a wide shot to capture the atmosphere and suspense.\"\n\n"
"Now, create a natural language video prompt for the following:\n"
)
user_prompt = (
f"- Role: {role}\n"
f"- Setting: {setting}\n"
f"- Emotion: {emotion}\n"
f"- Shot: {shot}, {duration}\n"
)
response = client.chat.completions.create(
model="gpt-4o",
messages=[
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
],
temperature=0.3
)
final_prompt = response.choices[0].message.content.strip()
return final_prompt
|