import os from dotenv import load_dotenv import streamlit as st import anthropic # Load environment variables from .env file load_dotenv() API_KEY = os.getenv("CLAUDE_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." ) # Generate Documents Button if st.sidebar.button("Generate Documents"): 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) # Main App Title and Description 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.") # 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.sidebar.error("Please fill in all the fields to generate your Game Design Document.") else: # If button is not pressed, still display the main title and description 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.")