Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
@@ -1,26 +1,69 @@
|
|
1 |
-
import spaces
|
2 |
-
import random
|
3 |
-
import openai
|
4 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
5 |
|
6 |
-
|
7 |
-
# ... (rest of your code remains unchanged)
|
8 |
|
9 |
-
#
|
10 |
iface = gr.Interface(
|
11 |
-
fn=
|
12 |
-
inputs=[
|
13 |
-
|
14 |
-
gr.
|
15 |
-
gr.
|
16 |
-
gr.
|
17 |
-
gr.outputs.Textbox(label="relationship"),
|
18 |
-
gr.outputs.Textbox(label="occupation"),
|
19 |
-
gr.outputs.Textbox(label="location") # Assuming you also want to output location
|
20 |
],
|
|
|
21 |
live=True,
|
22 |
-
title="
|
23 |
-
description="Generate a
|
|
|
24 |
)
|
25 |
|
|
|
26 |
iface.launch()
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import openai
|
3 |
+
|
4 |
+
def generate_script(api_key, name1, name2, situation):
|
5 |
+
# Initialize OpenAI API with the provided key
|
6 |
+
openai.api_key = api_key
|
7 |
+
|
8 |
+
# Define the example script to set the context
|
9 |
+
example_script = (
|
10 |
+
"Setting: A cafe\n\n"
|
11 |
+
"Scene:\n\n"
|
12 |
+
"(Lights come up on a cozy little coffee shop. LOUIS and GIRL are sitting at a small table, with two untouched coffees between them. "
|
13 |
+
"It's clear from their expressions that the awkwardness from the previous scene hasn't worn off.)\n\n"
|
14 |
+
"LOUIS. (Attempting to break the ice) So, um... do you come to this coffee shop often?\n"
|
15 |
+
"GIRL. (Coldly) No, not really.\n"
|
16 |
+
"LOUIS. Oh. Well, they have the best almond croissants here. You should try one, sometime.\n"
|
17 |
+
"GIRL. (Slightly warming up) I'm more of a bagel person, actually.\n"
|
18 |
+
"LOUIS. Really? Me too! What's your favorite kind?\n"
|
19 |
+
"GIRL. Plain. With cream cheese.\n"
|
20 |
+
"LOUIS. Nice choice. I like mine with a bit of jam.\n"
|
21 |
+
"(A brief pause as they both sip their coffee, seemingly more at ease.)\n\n"
|
22 |
+
"LOUIS. (Hesitant) Look, I'm sorry about earlier... I don't know why I was acting like such a jerk.\n"
|
23 |
+
"GIRL. (Softening) It's alright. People can act strange when they meet someone new.\n"
|
24 |
+
"LOUIS. Yeah. It's just... I've been feeling kind of... out of place lately. And I guess I was trying too hard to impress you.\n"
|
25 |
+
"GIRL. You don't have to impress me, Louis. Just be yourself.\n"
|
26 |
+
"(LOUIS smiles shyly and looks down at his coffee. The GIRL does too, and for a moment, there's a comfortable silence between them.)\n\n"
|
27 |
+
"LOUIS. So... do you have any plans for the weekend?\n"
|
28 |
+
"GIRL. (Smiling) Not much. Just taking my dog to the park. Maybe catch a movie later. How about you?\n"
|
29 |
+
"LOUIS. Same here. Minus the dog, though.\n"
|
30 |
+
"GIRL. (Laughs) Well, maybe you can join me. And who knows, you might just enjoy the simple joy of a walk in the park.\n"
|
31 |
+
"LOUIS. (Smiling) I'd like that.\n\n"
|
32 |
+
"(As they continue chatting, the lights dim, suggesting the budding of a new connection between LOUIS and GIRL.)\n\n"
|
33 |
+
"(Blackout)\n"
|
34 |
+
)
|
35 |
+
|
36 |
+
# Define the prompt to transform the user's inputs into a stage play script
|
37 |
+
prompt_text = (
|
38 |
+
f"{example_script}\n\n"
|
39 |
+
f"Generate a new stage play script based on the following details:\n"
|
40 |
+
f"Location: Cafe\n"
|
41 |
+
f"Character 1: {name1}\n"
|
42 |
+
f"Character 2: {name2}\n"
|
43 |
+
f"Situation: {situation}\n"
|
44 |
+
)
|
45 |
+
|
46 |
+
# Use OpenAI's Completion endpoint to generate the stage play script
|
47 |
+
response = openai.Completion.create(engine="davinci", prompt=prompt_text, max_tokens=500)
|
48 |
+
script = response.choices[0].text.strip()
|
49 |
|
50 |
+
return script
|
|
|
51 |
|
52 |
+
# Define Gradio Interface
|
53 |
iface = gr.Interface(
|
54 |
+
fn=generate_script,
|
55 |
+
inputs=[
|
56 |
+
gr.components.Textbox(label="OpenAI API Key", type="password"),
|
57 |
+
gr.components.Textbox(label="Name 1", type="text"),
|
58 |
+
gr.components.Textbox(label="Name 2", type="text"),
|
59 |
+
gr.components.Textbox(label="Situation", type="text"),
|
|
|
|
|
|
|
60 |
],
|
61 |
+
outputs=gr.components.Textbox(label="Generated Stage Play Script", type="text"),
|
62 |
live=True,
|
63 |
+
title="Stage Play Script Generator",
|
64 |
+
description="Generate a stage play script set in a cafe based on given characters and situation using OpenAI!",
|
65 |
+
progress="Generating stage play script...",
|
66 |
)
|
67 |
|
68 |
+
# Launch the Gradio app
|
69 |
iface.launch()
|