Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,4 +1,93 @@
|
|
| 1 |
import streamlit as st
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
# App Title
|
| 4 |
st.title("StoryForge")
|
|
@@ -12,22 +101,46 @@ with st.sidebar:
|
|
| 12 |
game_environment = st.text_input("Game Environment", "Describe the setting of your game")
|
| 13 |
protagonist = st.text_input("Protagonist", "Describe the main character")
|
| 14 |
antagonist = st.text_input("Antagonist", "Describe the main villain or opposing force")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# Layout with two columns
|
| 17 |
col1, col2 = st.columns(2)
|
| 18 |
|
| 19 |
with col1:
|
| 20 |
st.header("Game Environment")
|
| 21 |
-
st.
|
|
|
|
|
|
|
|
|
|
| 22 |
|
| 23 |
with col2:
|
| 24 |
st.header("Game Story")
|
| 25 |
-
|
|
|
|
|
|
|
|
|
|
| 26 |
|
| 27 |
with col1:
|
| 28 |
st.header("Protagonist")
|
| 29 |
-
st.
|
|
|
|
|
|
|
|
|
|
| 30 |
|
| 31 |
with col2:
|
| 32 |
st.header("Antagonist")
|
| 33 |
-
st.
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
+
import anthropic
|
| 3 |
+
|
| 4 |
+
# Initialize the Anthropic client
|
| 5 |
+
client = anthropic.Anthropic()
|
| 6 |
+
|
| 7 |
+
# Define the functions to generate content
|
| 8 |
+
def generate_game_environment(environment_description):
|
| 9 |
+
message = client.messages.create(
|
| 10 |
+
model="claude-3-5-sonnet-20240620",
|
| 11 |
+
max_tokens=1000,
|
| 12 |
+
temperature=0.7,
|
| 13 |
+
system="You are an expert in world-building. Generate a detailed description of a game environment based on the input.",
|
| 14 |
+
messages=[
|
| 15 |
+
{
|
| 16 |
+
"role": "user",
|
| 17 |
+
"content": [
|
| 18 |
+
{
|
| 19 |
+
"type": "text",
|
| 20 |
+
"text": f"Create a detailed description of a game environment based on this input: {environment_description}"
|
| 21 |
+
}
|
| 22 |
+
]
|
| 23 |
+
}
|
| 24 |
+
]
|
| 25 |
+
)
|
| 26 |
+
return message.content
|
| 27 |
+
|
| 28 |
+
def generate_protagonist(protagonist_description):
|
| 29 |
+
message = client.messages.create(
|
| 30 |
+
model="claude-3-5-sonnet-20240620",
|
| 31 |
+
max_tokens=1000,
|
| 32 |
+
temperature=0.7,
|
| 33 |
+
system="You are an expert in character creation. Generate a detailed description of a game protagonist based on the input.",
|
| 34 |
+
messages=[
|
| 35 |
+
{
|
| 36 |
+
"role": "user",
|
| 37 |
+
"content": [
|
| 38 |
+
{
|
| 39 |
+
"type": "text",
|
| 40 |
+
"text": f"Create a detailed description of a game protagonist based on this input: {protagonist_description}"
|
| 41 |
+
}
|
| 42 |
+
]
|
| 43 |
+
}
|
| 44 |
+
]
|
| 45 |
+
)
|
| 46 |
+
return message.content
|
| 47 |
+
|
| 48 |
+
def generate_antagonist(antagonist_description):
|
| 49 |
+
message = client.messages.create(
|
| 50 |
+
model="claude-3-5-sonnet-20240620",
|
| 51 |
+
max_tokens=1000,
|
| 52 |
+
temperature=0.7,
|
| 53 |
+
system="You are an expert in villain creation. Generate a detailed description of a game antagonist based on the input.",
|
| 54 |
+
messages=[
|
| 55 |
+
{
|
| 56 |
+
"role": "user",
|
| 57 |
+
"content": [
|
| 58 |
+
{
|
| 59 |
+
"type": "text",
|
| 60 |
+
"text": f"Create a detailed description of a game antagonist based on this input: {antagonist_description}"
|
| 61 |
+
}
|
| 62 |
+
]
|
| 63 |
+
}
|
| 64 |
+
]
|
| 65 |
+
)
|
| 66 |
+
return message.content
|
| 67 |
+
|
| 68 |
+
def generate_game_story(environment, protagonist, antagonist):
|
| 69 |
+
story_prompt = (f"Create a detailed game story based on the following inputs:\n"
|
| 70 |
+
f"Game Environment: {environment}\n"
|
| 71 |
+
f"Protagonist: {protagonist}\n"
|
| 72 |
+
f"Antagonist: {antagonist}")
|
| 73 |
+
message = client.messages.create(
|
| 74 |
+
model="claude-3-5-sonnet-20240620",
|
| 75 |
+
max_tokens=1000,
|
| 76 |
+
temperature=0.7,
|
| 77 |
+
system="You are a master storyteller. Generate a detailed game story based on the inputs provided.",
|
| 78 |
+
messages=[
|
| 79 |
+
{
|
| 80 |
+
"role": "user",
|
| 81 |
+
"content": [
|
| 82 |
+
{
|
| 83 |
+
"type": "text",
|
| 84 |
+
"text": story_prompt
|
| 85 |
+
}
|
| 86 |
+
]
|
| 87 |
+
}
|
| 88 |
+
]
|
| 89 |
+
)
|
| 90 |
+
return message.content
|
| 91 |
|
| 92 |
# App Title
|
| 93 |
st.title("StoryForge")
|
|
|
|
| 101 |
game_environment = st.text_input("Game Environment", "Describe the setting of your game")
|
| 102 |
protagonist = st.text_input("Protagonist", "Describe the main character")
|
| 103 |
antagonist = st.text_input("Antagonist", "Describe the main villain or opposing force")
|
| 104 |
+
if st.button("Generate Document"):
|
| 105 |
+
# Generate content based on user input
|
| 106 |
+
env_description = generate_game_environment(game_environment)
|
| 107 |
+
protagonist_description = generate_protagonist(protagonist)
|
| 108 |
+
antagonist_description = generate_antagonist(antagonist)
|
| 109 |
+
game_story = generate_game_story(game_environment, protagonist, antagonist)
|
| 110 |
+
|
| 111 |
+
# Display generated content
|
| 112 |
+
st.session_state.env_description = env_description
|
| 113 |
+
st.session_state.protagonist_description = protagonist_description
|
| 114 |
+
st.session_state.antagonist_description = antagonist_description
|
| 115 |
+
st.session_state.game_story = game_story
|
| 116 |
|
| 117 |
# Layout with two columns
|
| 118 |
col1, col2 = st.columns(2)
|
| 119 |
|
| 120 |
with col1:
|
| 121 |
st.header("Game Environment")
|
| 122 |
+
if 'env_description' in st.session_state:
|
| 123 |
+
st.write(st.session_state.env_description)
|
| 124 |
+
else:
|
| 125 |
+
st.write(game_environment)
|
| 126 |
|
| 127 |
with col2:
|
| 128 |
st.header("Game Story")
|
| 129 |
+
if 'game_story' in st.session_state:
|
| 130 |
+
st.write(st.session_state.game_story)
|
| 131 |
+
else:
|
| 132 |
+
st.write("Your game story will be generated based on the inputs provided.")
|
| 133 |
|
| 134 |
with col1:
|
| 135 |
st.header("Protagonist")
|
| 136 |
+
if 'protagonist_description' in st.session_state:
|
| 137 |
+
st.write(st.session_state.protagonist_description)
|
| 138 |
+
else:
|
| 139 |
+
st.write(protagonist)
|
| 140 |
|
| 141 |
with col2:
|
| 142 |
st.header("Antagonist")
|
| 143 |
+
if 'antagonist_description' in st.session_state:
|
| 144 |
+
st.write(st.session_state.antagonist_description)
|
| 145 |
+
else:
|
| 146 |
+
st.write(antagonist)
|