Blessin commited on
Commit
5f64618
·
1 Parent(s): 918b5ae

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -10
app.py CHANGED
@@ -1,30 +1,79 @@
1
  import openai
2
  import gradio as gr
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  def set_openai_key(api_key):
5
  # Set up the OpenAI API key
6
  openai.api_key = api_key
7
 
8
- def generate_statement(api_key):
9
  # Set the OpenAI API key using the provided input
10
  set_openai_key(api_key)
11
 
12
- # Generate a statement using OpenAI's GPT 3.5 model
13
- response = openai.Completion.create(
14
- engine="davinci",
15
- prompt="Provide a short and intriguing dialogue that can be incorporated into an improvisation scene to provoke unexpected reactions and drive the narrative in interesting directions.",
16
- max_tokens=50
17
- )
18
- return response.choices[0].text.strip()
 
 
 
 
19
 
20
  def main():
21
  # Define the UI components using gr.Interface
22
  interface = gr.Interface(
23
  fn=generate_statement, # Function to call on button press
24
- inputs="text", # Input is a text field for API key
25
  outputs="text", # Output is a text area
26
  live=False, # Only generate statement after button press
27
- description="Enter your OpenAI API key and press the button to generate a statement."
28
  )
29
 
30
  # Launch the UI on Spaces
 
1
  import openai
2
  import gradio as gr
3
+ import random
4
+
5
+ DIALOGUES = [
6
+ "Don’t look now, but they’re right behind you.",
7
+ "I need to talk to you about something.",
8
+ "Oh no! You’re hurt!",
9
+ "And that's why you're fired.",
10
+ "What’s that on your arm?",
11
+ "Is this seat taken?",
12
+ "I can’t believe you actually got me a pony!",
13
+ "Quick, pretend we've known each other for years!",
14
+ "You're not going to believe what I just heard.",
15
+ "How did you manage to get that stuck there?",
16
+ "The last time I saw that, things didn’t end well.",
17
+ "Wait, wasn’t that supposed to be a secret?",
18
+ "Why is everyone looking at us?",
19
+ "You promised you’d never bring that up again!",
20
+ "Guess what I found in the attic?",
21
+ "This isn't what it looks like, I swear!",
22
+ "That's the last place I'd expect to see you!",
23
+ "Did you just hear that noise too?",
24
+ "Remember when you dared me? Well, I did it.",
25
+ "Why is there a llama in the living room?",
26
+ "That's the exact opposite of what I told you to do!",
27
+ "Whose idea was it to bring the penguin?",
28
+ "You owe me big time for this one.",
29
+ "I thought you said you could juggle!",
30
+ "I've never seen anyone react to cake like that before.",
31
+ "That was supposed to be our little secret!",
32
+ "You won't believe who I bumped into at the market.",
33
+ "Where did all these chickens come from?",
34
+ "I might've accidentally set it to the wrong date.",
35
+ "I told you mixing those two was a bad idea!",
36
+ "You're holding it upside down, you know.",
37
+ "Why does that parrot keep calling your name?",
38
+ "You really thought that would impress me?",
39
+ "I never expected to see you in a tutu.",
40
+ "Someone's left a mysterious package at the door.",
41
+ "Oh, so that's where my missing sock went!",
42
+ "How do you always end up in these situations?",
43
+ "I've got some news you might not like.",
44
+ "Why do you have that map and shovel?",
45
+ "I've got a secret, but promise not to laugh!"
46
+ ]
47
+
48
 
49
  def set_openai_key(api_key):
50
  # Set up the OpenAI API key
51
  openai.api_key = api_key
52
 
53
+ def generate_statement(api_key, use_gpt=True):
54
  # Set the OpenAI API key using the provided input
55
  set_openai_key(api_key)
56
 
57
+ if use_gpt:
58
+ # Generate a statement using OpenAI's GPT 3.5 Turbo model
59
+ response = openai.Completion.create(
60
+ engine="gpt-3.5-turbo",
61
+ prompt="Provide a short and intriguing dialogue that can be incorporated into an improvisation scene to provoke unexpected reactions and drive the narrative in interesting directions.",
62
+ max_tokens=15
63
+ )
64
+ return response.choices[0].text.strip()
65
+ else:
66
+ # Return a random dialogue from the provided list
67
+ return random.choice(DIALOGUES)
68
 
69
  def main():
70
  # Define the UI components using gr.Interface
71
  interface = gr.Interface(
72
  fn=generate_statement, # Function to call on button press
73
+ inputs=["text", "checkbox"], # Input is a text field for API key and a checkbox for GPT option
74
  outputs="text", # Output is a text area
75
  live=False, # Only generate statement after button press
76
+ description="Enter your OpenAI API key and select whether to use GPT or get a random statement, then press the button."
77
  )
78
 
79
  # Launch the UI on Spaces