scene-generator / app.py
Blessin's picture
Update app.py
8b02059
import gradio as gr
import openai
def generate_scene_descriptions(api_key, theme, story):
openai.api_key = api_key
# Base introduction for the prompt
intro = f"Generate structured scene descriptions for a series of scenes for a video on the theme \"{theme}\":\n"
story_prompt = f"Story: {story}\n\n" if story else ""
# Constructing the prompt for multiple scenes
scenes_prompt = ""
for i in range(1, 6): # For generating up to 5 scenes
scenes_prompt += (
f"Scene #{i}\n"
"Narrator's voice: \n"
"Video prompt: \n"
"Voice over: \n"
"Music style: \n\n"
)
# Combine intro, optional story, and scenes into the full prompt
full_prompt = intro + story_prompt + scenes_prompt
# Call to OpenAI's GPT-3.5 API with the custom prompt
response = openai.Completion.create(
engine="text-davinci-003",
prompt=full_prompt,
max_tokens=1000 # Increased max_tokens to accommodate longer responses
)
# The response from the AI is formatted text based on our structured prompt
return response.choices[0].text.strip()
# Create the Gradio interface with appropriate inputs and outputs
iface = gr.Interface(
fn=generate_scene_descriptions,
inputs=[
gr.Textbox(label="Your OpenAI API Key", type="password", placeholder="Enter your OpenAI API Key here"), # Secure API key input
gr.Textbox(label="Thematic Area", placeholder="Enter a thematic area, e.g., Climate Crisis"), # Thematic area input
gr.Textbox(label="Story (Optional)", placeholder="Enter a story to base the scenes on (optional)") # Story input, optional by default
],
outputs="text", # The output is a text field
title="Multi-Scene Generator", # Title of the Gradio app
description="This app generates structured scene descriptions for multiple scenes of a video based on the given thematic area and optional story input using GPT-3.5." # Description for the Gradio app
)
# Launch the interface locally for testing
iface.launch()