Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import spaces
|
| 2 |
+
import random
|
| 3 |
+
import openai
|
| 4 |
+
import gradio as gr
|
| 5 |
+
|
| 6 |
+
def generate_improv_scene(api_key):
|
| 7 |
+
# Initialize the OpenAI API client with the provided key
|
| 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 |
+
@spaces.use(gr.Interface)
|
| 29 |
+
def app():
|
| 30 |
+
# Create Gradio UI
|
| 31 |
+
iface = gr.Interface(
|
| 32 |
+
fn=generate_improv_scene,
|
| 33 |
+
inputs=["text"], # Input for the OpenAI API key
|
| 34 |
+
outputs=["text", "text", "text", "text", "text", "text"],
|
| 35 |
+
live=True,
|
| 36 |
+
title="Improv Scene Generator",
|
| 37 |
+
description="Generate a random improv scene with dialogue, emotion, situation, location, relationship, and occupation."
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
iface.launch()
|
| 41 |
+
|
| 42 |
+
app()
|