Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,32 +4,20 @@ import openai
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
def generate_improv_scene(api_key):
|
| 7 |
-
#
|
| 8 |
-
openai.api_key = api_key
|
| 9 |
-
|
| 10 |
-
locations = ["beach", "outer space", "classroom", "pirate ship", "hospital", "concert stage", "underwater dome", "prehistoric cave", "unicorn land"]
|
| 11 |
-
emotions = ["happy", "angry", "confused", "elated", "sad", "anxious", "bemused", "bewildered"]
|
| 12 |
-
relationships = ["siblings", "co-workers", "friends", "enemies", "strangers", "parent and child", "alien and astronaut", "wizard and muggle"]
|
| 13 |
-
situations = ["finding a hidden portal", "preparing for an intergalactic festival", "solving the riddle of a talking frog", "escaping from a time loop", "organizing a dragon race", "trying to sell sand in a desert", "teaching dance to robots"]
|
| 14 |
-
occupations = ["astronaut", "dragon tamer", "unicorn whisperer", "intergalactic chef", "time traveler", "wizard", "robotic engineer", "underwater archaeologist"]
|
| 15 |
-
|
| 16 |
-
location, situation, occupation = random.sample(locations, 1)[0], random.sample(situations, 1)[0], random.sample(occupations, 1)[0]
|
| 17 |
-
emotion = random.choice(emotions)
|
| 18 |
-
relationship = random.choice(relationships)
|
| 19 |
-
|
| 20 |
-
# Generate a line/dialogue using OpenAI API
|
| 21 |
-
dialogue_prompt = "Create an unrelated and random line spoken by a character."
|
| 22 |
-
response = openai.Completion.create(engine="text-davinci-003", prompt=dialogue_prompt, max_tokens=150)
|
| 23 |
-
dialogue = response.choices[0].text.strip()
|
| 24 |
-
|
| 25 |
-
# Return the desired elements as a tuple
|
| 26 |
-
return dialogue, emotion, situation, location, relationship, occupation
|
| 27 |
|
| 28 |
# Create Gradio UI
|
| 29 |
iface = gr.Interface(
|
| 30 |
fn=generate_improv_scene,
|
| 31 |
inputs=["text"], # Input for OpenAI API Key
|
| 32 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
live=True,
|
| 34 |
title="Improv Scene Generator",
|
| 35 |
description="Generate a random improv scene with dialogue, emotion, situation, location, relationship, and occupation."
|
|
|
|
| 4 |
import gradio as gr
|
| 5 |
|
| 6 |
def generate_improv_scene(api_key):
|
| 7 |
+
# ... (rest of your code remains unchanged)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# Create Gradio UI
|
| 10 |
iface = gr.Interface(
|
| 11 |
fn=generate_improv_scene,
|
| 12 |
inputs=["text"], # Input for OpenAI API Key
|
| 13 |
+
outputs=[
|
| 14 |
+
gr.outputs.Textbox(label="dialogue"),
|
| 15 |
+
gr.outputs.Textbox(label="emotion"),
|
| 16 |
+
gr.outputs.Textbox(label="situation"),
|
| 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="Improv Scene Generator",
|
| 23 |
description="Generate a random improv scene with dialogue, emotion, situation, location, relationship, and occupation."
|