sainkan commited on
Commit
92ba273
·
verified ·
1 Parent(s): 11d601a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +92 -66
app.py CHANGED
@@ -1,80 +1,106 @@
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=f"You are a creative writer. Based on the following description, generate content for a game design document: {prompt}",
22
- messages=[
23
- {"role": "user", "content": [{"type": "text", "text": prompt}]}
24
- ]
25
- )
26
- return response.content[0].text
 
 
 
27
 
28
- # Main Function
29
- def main():
30
- st.set_page_config(page_title="StoryForge", layout="wide")
31
- st.title("StoryForge")
32
 
33
- # Sidebar for user input
34
- with st.sidebar:
35
- st.header("Controls")
36
- image_description = st.text_area("Set the foundation for the game world by providing a detailed and imaginative description of the overall theme, setting, and gameplay elements.", height=100)
37
- protagonist_description = st.text_area("Introduce the main character of the game. Describe their appearance, personality, strengths, and weaknesses. What makes them unique and interesting?", height=100)
38
- antagonist_description = st.text_area("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?", height=100)
 
 
 
 
 
 
 
 
 
 
39
 
40
- generate_text_btn = st.button("Generate Game Design")
41
 
42
- col1, col2 = st.columns(2)
 
 
 
 
 
 
43
 
44
- with col1:
45
- st.markdown("*StoryForge* is a cutting-edge AI app designed to empower *game developers* and creators. With StoryForge, you can effortlessly craft captivating game design documents. From crafting immersive storylines and intricate plots to defining compelling protagonists and antagonists, StoryForge unlocks your creative potential and streamlines the game design process.")
 
 
 
 
 
46
 
47
- st.subheader("Game Environment")
48
- if generate_text_btn and image_description:
49
- with st.spinner("Generating game environment description..."):
50
- generated_environment = generate_text(f"Generate a detailed description of a game environment based on this theme and setting: {image_description}")
51
- st.markdown(generated_environment)
 
 
52
 
53
- st.subheader("Antagonist")
54
- if generate_text_btn and antagonist_description:
55
- with st.spinner("Generating antagonist description..."):
56
- generated_antagonist = generate_text(f"Generate a detailed description of a game antagonist based on this description: {antagonist_description}")
57
- st.markdown(generated_antagonist)
 
 
 
58
 
59
- with col2:
60
- st.subheader("Story")
61
- if generate_text_btn and image_description:
62
- with st.spinner("Generating game story..."):
63
- generated_story = generate_text(f"Create a creative and engaging game story that includes a protagonist, antagonist, and a challenge based on this description: {image_description}")
64
- st.markdown(generated_story)
 
65
 
66
- st.subheader("Protagonist")
67
- if generate_text_btn and protagonist_description:
68
- with st.spinner("Generating protagonist description..."):
69
- generated_protagonist = generate_text(f"Generate a detailed description of a game protagonist based on this description: {protagonist_description}")
70
- st.markdown(generated_protagonist)
 
 
71
 
72
- st.subheader("Game Plot")
73
- if generate_text_btn and image_description:
74
- with st.spinner("Generating game plot..."):
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()