Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -51,20 +51,24 @@ def set_openai_key(api_key):
|
|
| 51 |
openai.api_key = api_key
|
| 52 |
|
| 53 |
def generate_statement(api_key, use_gpt):
|
| 54 |
-
|
| 55 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
def main():
|
| 69 |
# Define the UI components using gr.Interface
|
| 70 |
interface = gr.Interface(
|
|
|
|
| 51 |
openai.api_key = api_key
|
| 52 |
|
| 53 |
def generate_statement(api_key, use_gpt):
|
| 54 |
+
try:
|
| 55 |
+
# Set the OpenAI API key using the provided input
|
| 56 |
+
set_openai_key(api_key)
|
| 57 |
+
|
| 58 |
+
if use_gpt:
|
| 59 |
+
# Generate a statement using OpenAI's GPT 3.5 Turbo model
|
| 60 |
+
response = openai.Completion.create(
|
| 61 |
+
engine="gpt-3.5-turbo",
|
| 62 |
+
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.",
|
| 63 |
+
max_tokens=15
|
| 64 |
+
)
|
| 65 |
+
return response.choices[0].text.strip()
|
| 66 |
+
else:
|
| 67 |
+
# Return a random dialogue from the provided list
|
| 68 |
+
return random.choice(DIALOGUES)
|
| 69 |
+
except Exception as e:
|
| 70 |
+
return str(e)
|
| 71 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
def main():
|
| 73 |
# Define the UI components using gr.Interface
|
| 74 |
interface = gr.Interface(
|