Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,80 +1,106 @@
|
|
| 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 |
-
generated_plot = generate_text(f"Generate a short game plot with a hook, gameplay relation, sticky mechanics, and setting based on this description: {image_description}")
|
| 76 |
-
st.markdown(generated_plot)
|
| 77 |
-
|
| 78 |
-
# Run Main Function
|
| 79 |
-
if __name__ == "__main__":
|
| 80 |
-
main()
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import anthropic
|
| 3 |
+
import os
|
| 4 |
+
from dotenv import load_dotenv
|
| 5 |
|
| 6 |
+
# Load environment variables
|
| 7 |
+
load_dotenv()
|
| 8 |
|
| 9 |
+
# API keys
|
| 10 |
+
claude_api_key = os.getenv("ANTHROPIC_API_KEY")
|
| 11 |
|
| 12 |
+
# Initialize Claude AI client
|
| 13 |
+
client = anthropic.Anthropic(api_key=claude_api_key)
|
| 14 |
|
| 15 |
+
# Function to generate text using Claude AI
|
| 16 |
+
def generate_text(prompt, model_name="claude-3-opus-20240229"):
|
| 17 |
+
response = client.messages.create(
|
| 18 |
+
model=model_name,
|
| 19 |
+
max_tokens=500,
|
| 20 |
+
temperature=0.5,
|
| 21 |
+
system=(
|
| 22 |
+
"You are a creative writer. Based on the following description, "
|
| 23 |
+
"generate content for a game design document: {prompt}"
|
| 24 |
+
),
|
| 25 |
+
messages=[
|
| 26 |
+
{"role": "user", "content": [{"type": "text", "text": prompt}]}
|
| 27 |
+
]
|
| 28 |
+
)
|
| 29 |
+
return response.content[0].text
|
| 30 |
|
| 31 |
+
# Main Function
|
| 32 |
+
def main():
|
| 33 |
+
st.set_page_config(page_title="StoryForge", layout="wide")
|
| 34 |
+
st.title("StoryForge")
|
| 35 |
|
| 36 |
+
# Sidebar for user input
|
| 37 |
+
with st.sidebar:
|
| 38 |
+
st.header("Controls")
|
| 39 |
+
image_description = st.text_area(
|
| 40 |
+
"Set the foundation for the game world by providing a detailed and imaginative description of the overall theme, setting, and gameplay elements.",
|
| 41 |
+
height=100
|
| 42 |
+
)
|
| 43 |
+
protagonist_description = st.text_area(
|
| 44 |
+
"Introduce the main character of the game. Describe their appearance, personality, strengths, and weaknesses. What makes them unique and interesting?",
|
| 45 |
+
height=100
|
| 46 |
+
)
|
| 47 |
+
antagonist_description = st.text_area(
|
| 48 |
+
"Describe the primary antagonist or enemy in the game. What are their motivations, abilities, and characteristics? How do they pose a challenge to the protagonist?",
|
| 49 |
+
height=100
|
| 50 |
+
)
|
| 51 |
+
generate_text_btn = st.button("Generate Game Design")
|
| 52 |
|
| 53 |
+
col1, col2 = st.columns(2)
|
| 54 |
|
| 55 |
+
with col1:
|
| 56 |
+
st.markdown(
|
| 57 |
+
"*StoryForge* is a cutting-edge AI app designed to empower *game developers* and creators. "
|
| 58 |
+
"With StoryForge, you can effortlessly craft captivating game design documents. "
|
| 59 |
+
"From crafting immersive storylines and intricate plots to defining compelling protagonists and antagonists, "
|
| 60 |
+
"StoryForge unlocks your creative potential and streamlines the game design process."
|
| 61 |
+
)
|
| 62 |
|
| 63 |
+
st.subheader("Game Environment")
|
| 64 |
+
if generate_text_btn and image_description:
|
| 65 |
+
with st.spinner("Generating game environment description..."):
|
| 66 |
+
generated_environment = generate_text(
|
| 67 |
+
f"Generate a detailed description of a game environment based on this theme and setting: {image_description}"
|
| 68 |
+
)
|
| 69 |
+
st.markdown(generated_environment)
|
| 70 |
|
| 71 |
+
st.subheader("Antagonist")
|
| 72 |
+
if generate_text_btn and antagonist_description:
|
| 73 |
+
with st.spinner("Generating antagonist description..."):
|
| 74 |
+
generated_antagonist = generate_text(
|
| 75 |
+
f"Generate a detailed description of a game antagonist based on this description: {antagonist_description}"
|
| 76 |
+
)
|
| 77 |
+
st.markdown(generated_antagonist)
|
| 78 |
|
| 79 |
+
with col2:
|
| 80 |
+
st.subheader("Story")
|
| 81 |
+
if generate_text_btn and image_description:
|
| 82 |
+
with st.spinner("Generating game story..."):
|
| 83 |
+
generated_story = generate_text(
|
| 84 |
+
f"Create a creative and engaging game story that includes a protagonist, antagonist, and a challenge based on this description: {image_description}"
|
| 85 |
+
)
|
| 86 |
+
st.markdown(generated_story)
|
| 87 |
|
| 88 |
+
st.subheader("Protagonist")
|
| 89 |
+
if generate_text_btn and protagonist_description:
|
| 90 |
+
with st.spinner("Generating protagonist description..."):
|
| 91 |
+
generated_protagonist = generate_text(
|
| 92 |
+
f"Generate a detailed description of a game protagonist based on this description: {protagonist_description}"
|
| 93 |
+
)
|
| 94 |
+
st.markdown(generated_protagonist)
|
| 95 |
|
| 96 |
+
st.subheader("Game Plot")
|
| 97 |
+
if generate_text_btn and image_description:
|
| 98 |
+
with st.spinner("Generating game plot..."):
|
| 99 |
+
generated_plot = generate_text(
|
| 100 |
+
f"Generate a short game plot with a hook, gameplay relation, sticky mechanics, and setting based on this description: {image_description}"
|
| 101 |
+
)
|
| 102 |
+
st.markdown(generated_plot)
|
| 103 |
|
| 104 |
+
# Run Main Function
|
| 105 |
+
if __name__ == "__main__":
|
| 106 |
+
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|