File size: 2,099 Bytes
e3ab9bc
 
 
338a195
e3ab9bc
08898cf
61efed0
8b02059
338a195
 
61efed0
 
 
 
 
 
 
 
 
 
 
338a195
 
e3ab9bc
08898cf
e3ab9bc
 
61efed0
338a195
e3ab9bc
 
08898cf
e3ab9bc
 
08898cf
 
61efed0
08898cf
43f25a7
338a195
8b02059
08898cf
 
43f25a7
 
08898cf
 
 
e3ab9bc
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
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()