Safwanahmad619 commited on
Commit
ff5658f
·
verified ·
1 Parent(s): 83c3a40

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +134 -269
app.py CHANGED
@@ -1,308 +1,173 @@
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("🎮 Safwan's GameMaker Studio")
102
-
103
- # # App Description
104
- # st.write("Welcome to Safwan's GameMaker Studio, a popular game development platform known for its ease of use and powerful features. Enter your ideas according to your taste and this will generate a script with a real scenario. Generate more ideas to compete with the big communities.")
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 three columns
126
- # col1, col2, col3 = st.columns(3)
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
- # st.markdown("---")
135
-
136
- # with col2:
137
- # st.header("🦸‍♂️Protagonist")
138
- # if 'protagonist_description' in st.session_state:
139
- # st.write(st.session_state.protagonist_description)
140
- # if st.button("Edit Protagonist Details", key="edit_protagonist"):
141
- # new_protagonist_description = st.text_area("Edit Protagonist Description", st.session_state.protagonist_description)
142
- # if st.button("Update Protagonist", key="update_protagonist"):
143
- # st.session_state.protagonist_description = generate_protagonist(new_protagonist_description)
144
- # st.experimental_rerun()
145
- # else:
146
- # st.write(protagonist)
147
- # st.markdown("---")
148
-
149
- # with col3:
150
- # st.header("🦹‍♀️ Antagonist")
151
- # if 'antagonist_description' in st.session_state:
152
- # st.write(st.session_state.antagonist_description)
153
- # if st.button("Edit Antagonist Details", key="edit_antagonist"):
154
- # new_antagonist_description = st.text_area("Edit Antagonist Description", st.session_state.antagonist_description)
155
- # if st.button("Update Antagonist", key="update_antagonist"):
156
- # st.session_state.antagonist_description = generate_antagonist(new_antagonist_description)
157
- # st.experimental_rerun()
158
- # else:
159
- # st.write(antagonist)
160
- # st.markdown("---")
161
-
162
- # # Combine and merge sections to generate a scenario and script
163
- # if 'env_description' in st.session_state and 'protagonist_description' in st.session_state and 'antagonist_description' in st.session_state:
164
- # combined_content = (f"### Game Scenario\n\n"
165
- # f"**Environment:** {st.session_state.env_description}\n\n"
166
- # f"**Protagonist:** {st.session_state.protagonist_description}\n\n"
167
- # f"**Antagonist:** {st.session_state.antagonist_description}\n\n"
168
- # f"**Story:** {st.session_state.game_story}")
169
- # else:
170
- # combined_content = "Your complete game scenario and script will be generated based on the inputs provided."
171
-
172
- # st.header("📜 Game Scenario & Script")
173
- # st.write(combined_content)
174
-
175
- #
176
- #0----------------
177
  import streamlit as st
178
- import smtplib
179
- from email.mime.text import MIMEText
180
- from email.mime.multipart import MIMEMultipart
181
- from pydrive.auth import GoogleAuth
182
- from pydrive.drive import GoogleDrive
183
- import urllib.parse
184
-
185
- # Function to send an email with the script
186
- def send_email(to_email, subject, body):
187
- from_email = "[email protected]"
188
- password = "your_email_password"
189
-
190
- msg = MIMEMultipart()
191
- msg['From'] = from_email
192
- msg['To'] = to_email
193
- msg['Subject'] = subject
194
- msg.attach(MIMEText(body, 'plain'))
195
-
196
- server = smtplib.SMTP('smtp.gmail.com', 587)
197
- server.starttls()
198
- server.login(from_email, password)
199
- server.sendmail(from_email, to_email, msg.as_string())
200
- server.quit()
201
-
202
- # Function to upload the script to Google Drive and get a shareable link
203
- def upload_to_drive(file_name, file_content):
204
- gauth = GoogleAuth()
205
- gauth.LocalWebserverAuth()
206
- drive = GoogleDrive(gauth)
207
-
208
- file = drive.CreateFile({'title': file_name})
209
- file.SetContentString(file_content)
210
- file.Upload()
211
-
212
- file.InsertPermission({
213
- 'type': 'anyone',
214
- 'value': 'anyone',
215
- 'role': 'reader'
216
- })
217
- return file['alternateLink']
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
219
  # Layout with three columns
220
  col1, col2, col3 = st.columns(3)
221
 
222
  with col1:
223
  st.header("🌍 Game Environment")
224
- st.image("path_to_environment_image.jpg", caption="Game Environment", use_column_width=True)
225
  if 'env_description' in st.session_state:
226
  st.write(st.session_state.env_description)
227
  else:
228
- st.write("Default game environment")
229
  st.markdown("---")
230
 
231
  with col2:
232
- st.header("🦸‍♂️ Protagonist")
233
- st.image("path_to_protagonist_image.jpg", caption="Protagonist", use_column_width=True)
234
  if 'protagonist_description' in st.session_state:
235
  st.write(st.session_state.protagonist_description)
236
  if st.button("Edit Protagonist Details", key="edit_protagonist"):
237
  new_protagonist_description = st.text_area("Edit Protagonist Description", st.session_state.protagonist_description)
238
  if st.button("Update Protagonist", key="update_protagonist"):
239
- st.session_state.protagonist_description = new_protagonist_description
240
  st.experimental_rerun()
241
  else:
242
- st.write("Default protagonist description")
243
  st.markdown("---")
244
 
245
  with col3:
246
  st.header("🦹‍♀️ Antagonist")
