Blessin commited on
Commit
c770bf3
·
1 Parent(s): 34ead9b

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -0
app.py ADDED
@@ -0,0 +1,56 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ from gtts import gTTS
4
+ import tempfile
5
+
6
+ def generate_stage_directions(location, situation, api_key):
7
+ prompt = (
8
+ f"Write detailed stage directions for a scene with 5 characters, set in a {location}. "
9
+ "You are reading these directions out loud to an audience, so keep the stage directions conversational. "
10
+ "Do not break it down into different sections. Each character enters one by one, two of them enter as a couple. "
11
+ "As they enter, tell us their name and describe their physical characteristics, their emotional state and their actions, "
12
+ "gestures and movements in the scene. Write detailed stage direction on how they interact with the location they are in "
13
+ "and with each other, with detailed description on their movements, actions and gestures in the scene. Make the overall "
14
+ "scene highly dramatic, full of twists and turns, with lots of movement by the characters that keep changing positions "
15
+ "and moving around. At some point, a {situation} happens in the scene. Show the characters interacting with elements of "
16
+ "the location. Describe in vivid detail their emotion, facial expressions and emotions. You will also write dialogues for "
17
+ "each character. Keep the dialogues short. Keep the scene mostly non-verbal, with only a few dialogues. Make the scene "
18
+ "very dramatic, emotional, thrilling. Keep your response limited to 750 words."
19
+ )
20
+
21
+ openai.api_key = api_key # Set the API key from the user input
22
+
23
+ try:
24
+ response = openai.Completion.create(
25
+ engine="text-davinci-003",
26
+ prompt=prompt,
27
+ max_tokens=750,
28
+ temperature=0.7,
29
+ )
30
+ stage_directions = response.choices[0].text.strip()
31
+ response_audio_path = text_to_audio(stage_directions)
32
+ return response_audio_path
33
+ except Exception as e:
34
+ return str(e)
35
+
36
+ def text_to_audio(text):
37
+ tts = gTTS(text, lang='en')
38
+ temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.mp3')
39
+ tts.save(temp_file.name)
40
+ return temp_file.name
41
+
42
+ # Create Gradio UI
43
+ iface = gr.Interface(
44
+ fn=generate_stage_directions,
45
+ inputs=[
46
+ gr.Textbox(label="Location"),
47
+ gr.Textbox(label="Situation"),
48
+ gr.Textbox(label="API Key")
49
+ ],
50
+ outputs=gr.Audio(type='filepath', label="Stage Directions"),
51
+ live=True,
52
+ title="DramaDirector",
53
+ description="Input a location, situation, and your OpenAI API key to generate stage directions.",
54
+ )
55
+
56
+ iface.launch()