Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,109 @@
|
|
|
|
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# Sidebar Inputs
|
4 |
st.sidebar.title("StoryForge Input")
|
@@ -19,19 +124,30 @@ antagonist = st.sidebar.text_input(
|
|
19 |
st.title("StoryForge")
|
20 |
st.write("StoryForge is your tool for crafting comprehensive Game Design Documents. Enter your game's details, and StoryForge will generate a structured document to guide your development process.")
|
21 |
|
22 |
-
#
|
23 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
st.write(environment)
|
28 |
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
-
|
33 |
-
|
34 |
-
|
|
|
35 |
|
36 |
-
st.subheader("Antagonist")
|
37 |
-
st.write(antagonist)
|
|
|
1 |
+
import os
|
2 |
+
from dotenv import load_dotenv
|
3 |
import streamlit as st
|
4 |
+
import anthropic
|
5 |
+
|
6 |
+
# Load environment variables from .env file
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
# Set your Anthropic API key
|
10 |
+
API_KEY = os.getenv("ANTHROPIC_API_KEY")
|
11 |
+
|
12 |
+
# Define functions to generate content using the Anthropic API
|
13 |
+
def generate_game_environment(environment_description):
|
14 |
+
client = anthropic.Anthropic(api_key=API_KEY)
|
15 |
+
|
16 |
+
message = client.messages.create(
|
17 |
+
model="claude-3-5-sonnet-20240620",
|
18 |
+
max_tokens=150,
|
19 |
+
temperature=0.7,
|
20 |
+
system="You are an expert game designer. Create a detailed description of the game environment.",
|
21 |
+
messages=[
|
22 |
+
{
|
23 |
+
"role": "user",
|
24 |
+
"content": [
|
25 |
+
{
|
26 |
+
"type": "text",
|
27 |
+
"text": f"Describe the game environment based on: {environment_description}"
|
28 |
+
}
|
29 |
+
]
|
30 |
+
}
|
31 |
+
]
|
32 |
+
)
|
33 |
+
|
34 |
+
return message['content'] # Return the relevant content
|
35 |
+
|
36 |
+
def generate_game_story(environment, protagonist, antagonist):
|
37 |
+
client = anthropic.Anthropic(api_key=API_KEY)
|
38 |
+
|
39 |
+
message = client.messages.create(
|
40 |
+
model="claude-3-5-sonnet-20240620",
|
41 |
+
max_tokens=150,
|
42 |
+
temperature=0.7,
|
43 |
+
system="You are an expert game storyteller. Create an engaging game story.",
|
44 |
+
messages=[
|
45 |
+
{
|
46 |
+
"role": "user",
|
47 |
+
"content": [
|
48 |
+
{
|
49 |
+
"type": "text",
|
50 |
+
"text": f"Create a game story based on the following elements:\n"
|
51 |
+
f"Environment: {environment}\n"
|
52 |
+
f"Protagonist: {protagonist}\n"
|
53 |
+
f"Antagonist: {antagonist}"
|
54 |
+
}
|
55 |
+
]
|
56 |
+
}
|
57 |
+
]
|
58 |
+
)
|
59 |
+
|
60 |
+
return message['content'] # Return the relevant content
|
61 |
+
|
62 |
+
def generate_protagonist(protagonist_description):
|
63 |
+
client = anthropic.Anthropic(api_key=API_KEY)
|
64 |
+
|
65 |
+
message = client.messages.create(
|
66 |
+
model="claude-3-5-sonnet-20240620",
|
67 |
+
max_tokens=150,
|
68 |
+
temperature=0.7,
|
69 |
+
system="You are an expert character designer. Create a detailed description of the game's protagonist.",
|
70 |
+
messages=[
|
71 |
+
{
|
72 |
+
"role": "user",
|
73 |
+
"content": [
|
74 |
+
{
|
75 |
+
"type": "text",
|
76 |
+
"text": f"Describe the protagonist based on: {protagonist_description}"
|
77 |
+
}
|
78 |
+
]
|
79 |
+
}
|
80 |
+
]
|
81 |
+
)
|
82 |
+
|
83 |
+
return message['content'] # Return the relevant content
|
84 |
+
|
85 |
+
def generate_antagonist(antagonist_description):
|
86 |
+
client = anthropic.Anthropic(api_key=API_KEY)
|
87 |
+
|
88 |
+
message = client.messages.create(
|
89 |
+
model="claude-3-5-sonnet-20240620",
|
90 |
+
max_tokens=150,
|
91 |
+
temperature=0.7,
|
92 |
+
system="You are an expert character designer. Create a detailed description of the game's antagonist.",
|
93 |
+
messages=[
|
94 |
+
{
|
95 |
+
"role": "user",
|
96 |
+
"content": [
|
97 |
+
{
|
98 |
+
"type": "text",
|
99 |
+
"text": f"Describe the antagonist based on: {antagonist_description}"
|
100 |
+
}
|
101 |
+
]
|
102 |
+
}
|
103 |
+
]
|
104 |
+
)
|
105 |
+
|
106 |
+
return message['content'] # Return the relevant content
|
107 |
|
108 |
# Sidebar Inputs
|
109 |
st.sidebar.title("StoryForge Input")
|
|
|
124 |
st.title("StoryForge")
|
125 |
st.write("StoryForge is your tool for crafting comprehensive Game Design Documents. Enter your game's details, and StoryForge will generate a structured document to guide your development process.")
|
126 |
|
127 |
+
# Generate the content when the user has filled in all fields
|
128 |
+
if environment and protagonist and antagonist:
|
129 |
+
# Generate content
|
130 |
+
generated_environment = generate_game_environment(environment)
|
131 |
+
generated_protagonist = generate_protagonist(protagonist)
|
132 |
+
generated_antagonist = generate_antagonist(antagonist)
|
133 |
+
generated_story = generate_game_story(generated_environment, generated_protagonist, generated_antagonist)
|
134 |
+
|
135 |
+
# Columns for Outputs
|
136 |
+
col1, col2 = st.columns(2)
|
137 |
+
|
138 |
+
with col1:
|
139 |
+
st.subheader("Game Environment")
|
140 |
+
st.write(generated_environment)
|
141 |
|
142 |
+
st.subheader("Protagonist")
|
143 |
+
st.write(generated_protagonist)
|
|
|
144 |
|
145 |
+
with col2:
|
146 |
+
st.subheader("Game Story")
|
147 |
+
st.write(generated_story)
|
148 |
|
149 |
+
st.subheader("Antagonist")
|
150 |
+
st.write(generated_antagonist)
|
151 |
+
else:
|
152 |
+
st.write("Please fill in all the fields in the sidebar to generate your Game Design Document.")
|
153 |
|
|
|
|