sainkan commited on
Commit
1b3748a
1 Parent(s): 17ba82d

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +132 -82
app.py CHANGED
@@ -1,104 +1,154 @@
 
1
  import streamlit as st
2
  import anthropic
3
- import os
4
  from dotenv import load_dotenv
5
 
6
  # Load environment variables from .env file
7
  load_dotenv()
8
 
9
- # API keys
10
- claude_api_key = os.getenv("ANTHROPIC_API_KEY")
11
- if claude_api_key is None:
12
- raise ValueError("Claude API Key is not set. Please check your .env file.")
 
13
 
14
- print(f"Claude API Key: {claude_api_key}") # Debugging line to check if the key is loaded
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
- # Initialize Claude AI client
17
- client = anthropic.Anthropic(api_key=claude_api_key)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
18
 
19
- # Function to generate text using Claude AI
20
- def generate_text(prompt, model_name="claude-3-opus-20240229"):
21
- response = client.messages.create(
22
- model=model_name,
23
- max_tokens=500,
24
- temperature=0.5,
25
- system=(
26
- "You are a creative writer. Based on the following description, "
27
- "generate content for a game design document: {prompt}"
28
- ),
29
  messages=[
30
- {"role": "user", "content": [{"type": "text", "text": prompt}]}
 
 
 
 
 
 
 
 
31
  ]
32
  )
33
- return response.content[0].text
34
 
35
- # Main Function
36
- def main():
37
- st.set_page_config(page_title="StoryForge", layout="wide")
38
- st.title("StoryForge")
39
- st.markdown(
40
- """
41
- **StoryForge** helps game developers generate comprehensive Game Design Documents.
42
- Input details about your game environment, protagonist, and antagonist to create a structured design document.
43
- """
 
 
 
 
 
 
 
 
 
 
 
 
44
  )
 
 
 
 
45
 
46
- # Sidebar for user input
47
- with st.sidebar:
48
- st.header("Game Details")
49
- image_description = st.text_area(
50
- "Game Environment",
51
- placeholder="Describe the setting of your game",
52
- height=100
53
- )
54
- protagonist_description = st.text_area(
55
- "Protagonist",
56
- placeholder="Describe the main character",
57
- height=100
58
- )
59
- antagonist_description = st.text_area(
60
- "Antagonist",
61
- placeholder="Describe the main villain or opposing force",
62
- height=100
63
- )
64
- generate_text_btn = st.button("Generate Document")
65
 
66
- col1, col2 = st.columns(2)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
67
 
68
- with col1:
69
- st.subheader("Game Environment")
70
- if generate_text_btn and image_description:
71
- with st.spinner("Generating game environment description..."):
72
- generated_environment = generate_text(
73
- f"Generate a detailed description of a game environment based on this theme and setting: {image_description}"
74
- )
75
- st.markdown(generated_environment)
76
 
77
- st.subheader("Protagonist")
78
- if generate_text_btn and protagonist_description:
79
- with st.spinner("Generating protagonist description..."):
80
- generated_protagonist = generate_text(
81
- f"Generate a detailed description of a game protagonist based on this description: {protagonist_description}"
82
- )
83
- st.markdown(generated_protagonist)
84
 
85
- with col2:
86
- st.subheader("Game Story")
87
- if generate_text_btn and image_description:
88
- with st.spinner("Generating game story..."):
89
- generated_story = generate_text(
90
- f"Create a creative and engaging game story that includes a protagonist, antagonist, and a challenge based on this description: {image_description}"
91
- )
92
- st.markdown(generated_story)
93
 
94
- st.subheader("Antagonist")
95
- if generate_text_btn and antagonist_description:
96
- with st.spinner("Generating antagonist description..."):
97
- generated_antagonist = generate_text(
98
- f"Generate a detailed description of a game antagonist based on this description: {antagonist_description}"
99
- )
100
- st.markdown(generated_antagonist)
101
 
102
- # Run Main Function
103
- if __name__ == "__main__":
104
- main()
 
 
 
 
1
+ import os
2
  import streamlit as st
3
  import anthropic
 
4
  from dotenv import load_dotenv
5
 
6
  # Load environment variables from .env file
7
  load_dotenv()
8
 
9
+ # Retrieve the API key from environment variables
10
+ api_key = os.getenv("Claude_api_key")
11
+
12
+ # Initialize the Anthropic client with the API key
13
+ client = anthropic.Anthropic(api_key=api_key)
14
 
