Spaces:
Sleeping
Sleeping
File size: 5,146 Bytes
3ace78a 431280c 3ace78a e8bd320 3ace78a e8bd320 3ace78a e8bd320 3ace78a e8bd320 431280c 3ace78a 431280c 3ace78a 431280c 3ace78a 431280c 3ace78a 431280c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 |
import os
from dotenv import load_dotenv
import streamlit as st
import anthropic
# Load environment variables from .env file
load_dotenv()
# Set your Anthropic API key
API_KEY = os.getenv("ANTHROPIC_API_KEY")
# Define functions to generate content using the Anthropic API
def generate_game_environment(environment_description):
client = anthropic.Anthropic(api_key=API_KEY)
message = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=150,
temperature=0.7,
system="You are an expert game designer. Create a detailed description of the game environment.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": f"Describe the game environment based on: {environment_description}"
}
]
}
]
)
return message.content[0].text # Return the relevant content
def generate_game_story(environment, protagonist, antagonist):
client = anthropic.Anthropic(api_key=API_KEY)
message = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=150,
temperature=0.7,
system="You are an expert game storyteller. Create an engaging game story.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": f"Create a game story based on the following elements:\n"
f"Environment: {environment}\n"
f"Protagonist: {protagonist}\n"
f"Antagonist: {antagonist}"
}
]
}
]
)
return message.content[0].text # Return the relevant content
def generate_protagonist(protagonist_description):
client = anthropic.Anthropic(api_key=API_KEY)
message = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=150,
temperature=0.7,
system="You are an expert character designer. Create a detailed description of the game's protagonist.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": f"Describe the protagonist based on: {protagonist_description}"
}
]
}
]
)
return message.content[0].text # Return the relevant content
def generate_antagonist(antagonist_description):
client = anthropic.Anthropic(api_key=API_KEY)
message = client.messages.create(
model="claude-3-5-sonnet-20240620",
max_tokens=150,
temperature=0.7,
system="You are an expert character designer. Create a detailed description of the game's antagonist.",
messages=[
{
"role": "user",
"content": [
{
"type": "text",
"text": f"Describe the antagonist based on: {antagonist_description}"
}
]
}
]
)
return message.content[0].text # Return the relevant content
# Sidebar Inputs
st.sidebar.title("StoryForge Input")
environment = st.sidebar.text_input(
"Game Environment",
"Enter a detailed description of the game's world, including key locations, atmosphere, and overall tone."
)
protagonist = st.sidebar.text_input(
"Protagonist",
"Describe the main character, including their background, personality traits, goals, and what makes them unique."
)
antagonist = st.sidebar.text_input(
"Antagonist",
"Provide details about the main villain or opposing force, including their motivations, strengths, and weaknesses."
)
# Main App
st.title("StoryForge")
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.")
# Generate the content when the user has filled in all fields
if environment and protagonist and antagonist:
# Generate content
generated_environment = generate_game_environment(environment)
generated_protagonist = generate_protagonist(protagonist)
generated_antagonist = generate_antagonist(antagonist)
generated_story = generate_game_story(generated_environment, generated_protagonist, generated_antagonist)
# Columns for Outputs
col1, col2 = st.columns(2)
with col1:
st.subheader("Game Environment")
st.write(generated_environment)
st.subheader("Protagonist")
st.write(generated_protagonist)
with col2:
st.subheader("Game Story")
st.write(generated_story)
st.subheader("Antagonist")
st.write(generated_antagonist)
else:
st.write("Please fill in all the fields in the sidebar to generate your Game Design Document.")
|