247
- st.image("path_to_antagonist_image.jpg", caption="Antagonist", use_column_width=True)
248
  if 'antagonist_description' in st.session_state:
249
  st.write(st.session_state.antagonist_description)
250
  if st.button("Edit Antagonist Details", key="edit_antagonist"):
251
  new_antagonist_description = st.text_area("Edit Antagonist Description", st.session_state.antagonist_description)
252
  if st.button("Update Antagonist", key="update_antagonist"):
253
- st.session_state.antagonist_description = new_antagonist_description
254
  st.experimental_rerun()
255
  else:
256
- st.write("Default antagonist description")
257
  st.markdown("---")
258
 
259
  # Combine and merge sections to generate a scenario and script
260
- if all(k in st.session_state for k in ['env_description', 'protagonist_description', 'antagonist_description']):
261
- combined_content = (
262
- f"### Game Scenario\n\n"
263
- f"**Environment:** {st.session_state.env_description}\n\n"
264
- f"**Protagonist:** {st.session_state.protagonist_description}\n\n"
265
- f"**Antagonist:** {st.session_state.antagonist_description}\n\n"
266
- f"**Story:** This is where the story will go..."
267
- )
268
  else:
269
  combined_content = "Your complete game scenario and script will be generated based on the inputs provided."
270
 
271
  st.header("📜 Game Scenario & Script")
272
  st.write(combined_content)
273
-
274
- # Add a download button to save the script
275
- st.download_button(
276
- label="💾 Download Script",
277
- data=combined_content,
278
- file_name="game_script.txt",
279
- mime="text/plain"
280
- )
281
-
282
- # Email sharing option
283
- to_email = st.text_input("Enter recipient email address:")
284
- if st.button("📧 Send Script via Email"):
285
- if to_email:
286
- send_email(to_email, "Your Game Script", combined_content)
287
- st.success(f"Script sent to {to_email} successfully!")
288
-
289
- # Google Drive sharing option
290
- if st.button("🔗 Upload & Get Shareable Link"):
291
- link = upload_to_drive("game_script.txt", combined_content)
292
- st.success("File uploaded successfully!")
293
- st.write(f"Shareable Link: {link}")
294
-
295
- # WhatsApp sharing option
296
- phone_number = st.text_input("Enter phone number with country code:")
297
- if st.button("📲 Share via WhatsApp"):
298
- if phone_number:
299
- message = combined_content
300
- encoded_message = urllib.parse.quote(message)
301
- url = f"https://api.whatsapp.com/send?phone={phone_number}&text={encoded_message}"
302
- st.markdown(f"[Click to Share on WhatsApp]({url})")
303
-
304
- # Shareable web page link (assuming Streamlit is deployed)
305
- if st.button("Generate Shareable Link"):
306
- app_base_url = "https://your-streamlit-app-url" # Replace with your deployed app's base URL
307
- script_link = app_base_url + "/script?content=" + urllib.parse.quote(combined_content)
308
- st.write(f"Shareable Link: {script_link}")
 
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("🎮 Safwan's GameMaker Studio")
102
+
103
+ # App Description
104
+ st.write("Welcome to Safwan's GameMaker Studio, a popular game development platform known for its ease of use and powerful features. Enter your ideas according to your taste and this will generate a script with a real scenario. Generate more ideas to compete with the big communities.")
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 three columns
126
  col1, col2, col3 = st.columns(3)
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
  st.markdown("---")
135
 
136
  with col2:
137
+ st.header("🦸‍♂️Protagonist")
 
138
  if 'protagonist_description' in st.session_state:
139
  st.write(st.session_state.protagonist_description)
140
  if st.button("Edit Protagonist Details", key="edit_protagonist"):
141
  new_protagonist_description = st.text_area("Edit Protagonist Description", st.session_state.protagonist_description)
142
  if st.button("Update Protagonist", key="update_protagonist"):
143
+ st.session_state.protagonist_description = generate_protagonist(new_protagonist_description)
144
  st.experimental_rerun()
145
  else:
146
+ st.write(protagonist)
147
  st.markdown("---")
148
 
149
  with col3:
150
  st.header("🦹‍♀️ Antagonist")
 
151
  if 'antagonist_description' in st.session_state:
152
  st.write(st.session_state.antagonist_description)
153
  if st.button("Edit Antagonist Details", key="edit_antagonist"):
154
  new_antagonist_description = st.text_area("Edit Antagonist Description", st.session_state.antagonist_description)
155
  if st.button("Update Antagonist", key="update_antagonist"):
156
+ st.session_state.antagonist_description = generate_antagonist(new_antagonist_description)
157
  st.experimental_rerun()
158
  else:
159
+ st.write(antagonist)
160
  st.markdown("---")
161
 
162
  # Combine and merge sections to generate a scenario and script
163
+ if 'env_description' in st.session_state and 'protagonist_description' in st.session_state and 'antagonist_description' in st.session_state:
164
+ combined_content = (f"### Game Scenario\n\n"
165
+ f"**Environment:** {st.session_state.env_description}\n\n"
166
+ f"**Protagonist:** {st.session_state.protagonist_description}\n\n"
167
+ f"**Antagonist:** {st.session_state.antagonist_description}\n\n"
168
+ f"**Story:** {st.session_state.game_story}")
 
 
169
  else:
170
  combined_content = "Your complete game scenario and script will be generated based on the inputs provided."
171
 
172
  st.header("📜 Game Scenario & Script")
173
  st.write(combined_content)