15
+ # Define the functions to generate content
16
+ def generate_game_environment(environment_description):
17
+ message = client.messages.create(
18
+ model="claude-3-5-sonnet-20240620",
19
+ max_tokens=150,
20
+ temperature=0.7,
21
+ system="You are an expert in world-building. Generate a detailed description of a game environment based on the input.",
22
+ messages=[
23
+ {
24
+ "role": "user",
25
+ "content": [
26
+ {
27
+ "type": "text",
28
+ "text": f"Create a detailed description of a game environment based on this input: {environment_description}"
29
+ }
30
+ ]
31
+ }
32
+ ]
33
+ )
34
+ return message.content[0].text
35
 
36
+ def generate_protagonist(protagonist_description):
37
+ message = client.messages.create(
38
+ model="claude-3-5-sonnet-20240620",
39
+ max_tokens=150,
40
+ temperature=0.7,
41
+ system="You are an expert in character creation. Generate a detailed description of a game protagonist based on the input.",
42
+ messages=[
43
+ {
44
+ "role": "user",
45
+ "content": [
46
+ {
47
+ "type": "text",
48
+ "text": f"Create a detailed description of a game protagonist based on this input: {protagonist_description}"
49
+ }
50
+ ]
51
+ }
52
+ ]
53
+ )
54
+ return message.content[0].text
55
 
56
+ def generate_antagonist(antagonist_description):
57
+ message = client.messages.create(
58
+ model="claude-3-5-sonnet-20240620",
59
+ max_tokens=150,
60
+ temperature=0.7,
61
+ system="You are an expert in villain creation. Generate a detailed description of a game antagonist based on the input.",
 
 
 
 
62
  messages=[
63
+ {
64
+ "role": "user",
65
+ "content": [
66
+ {
67
+ "type": "text",
68
+ "text": f"Create a detailed description of a game antagonist based on this input: {antagonist_description}"
69
+ }
70
+ ]
71
+ }
72
  ]
73
  )
74
+ return message.content[0].text
75
 
76
+ def generate_game_story(environment, protagonist, antagonist):
77
+ story_prompt = (f"Create a detailed game story based on the following inputs:\n"
78
+ f"Game Environment: {environment}\n"
79
+ f"Protagonist: {protagonist}\n"
80
+ f"Antagonist: {antagonist}")
81
+ message = client.messages.create(
82
+ model="claude-3-5-sonnet-20240620",
83
+ max_tokens= 150,
84
+ temperature=0.7,
85
+ system="You are a master storyteller. Generate a detailed game story based on the inputs provided.",
86
+ messages=[
87
+ {
88
+ "role": "user",
89
+ "content": [
90
+ {
91
+ "type": "text",
92
+ "text": story_prompt
93
+ }
94
+ ]
95
+ }
96
+ ]
97
  )
98
+ return message.content[0].text
99
+
100
+ # App Title
101
+ st.title("StoryForge")
102
 
103
+ # App Description
104
+ st.write("StoryForge helps game developers generate comprehensive Game Design Documents. Input details about your game environment, protagonist, and antagonist to create a structured design document.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
+ # Sidebar Inputs
107
+ with st.sidebar:
108
+ st.header("Game Details")
109
+ game_environment = st.text_input("Game Environment", "Describe the setting of your game")
110
+ protagonist = st.text_input("Protagonist", "Describe the main character")
111
+ antagonist = st.text_input("Antagonist", "Describe the main villain or opposing force")
112
+ if st.button("Generate Document"):
113
+ # Generate content based on user input
114
+ env_description = generate_game_environment(game_environment)
115
+ protagonist_description = generate_protagonist(protagonist)
116
+ antagonist_description = generate_antagonist(antagonist)
117
+ game_story = generate_game_story(game_environment, protagonist, antagonist)
118
+
119
+ # Store results in session state
120
+ st.session_state.env_description = env_description
121
+ st.session_state.protagonist_description = protagonist_description
122
+ st.session_state.antagonist_description = antagonist_description
123
+ st.session_state.game_story = game_story
124
 
125
+ # Layout with two columns
126
+ col1, col2 = st.columns(2)
 
 
 
 
 
 
127
 
128
+ with col1:
129
+ st.header("Game Environment")
130
+ if 'env_description' in st.session_state:
131
+ st.write(st.session_state.env_description)
132
+ else:
133
+ st.write(game_environment)
 
134
 
135
+ with col2:
136
+ st.header("Game Story")
137
+ if 'game_story' in st.session_state:
138
+ st.write(st.session_state.game_story)
139
+ else:
140
+ st.write("Your game story will be generated based on the inputs provided.")
 
 
141
 
142
+ with col1:
143
+ st.header("Protagonist")
144
+ if 'protagonist_description' in st.session_state:
145
+ st.write(st.session_state.protagonist_description)
146
+ else:
147
+ st.write(protagonist)
 
148
 
149
+ with col2:
150
+ st.header("Antagonist")
151
+ if 'antagonist_description' in st.session_state:
152
+ st.write(st.session_state.antagonist_description)
153
+ else:
154
+ st.write(antagonist)