Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2,11 +2,11 @@ import gradio as gr
|
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
| 4 |
|
| 5 |
-
#
|
| 6 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
client = OpenAI(api_key=api_key)
|
| 8 |
|
| 9 |
-
#
|
| 10 |
initial_scenario = "You wake up in a strange forest. Paths lead in all directions."
|
| 11 |
default_choices = [
|
| 12 |
"Walk north into the dense forest.",
|
|
@@ -15,7 +15,7 @@ default_choices = [
|
|
| 15 |
"Move west where the land rises."
|
| 16 |
]
|
| 17 |
|
| 18 |
-
#
|
| 19 |
system_prompt = {
|
| 20 |
"role": "system",
|
| 21 |
"content": (
|
|
@@ -25,7 +25,6 @@ system_prompt = {
|
|
| 25 |
)
|
| 26 |
}
|
| 27 |
|
| 28 |
-
# Global story and history state
|
| 29 |
history = [system_prompt, {"role": "user", "content": initial_scenario}]
|
| 30 |
story_log = initial_scenario
|
| 31 |
|
|
@@ -79,9 +78,8 @@ def restart_game():
|
|
| 79 |
return [story_log] + default_choices
|
| 80 |
|
| 81 |
|
| 82 |
-
# Gradio UI
|
| 83 |
with gr.Blocks() as app:
|
| 84 |
-
gr.Markdown("##
|
| 85 |
|
| 86 |
story_display = gr.Textbox(value=initial_scenario, lines=20, interactive=False, label="Your Story")
|
| 87 |
|
|
|
|
| 2 |
import os
|
| 3 |
from openai import OpenAI
|
| 4 |
|
| 5 |
+
# load API key
|
| 6 |
api_key = os.getenv("OPENAI_API_KEY")
|
| 7 |
client = OpenAI(api_key=api_key)
|
| 8 |
|
| 9 |
+
# initial game scenario
|
| 10 |
initial_scenario = "You wake up in a strange forest. Paths lead in all directions."
|
| 11 |
default_choices = [
|
| 12 |
"Walk north into the dense forest.",
|
|
|
|
| 15 |
"Move west where the land rises."
|
| 16 |
]
|
| 17 |
|
| 18 |
+
# template prompt
|
| 19 |
system_prompt = {
|
| 20 |
"role": "system",
|
| 21 |
"content": (
|
|
|
|
| 25 |
)
|
| 26 |
}
|
| 27 |
|
|
|
|
| 28 |
history = [system_prompt, {"role": "user", "content": initial_scenario}]
|
| 29 |
story_log = initial_scenario
|
| 30 |
|
|
|
|
| 78 |
return [story_log] + default_choices
|
| 79 |
|
| 80 |
|
|
|
|
| 81 |
with gr.Blocks() as app:
|
| 82 |
+
gr.Markdown("## Text-Based RPG Adventure")
|
| 83 |
|
| 84 |
story_display = gr.Textbox(value=initial_scenario, lines=20, interactive=False, label="Your Story")
|
| 85 |
|