Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -3,6 +3,8 @@ import openai
|
|
| 3 |
|
| 4 |
def generate_scene_description(api_key, theme, scene_number):
|
| 5 |
openai.api_key = api_key
|
|
|
|
|
|
|
| 6 |
intro = f"Generate a structured scene description for a video on the theme \"{theme}\":\n\n"
|
| 7 |
scene = f"Scene #{scene_number}\n"
|
| 8 |
narrator_voice = "Narrator's voice: \n"
|
|
@@ -12,12 +14,28 @@ def generate_scene_description(api_key, theme, scene_number):
|
|
| 12 |
|
| 13 |
prompt = intro + scene + narrator_voice + video_prompt + voice_over + music_style
|
| 14 |
|
|
|
|
| 15 |
response = openai.Completion.create(
|
| 16 |
engine="text-davinci-003",
|
| 17 |
prompt=prompt,
|
| 18 |
max_tokens=250
|
| 19 |
)
|
| 20 |
|
|
|
|
| 21 |
return response.choices[0].text.strip()
|
| 22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
iface.launch()
|
|
|
|
| 3 |
|
| 4 |
def generate_scene_description(api_key, theme, scene_number):
|
| 5 |
openai.api_key = api_key
|
| 6 |
+
|
| 7 |
+
# Variables that represent each part of the scene description
|
| 8 |
intro = f"Generate a structured scene description for a video on the theme \"{theme}\":\n\n"
|
| 9 |
scene = f"Scene #{scene_number}\n"
|
| 10 |
narrator_voice = "Narrator's voice: \n"
|
|
|
|
| 14 |
|
| 15 |
prompt = intro + scene + narrator_voice + video_prompt + voice_over + music_style
|
| 16 |
|
| 17 |
+
# Call to OpenAI's GPT-3.5 API with the custom prompt
|
| 18 |
response = openai.Completion.create(
|
| 19 |
engine="text-davinci-003",
|
| 20 |
prompt=prompt,
|
| 21 |
max_tokens=250
|
| 22 |
)
|
| 23 |
|
| 24 |
+
# The response from the AI is formatted text based on our structured prompt
|
| 25 |
return response.choices[0].text.strip()
|
| 26 |
|
| 27 |
+
# Create the Gradio interface with appropriate inputs and outputs
|
| 28 |
+
iface = gr.Interface(
|
| 29 |
+
fn=generate_scene_description,
|
| 30 |
+
inputs=[
|
| 31 |
+
gr.Textbox(label="Your OpenAI API Key", type="password"), # Secure API key input
|
| 32 |
+
gr.Textbox(label="Thematic Area", placeholder="Enter a thematic area, e.g., Climate Crisis"), # Thematic area input
|
| 33 |
+
gr.Dropdown(label="Scene Number", choices=[1, 2, 3, 4, 5, 6], type="index") # Dropdown for selecting scene number
|
| 34 |
+
],
|
| 35 |
+
outputs="text", # The output is a text field
|
| 36 |
+
title="Video Scene Description Generator", # Title of the Gradio app
|
| 37 |
+
description="This app generates structured scene descriptions for a video based on the given thematic area using GPT-3.5." # Description for the Gradio app
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# Launch the interface locally for testing
|
| 41 |
iface.launch()
|