sal-maq commited on
Commit
16ac246
Β·
verified Β·
1 Parent(s): 70a7955

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +83 -69
app.py CHANGED
@@ -1,143 +1,157 @@
 
1
  import streamlit as st
2
  import anthropic
3
- import os
4
  from dotenv import load_dotenv
5
 
6
- # Load API key from .env file
7
  load_dotenv()
 
 
8
  api_key = os.getenv("Claude_api_key")
9
 
10
- # Initialize the Anthrop client
11
  client = anthropic.Anthropic(api_key=api_key)
12
 
13
- def extract_relevant_info(response):
14
- """Extract relevant information from the API response."""
15
- # Print response to understand its structure
16
- print(response)
17
- # Adjust this based on the actual structure of response
18
- return response.content.get_text().strip() if hasattr(response.content, 'get_text') else "No content available"
19
-
20
- def generate_game_environment(description):
21
- response = client.messages.create(
22
  model="claude-3-5-sonnet-20240620",
23
  max_tokens=150,
24
  temperature=0.7,
25
- system="You are a world-class game designer. Respond only with detailed and creative descriptions of game environments.",
26
  messages=[
27
  {
28
  "role": "user",
29
  "content": [
30
  {
31
  "type": "text",
32
- "text": f"Create a game environment based on the following description: {description}"
33
  }
34
  ]
35
  }
36
  ]
37
  )
38
- return extract_relevant_info(response)
39
 
40
- def generate_protagonist(description):
41
- response = client.messages.create(
42
  model="claude-3-5-sonnet-20240620",
43
  max_tokens=150,
44
  temperature=0.7,
45
- system="You are a world-class game designer. Respond only with detailed and creative descriptions of game protagonists.",
46
  messages=[
47
  {
48
  "role": "user",
49
  "content": [
50
  {
51
  "type": "text",
52
- "text": f"Create a game protagonist based on the following description: {description}"
53
  }
54
  ]
55
  }
56
  ]
57
  )
58
- return extract_relevant_info(response)
59
 
60
- def generate_antagonist(description):
61
- response = client.messages.create(
62
  model="claude-3-5-sonnet-20240620",
63
  max_tokens=150,
64
  temperature=0.7,
65
- system="You are a world-class game designer. Respond only with detailed and creative descriptions of game antagonists.",
66
  messages=[
67
  {
68
  "role": "user",
69
  "content": [
70
  {
71
  "type": "text",
72
- "text": f"Create a game antagonist based on the following description: {description}"
73
  }
74
  ]
75
  }
76
  ]
77
  )
78
- return extract_relevant_info(response)
79
 
80
  def generate_game_story(environment, protagonist, antagonist):
81
- response = client.messages.create(
 
 
 
 
82
  model="claude-3-5-sonnet-20240620",
83
- max_tokens=1000,
84
  temperature=0.7,
85
- system="You are a world-class game designer. Respond only with detailed and creative game story plots.",
86
  messages=[
87
  {
88
  "role": "user",
89
  "content": [
90
  {
91
  "type": "text",
92
- "text": f"Create a game story plot based on the following: \n"
93
- f"Environment: {environment}\n"
94
- f"Protagonist: {protagonist}\n"
95
- f"Antagonist: {antagonist}"
96
  }
97
  ]
98
  }
99
  ]
100
  )
101
- return extract_relevant_info(response)
102
-
103
- # Sidebar for user inputs
104
- st.sidebar.header("Input Your Game Details")
105
- st.sidebar.text("Please provide detailed and creative descriptions.")
106
-
107
- game_environment_input = st.sidebar.text_input("🌍 Game Environment",
108
- "Describe the setting of your game. Include details like time period, location, and atmosphere.")
109
- protagonist_input = st.sidebar.text_input("🦸 Protagonist",
110
- "Describe the main character. Include their background, motivations, and abilities.")
111
- antagonist_input = st.sidebar.text_input("🦹 Antagonist",
112
- "Describe the main enemy. Include their backstory, goals, and relationship with the protagonist.")
113
-
114
- # Main app title and description
115
- st.title("Story Forger")
116
- st.write("Developed by Salman Maqbool")
117
- st.write("**Story Forger** is a tool for game developers to easily create detailed game design documents. Input your game environment, protagonist, and antagonist, and generate a solid foundation for your game's story.")
118
-
119
- # Generating the content based on user inputs
120
- if st.sidebar.button("Generate"):
121
- if game_environment_input and protagonist_input and antagonist_input:
122
- game_environment = generate_game_environment(game_environment_input)
123
- protagonist = generate_protagonist(protagonist_input)
124
- antagonist = generate_antagonist(antagonist_input)
125
  game_story = generate_game_story(game_environment, protagonist, antagonist)
 
 
 
 
 
 
 
 
 
126
 
127
- col1, col2 = st.columns(2)
 
 
 
 
 
128
 
129
- with col1:
130
- st.subheader("🌍 Game Environment")
131
- st.write(game_environment)
132
-
133
- st.subheader("🦸 Protagonist")
134
- st.write(protagonist)
135
 
136
- with col2:
137
- st.subheader("πŸ“– Game Story")
138
- st.write(game_story)
 
 
 
139
 
140
- st.subheader("🦹 Antagonist")
141
- st.write(antagonist)
 
 
142
  else:
143
- st.error("Please fill in all the details in the sidebar before generating.")
 
 
 
 
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 a World Class Game Designer. 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("Story Forger ✨")
102
+
103
+ # App Description
104
+ st.write("Story Forger 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)
155
+
156
+ # Footer
157
+ st.write("**Developed by Salman Maqbool**")