sabahat-shakeel commited on
Commit
910753a
·
verified ·
1 Parent(s): cfd11bf

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +168 -0
app.py ADDED
@@ -0,0 +1,168 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ # Retrieve API key from environment variable
10
+ api_key = os.getenv('Claude_api_key')
11
+
12
+ # Initialize Anthropic client with API key
13
+ client = anthropic.Anthropic(api_key=api_key)
14
+
15
+ # Define the functions for generating game content
16
+ def generate_game_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 creative game designer. Generate a detailed and imaginative game environment based on the provided description.",
22
+ messages=[
23
+ {
24
+ "role": "user",
25
+ "content": [
26
+ {
27
+ "type": "text",
28
+ "text": f"Create a game environment based on the following description: {description}"
29
+ }
30
+ ]
31
+ }
32
+ ]
33
+ )
34
+ return message.content[0].text # Return relevant text
35
+
36
+ def generate_game_story(environment, protagonist, antagonist):
37
+ message = client.messages.create(
38
+ model="claude-3-5-sonnet-20240620",
39
+ max_tokens=150,
40
+ temperature=0.7,
41
+ system="You are a skilled storyteller. Craft a compelling game story that connects the environment, protagonist, and antagonist.",
42
+ messages=[
43
+ {
44
+ "role": "user",
45
+ "content": [
46
+ {
47
+ "type": "text",
48
+ "text": f"Create a game story that takes place in the following environment: {environment}. "
49
+ f"The protagonist is: {protagonist}. The antagonist is: {antagonist}. "
50
+ "Please craft a detailed and engaging game story."
51
+ }
52
+ ]
53
+ }
54
+ ]
55
+ )
56
+ return message.content[0].text # Return relevant text
57
+
58
+ def generate_protagonist(description):
59
+ message = client.messages.create(
60
+ model="claude-3-5-sonnet-20240620",
61
+ max_tokens=150,
62
+ temperature=0.7,
63
+ system="You are an expert in character development. Create a well-defined and relatable protagonist based on the provided description.",
64
+ messages=[
65
+ {
66
+ "role": "user",
67
+ "content": [
68
+ {
69
+ "type": "text",
70
+ "text": f"Create a protagonist based on the following description: {description}"
71
+ }
72
+ ]
73
+ }
74
+ ]
75
+ )
76
+ return message.content[0].text # Return relevant text
77
+
78
+ def generate_antagonist(description):
79
+ message = client.messages.create(
80
+ model="claude-3-5-sonnet-20240620",
81
+ max_tokens=150,
82
+ temperature=0.7,
83
+ system="You are an expert in creating antagonists. Generate a compelling and complex antagonist based on the provided description.",
84
+ messages=[
85
+ {
86
+ "role": "user",
87
+ "content": [
88
+ {
89
+ "type": "text",
90
+ "text": f"Create an antagonist based on the following description: {description}"
91
+ }
92
+ ]
93
+ }
94
+ ]
95
+ )
96
+ return message.content[0].text # Return relevant text
97
+
98
+ # Sidebar Inputs
99
+ st.sidebar.title("GameNarrator")
100
+ st.sidebar.subheader("Please enter the details for your game:")
101
+
102
+ game_environment = st.sidebar.text_input("Game Environment",
103
+ "Enter the setting or world where your game takes place. For example, a post-apocalyptic city, a fantasy kingdom, or a sci-fi space station.")
104
+
105
+ protagonist = st.sidebar.text_input("Protagonist",
106
+ "Enter the main character of your game, including their role and key characteristics. For example, a brave knight, a resourceful hacker, or a mystical sorcerer.")
107
+
108
+ antagonist = st.sidebar.text_input("Antagonist",
109
+ "Enter the main antagonist of your game, describing their role and motivations. For example, an evil warlord, a corrupt corporation, or a malevolent AI.")
110
+
111
+ # Generate content when the user clicks the button
112
+ if st.sidebar.button("Generate Game Design Document"):
113
+ if game_environment and protagonist and antagonist:
114
+ # Generate each part of the game design document
115
+ generated_environment = generate_game_environment(game_environment)
116
+ generated_protagonist = generate_protagonist(protagonist)
117
+ generated_antagonist = generate_antagonist(antagonist)
118
+ generated_story = generate_game_story(generated_environment, generated_protagonist, generated_antagonist)
119
+
120
+ # Main App Title and Description
121
+ st.title("GameNarrator")
122
+ st.write("""
123
+ GameNarrator is a powerful tool for game developers to generate comprehensive Game Design Documents (GDD).
124
+ Simply input key elements of your game, and GameNarrator will help you organize and structure your ideas into a professional document.
125
+ """)
126
+
127
+ # Layout with Columns
128
+ col1, col2 = st.columns(2)
129
+
130
+ with col1:
131
+ st.subheader("Game Environment")
132
+ st.write(generated_environment)
133
+
134
+ st.subheader("Protagonist")
135
+ st.write(generated_protagonist)
136
+
137
+ with col2:
138
+ st.subheader("Game Story")
139
+ st.write(generated_story)
140
+
141
+ st.subheader("Antagonist")
142
+ st.write(generated_antagonist)
143
+ else:
144
+ st.error("Please fill out all fields in the sidebar to generate the Game Design Document.")
145
+ else:
146
+ # Main App Title and Description
147
+ st.title("GameNarrator")
148
+ st.write("""
149
+ GameNarrator is a powerful tool for game developers to generate comprehensive Game Design Documents (GDD).
150
+ Simply input key elements of your game, and GameNarrator will help you organize and structure your ideas into a professional document.
151
+ """)
152
+
153
+ # Layout with Columns and placeholders for when no content is generated
154
+ col1, col2 = st.columns(2)
155
+
156
+ with col1:
157
+ st.subheader("Game Environment")
158
+ st.write("Enter game environment details to generate content.")
159
+
160
+ st.subheader("Protagonist")
161
+ st.write("Enter protagonist details to generate content.")
162
+
163
+ with col2:
164
+ st.subheader("Game Story")
165
+ st.write("Enter game environment, protagonist, and antagonist to generate the story.")
166
+
167
+ st.subheader("Antagonist")
168
+ st.write("Enter antagonist details to generate content.")