Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,34 +1,140 @@
|
|
1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# Sidebar for user inputs
|
4 |
st.sidebar.header("Input Your Game Details")
|
5 |
st.sidebar.text("Please provide detailed and creative descriptions.")
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
|
14 |
# Main app title and description
|
15 |
st.title("Story Forger")
|
16 |
st.write("Developed by Salman Maqbool")
|
17 |
st.write("**Story Forger** is a tool for game developers to easily create detailed game design documents. Input your game environment, protagonist, and antagonist, and generate a solid foundation for your game's story.")
|
18 |
|
19 |
-
#
|
20 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
21 |
|
22 |
-
with col1:
|
23 |
-
|
24 |
-
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
|
29 |
-
with col2:
|
30 |
-
|
31 |
-
|
32 |
|
33 |
-
|
34 |
-
|
|
|
|
|
|
1 |
import streamlit as st
|
2 |
+
import anthropic
|
3 |
+
import os
|
4 |
+
from dotenv import load_dotenv
|
5 |
+
|
6 |
+
# Load API key from .env file
|
7 |
+
load_dotenv()
|
8 |
+
api_key = os.getenv("Claude_api_key")
|
9 |
+
|
10 |
+
# Initialize the Anthrop client
|
11 |
+
client = anthropic.Anthropic(api_key=api_key)
|
12 |
+
|
13 |
+
def extract_relevant_info(response):
|
14 |
+
"""Extract relevant information from the API response."""
|
15 |
+
return response['content'].strip()
|
16 |
+
|
17 |
+
def generate_game_environment(description):
|
18 |
+
message = client.messages.create(
|
19 |
+
model="claude-3-5-sonnet-20240620",
|
20 |
+
max_tokens=150,
|
21 |
+
temperature=0.7,
|
22 |
+
system="You are a world-class game designer. Respond only with detailed and creative descriptions of game environments.",
|
23 |
+
messages=[
|
24 |
+
{
|
25 |
+
"role": "user",
|
26 |
+
"content": [
|
27 |
+
{
|
28 |
+
"type": "text",
|
29 |
+
"text": f"Create a game environment based on the following description: {description}"
|
30 |
+
}
|
31 |
+
]
|
32 |
+
}
|
33 |
+
]
|
34 |
+
)
|
35 |
+
return extract_relevant_info(message)
|
36 |
+
|
37 |
+
def generate_protagonist(description):
|
38 |
+
message = client.messages.create(
|
39 |
+
model="claude-3-5-sonnet-20240620",
|
40 |
+
max_tokens=150,
|
41 |
+
temperature=0.7,
|
42 |
+
system="You are a world-class game designer. Respond only with detailed and creative descriptions of game protagonists.",
|
43 |
+
messages=[
|
44 |
+
{
|
45 |
+
"role": "user",
|
46 |
+
"content": [
|
47 |
+
{
|
48 |
+
"type": "text",
|
49 |
+
"text": f"Create a game protagonist based on the following description: {description}"
|
50 |
+
}
|
51 |
+
]
|
52 |
+
}
|
53 |
+
]
|
54 |
+
)
|
55 |
+
return extract_relevant_info(message)
|
56 |
+
|
57 |
+
def generate_antagonist(description):
|
58 |
+
message = client.messages.create(
|
59 |
+
model="claude-3-5-sonnet-20240620",
|
60 |
+
max_tokens=150,
|
61 |
+
temperature=0.7,
|
62 |
+
system="You are a world-class game designer. Respond only with detailed and creative descriptions of game antagonists.",
|
63 |
+
messages=[
|
64 |
+
{
|
65 |
+
"role": "user",
|
66 |
+
"content": [
|
67 |
+
{
|
68 |
+
"type": "text",
|
69 |
+
"text": f"Create a game antagonist based on the following description: {description}"
|
70 |
+
}
|
71 |
+
]
|
72 |
+
}
|
73 |
+
]
|
74 |
+
)
|
75 |
+
return extract_relevant_info(message)
|
76 |
+
|
77 |
+
def generate_game_story(environment, protagonist, antagonist):
|
78 |
+
message = client.messages.create(
|
79 |
+
model="claude-3-5-sonnet-20240620",
|
80 |
+
max_tokens=1000,
|
81 |
+
temperature=0.7,
|
82 |
+
system="You are a world-class game designer. Respond only with detailed and creative game story plots.",
|
83 |
+
messages=[
|
84 |
+
{
|
85 |
+
"role": "user",
|
86 |
+
"content": [
|
87 |
+
{
|
88 |
+
"type": "text",
|
89 |
+
"text": f"Create a game story plot based on the following: \n"
|
90 |
+
f"Environment: {environment}\n"
|
91 |
+
f"Protagonist: {protagonist}\n"
|
92 |
+
f"Antagonist: {antagonist}"
|
93 |
+
}
|
94 |
+
]
|
95 |
+
}
|
96 |
+
]
|
97 |
+
)
|
98 |
+
return extract_relevant_info(message)
|
99 |
|
100 |
# Sidebar for user inputs
|
101 |
st.sidebar.header("Input Your Game Details")
|
102 |
st.sidebar.text("Please provide detailed and creative descriptions.")
|
103 |
|
104 |
+
game_environment_input = st.sidebar.text_input("π Game Environment",
|
105 |
+
"Describe the setting of your game. Include details like time period, location, and atmosphere.")
|
106 |
+
protagonist_input = st.sidebar.text_input("π¦Έ Protagonist",
|
107 |
+
"Describe the main character. Include their background, motivations, and abilities.")
|
108 |
+
antagonist_input = st.sidebar.text_input("π¦Ή Antagonist",
|
109 |
+
"Describe the main enemy. Include their backstory, goals, and relationship with the protagonist.")
|
110 |
|
111 |
# Main app title and description
|
112 |
st.title("Story Forger")
|
113 |
st.write("Developed by Salman Maqbool")
|
114 |
st.write("**Story Forger** is a tool for game developers to easily create detailed game design documents. Input your game environment, protagonist, and antagonist, and generate a solid foundation for your game's story.")
|
115 |
|
116 |
+
# Generating the content based on user inputs
|
117 |
+
if st.sidebar.button("Generate"):
|
118 |
+
if game_environment_input and protagonist_input and antagonist_input:
|
119 |
+
game_environment = generate_game_environment(game_environment_input)
|
120 |
+
protagonist = generate_protagonist(protagonist_input)
|
121 |
+
antagonist = generate_antagonist(antagonist_input)
|
122 |
+
game_story = generate_game_story(game_environment, protagonist, antagonist)
|
123 |
+
|
124 |
+
col1, col2 = st.columns(2)
|
125 |
|
126 |
+
with col1:
|
127 |
+
st.subheader("π Game Environment")
|
128 |
+
st.write(game_environment)
|
129 |
+
|
130 |
+
st.subheader("π¦Έ Protagonist")
|
131 |
+
st.write(protagonist)
|
132 |
|
133 |
+
with col2:
|
134 |
+
st.subheader("π Game Story")
|
135 |
+
st.write(game_story)
|
136 |
|
137 |
+
st.subheader("π¦Ή Antagonist")
|
138 |
+
st.write(antagonist)
|
139 |
+
else:
|
140 |
+
st.error("Please fill in all the details in the sidebar before generating.")
|