Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,24 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
| 3 |
|
| 4 |
-
def
|
| 5 |
openai.api_key = api_key
|
| 6 |
|
| 7 |
-
#
|
| 8 |
-
intro = f"Generate
|
| 9 |
-
scene = f"Scene #{scene_number}\n"
|
| 10 |
-
narrator_voice = "Narrator's voice: \n"
|
| 11 |
-
video_prompt = "Video prompt: \n"
|
| 12 |
-
voice_over = "Voice over: \n"
|
| 13 |
-
music_style = "Music style: \n"
|
| 14 |
|
| 15 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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=
|
| 21 |
-
max_tokens=550
|
| 22 |
)
|
| 23 |
|
| 24 |
# The response from the AI is formatted text based on our structured prompt
|
|
@@ -26,16 +33,14 @@ def generate_scene_description(api_key, theme, scene_number):
|
|
| 26 |
|
| 27 |
# Create the Gradio interface with appropriate inputs and outputs
|
| 28 |
iface = gr.Interface(
|
| 29 |
-
fn=
|
| 30 |
inputs=[
|
| 31 |
-
gr.Textbox(label="Thematic Area", placeholder="Enter a thematic area, e.g., Climate Crisis"), # Thematic area input
|
| 32 |
gr.Textbox(label="Your OpenAI API Key", type="password"), # Secure API key input
|
| 33 |
-
|
| 34 |
-
# gr.Dropdown(label="Scene Number", choices=[1, 2, 3, 4, 5, 6], type="index") # Dropdown for selecting scene number
|
| 35 |
],
|
| 36 |
outputs="text", # The output is a text field
|
| 37 |
-
title="Scene Generator", # Title of the Gradio app
|
| 38 |
-
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
|
| 39 |
)
|
| 40 |
|
| 41 |
# Launch the interface locally for testing
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import openai
|
| 3 |
|
| 4 |
+
def generate_scene_descriptions(api_key, theme):
|
| 5 |
openai.api_key = api_key
|
| 6 |
|
| 7 |
+
# Base introduction for the prompt
|
| 8 |
+
intro = f"Generate structured scene descriptions for a series of scenes for a video on the theme \"{theme}\":\n"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
|
| 10 |
+
# Constructing the prompt for multiple scenes
|
| 11 |
+
scenes_prompt = ""
|
| 12 |
+
for i in range(1, 6): # For generating up to 5 scenes
|
| 13 |
+
scenes_prompt += (
|
| 14 |
+
f"Scene #{i}\n"
|
| 15 |
+
"Narrator's voice: \n"
|
| 16 |
+
"Video prompt: \n"
|
| 17 |
+
"Voice over: \n"
|
| 18 |
+
"Music style: \n\n"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Combine intro and scenes into the full prompt
|
| 22 |
+
full_prompt = intro + scenes_prompt
|
| 23 |
|
| 24 |
# Call to OpenAI's GPT-3.5 API with the custom prompt
|
| 25 |
response = openai.Completion.create(
|
| 26 |
engine="text-davinci-003",
|
| 27 |
+
prompt=full_prompt,
|
| 28 |
+
max_tokens=550 # Adjust as necessary
|
| 29 |
)
|
| 30 |
|
| 31 |
# The response from the AI is formatted text based on our structured prompt
|
|
|
|
| 33 |
|
| 34 |
# Create the Gradio interface with appropriate inputs and outputs
|
| 35 |
iface = gr.Interface(
|
| 36 |
+
fn=generate_scene_descriptions,
|
| 37 |
inputs=[
|
|
|
|
| 38 |
gr.Textbox(label="Your OpenAI API Key", type="password"), # Secure API key input
|
| 39 |
+
gr.Textbox(label="Thematic Area", placeholder="Enter a thematic area, e.g., Climate Crisis") # Thematic area input
|
|
|
|
| 40 |
],
|
| 41 |
outputs="text", # The output is a text field
|
| 42 |
+
title="Multi-Scene Generator", # Title of the Gradio app
|
| 43 |
+
description="This app generates structured scene descriptions for multiple scenes of a video based on the given thematic area using GPT-3.5." # Description for the Gradio app
|
| 44 |
)
|
| 45 |
|
| 46 |
# Launch the interface locally for testing
|