Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,104 +1,154 @@
|
|
|
|
1 |
import streamlit as st
|
2 |
import anthropic
|
3 |
-
import os
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
# Load environment variables from .env file
|
7 |
load_dotenv()
|
8 |
|
9 |
-
# API
|
10 |
-
|
11 |
-
|
12 |
-
|
|
|
13 |
|
14 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
15 |
|
16 |
-
|
17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
system=(
|
26 |
-
"You are a creative writer. Based on the following description, "
|
27 |
-
"generate content for a game design document: {prompt}"
|
28 |
-
),
|
29 |
messages=[
|
30 |
-
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
31 |
]
|
32 |
)
|
33 |
-
return
|
34 |
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
44 |
)
|
|
|
|
|
|
|
|
|
45 |
|
46 |
-
|
47 |
-
|
48 |
-
st.header("Game Details")
|
49 |
-
image_description = st.text_area(
|
50 |
-
"Game Environment",
|
51 |
-
placeholder="Describe the setting of your game",
|
52 |
-
height=100
|
53 |
-
)
|
54 |
-
protagonist_description = st.text_area(
|
55 |
-
"Protagonist",
|
56 |
-
placeholder="Describe the main character",
|
57 |
-
height=100
|
58 |
-
)
|
59 |
-
antagonist_description = st.text_area(
|
60 |
-
"Antagonist",
|
61 |
-
placeholder="Describe the main villain or opposing force",
|
62 |
-
height=100
|
63 |
-
)
|
64 |
-
generate_text_btn = st.button("Generate Document")
|
65 |
|
66 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
|
68 |
-
|
69 |
-
|
70 |
-
if generate_text_btn and image_description:
|
71 |
-
with st.spinner("Generating game environment description..."):
|
72 |
-
generated_environment = generate_text(
|
73 |
-
f"Generate a detailed description of a game environment based on this theme and setting: {image_description}"
|
74 |
-
)
|
75 |
-
st.markdown(generated_environment)
|
76 |
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
st.markdown(generated_protagonist)
|
84 |
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
)
|
92 |
-
st.markdown(generated_story)
|
93 |
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
st.markdown(generated_antagonist)
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
|
|
|
|
|
|
|
1 |
+
import os
|
2 |
import streamlit as st
|
3 |
import anthropic
|
|
|
4 |
from dotenv import load_dotenv
|
5 |
|
6 |
# Load environment variables from .env file
|
7 |
load_dotenv()
|
8 |
|
9 |
+
# Retrieve the API key from environment variables
|
10 |
+
api_key = os.getenv("Claude_api_key")
|
11 |
+
|
12 |
+
# Initialize the Anthropic client with the API key
|
13 |
+
client = anthropic.Anthropic(api_key=api_key)
|
14 |
|
15 |
+
# Define the functions to generate content
|
16 |
+
def generate_game_environment(environment_description):
|
17 |
+
message = client.messages.create(
|
18 |
+
model="claude-3-5-sonnet-20240620",
|
19 |
+
max_tokens=150,
|
20 |
+
temperature=0.7,
|
21 |
+
system="You are an expert in world-building. Generate a detailed description of a game environment based on the input.",
|
22 |
+
messages=[
|
23 |
+
{
|
24 |
+
"role": "user",
|
25 |
+
"content": [
|
26 |
+
{
|
27 |
+
"type": "text",
|
28 |
+
"text": f"Create a detailed description of a game environment based on this input: {environment_description}"
|
29 |
+
}
|
30 |
+
]
|
31 |
+
}
|
32 |
+
]
|
33 |
+
)
|
34 |
+
return message.content[0].text
|
35 |
|
36 |
+
def generate_protagonist(protagonist_description):
|
37 |
+
message = client.messages.create(
|
38 |
+
model="claude-3-5-sonnet-20240620",
|
39 |
+
max_tokens=150,
|
40 |
+
temperature=0.7,
|
41 |
+
system="You are an expert in character creation. Generate a detailed description of a game protagonist based on the input.",
|
42 |
+
messages=[
|
43 |
+
{
|
44 |
+
"role": "user",
|
45 |
+
"content": [
|
46 |
+
{
|
47 |
+
"type": "text",
|
48 |
+
"text": f"Create a detailed description of a game protagonist based on this input: {protagonist_description}"
|
49 |
+
}
|
50 |
+
]
|
51 |
+
}
|
52 |
+
]
|
53 |
+
)
|
54 |
+
return message.content[0].text
|
55 |
|
56 |
+
def generate_antagonist(antagonist_description):
|
57 |
+
message = client.messages.create(
|
58 |
+
model="claude-3-5-sonnet-20240620",
|
59 |
+
max_tokens=150,
|
60 |
+
temperature=0.7,
|
61 |
+
system="You are an expert in villain creation. Generate a detailed description of a game antagonist based on the input.",
|
|
|
|
|
|
|
|
|
62 |
messages=[
|
63 |
+
{
|
64 |
+
"role": "user",
|
65 |
+
"content": [
|
66 |
+
{
|
67 |
+
"type": "text",
|
68 |
+
"text": f"Create a detailed description of a game antagonist based on this input: {antagonist_description}"
|
69 |
+
}
|
70 |
+
]
|
71 |
+
}
|
72 |
]
|
73 |
)
|
74 |
+
return message.content[0].text
|
75 |
|
76 |
+
def generate_game_story(environment, protagonist, antagonist):
|
77 |
+
story_prompt = (f"Create a detailed game story based on the following inputs:\n"
|
78 |
+
f"Game Environment: {environment}\n"
|
79 |
+
f"Protagonist: {protagonist}\n"
|
80 |
+
f"Antagonist: {antagonist}")
|
81 |
+
message = client.messages.create(
|
82 |
+
model="claude-3-5-sonnet-20240620",
|
83 |
+
max_tokens= 150,
|
84 |
+
temperature=0.7,
|
85 |
+
system="You are a master storyteller. Generate a detailed game story based on the inputs provided.",
|
86 |
+
messages=[
|
87 |
+
{
|
88 |
+
"role": "user",
|
89 |
+
"content": [
|
90 |
+
{
|
91 |
+
"type": "text",
|
92 |
+
"text": story_prompt
|
93 |
+
}
|
94 |
+
]
|
95 |
+
}
|
96 |
+
]
|
97 |
)
|
98 |
+
return message.content[0].text
|
99 |
+
|
100 |
+
# App Title
|
101 |
+
st.title("StoryForge")
|
102 |
|
103 |
+
# App Description
|
104 |
+
st.write("StoryForge helps game developers generate comprehensive Game Design Documents. Input details about your game environment, protagonist, and antagonist to create a structured design document.")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
|
106 |
+
# Sidebar Inputs
|
107 |
+
with st.sidebar:
|
108 |
+
st.header("Game Details")
|
109 |
+
game_environment = st.text_input("Game Environment", "Describe the setting of your game")
|
110 |
+
protagonist = st.text_input("Protagonist", "Describe the main character")
|
111 |
+
antagonist = st.text_input("Antagonist", "Describe the main villain or opposing force")
|
112 |
+
if st.button("Generate Document"):
|
113 |
+
# Generate content based on user input
|
114 |
+
env_description = generate_game_environment(game_environment)
|
115 |
+
protagonist_description = generate_protagonist(protagonist)
|
116 |
+
antagonist_description = generate_antagonist(antagonist)
|
117 |
+
game_story = generate_game_story(game_environment, protagonist, antagonist)
|
118 |
+
|
119 |
+
# Store results in session state
|
120 |
+
st.session_state.env_description = env_description
|
121 |
+
st.session_state.protagonist_description = protagonist_description
|
122 |
+
st.session_state.antagonist_description = antagonist_description
|
123 |
+
st.session_state.game_story = game_story
|
124 |
|
125 |
+
# Layout with two columns
|
126 |
+
col1, col2 = st.columns(2)
|
|
|
|
|
|
|
|
|
|
|
|
|
127 |
|
128 |
+
with col1:
|
129 |
+
st.header("Game Environment")
|
130 |
+
if 'env_description' in st.session_state:
|
131 |
+
st.write(st.session_state.env_description)
|
132 |
+
else:
|
133 |
+
st.write(game_environment)
|
|
|
134 |
|
135 |
+
with col2:
|
136 |
+
st.header("Game Story")
|
137 |
+
if 'game_story' in st.session_state:
|
138 |
+
st.write(st.session_state.game_story)
|
139 |
+
else:
|
140 |
+
st.write("Your game story will be generated based on the inputs provided.")
|
|
|
|
|
141 |
|
142 |
+
with col1:
|
143 |
+
st.header("Protagonist")
|
144 |
+
if 'protagonist_description' in st.session_state:
|
145 |
+
st.write(st.session_state.protagonist_description)
|
146 |
+
else:
|
147 |
+
st.write(protagonist)
|
|
|
148 |
|
149 |
+
with col2:
|
150 |
+
st.header("Antagonist")
|
151 |
+
if 'antagonist_description' in st.session_state:
|
152 |
+
st.write(st.session_state.antagonist_description)
|
153 |
+
else:
|
154 |
+
st.write(antagonist)
|