Spaces:
Runtime error
Runtime error
TANVEERMAKHDOOM
commited on
Commit
•
cb7b1ec
1
Parent(s):
5b61aa1
Update app.py
Browse files
app.py
CHANGED
@@ -1,9 +1,104 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
def generate_game_design(environment, protagonist, antagonist):
|
4 |
-
#
|
5 |
-
|
6 |
-
|
|
|
|
|
|
|
|
|
7 |
|
8 |
def main():
|
9 |
with gr.Blocks() as demo:
|
@@ -21,11 +116,17 @@ def main():
|
|
21 |
gr.Markdown("## Protagonist")
|
22 |
gr.Markdown("## Antagonist")
|
23 |
gr.Markdown("## Game Story")
|
|
|
|
|
|
|
24 |
game_story_output = gr.Textbox(label="Game Story", interactive=False)
|
25 |
|
26 |
-
submit_btn.click(generate_game_design, inputs=[environment, protagonist, antagonist], outputs=game_story_output)
|
27 |
|
28 |
demo.launch()
|
29 |
|
30 |
if __name__ == "__main__":
|
31 |
main()
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import anthropic
|
3 |
+
|
4 |
+
# Initialize the Anthropic client
|
5 |
+
client = anthropic.Anthropic()
|
6 |
+
|
7 |
+
def generate_game_environment(description_prompt):
|
8 |
+
message = client.messages.create(
|
9 |
+
model="claude-3-5-sonnet-20240620",
|
10 |
+
max_tokens=500,
|
11 |
+
temperature=0.7,
|
12 |
+
system="You are a creative writer specialized in generating immersive game environments.",
|
13 |
+
messages=[
|
14 |
+
{
|
15 |
+
"role": "user",
|
16 |
+
"content": [
|
17 |
+
{
|
18 |
+
"type": "text",
|
19 |
+
"text": description_prompt
|
20 |
+
}
|
21 |
+
]
|
22 |
+
}
|
23 |
+
]
|
24 |
+
)
|
25 |
+
return message.content
|
26 |
+
|
27 |
+
def generate_protagonist(description_prompt):
|
28 |
+
message = client.messages.create(
|
29 |
+
model="claude-3-5-sonnet-20240620",
|
30 |
+
max_tokens=500,
|
31 |
+
temperature=0.7,
|
32 |
+
system="You are a character designer specializing in creating detailed protagonists for games.",
|
33 |
+
messages=[
|
34 |
+
{
|
35 |
+
"role": "user",
|
36 |
+
"content": [
|
37 |
+
{
|
38 |
+
"type": "text",
|
39 |
+
"text": description_prompt
|
40 |
+
}
|
41 |
+
]
|
42 |
+
}
|
43 |
+
]
|
44 |
+
)
|
45 |
+
return message.content
|
46 |
+
|
47 |
+
def generate_antagonist(description_prompt):
|
48 |
+
message = client.messages.create(
|
49 |
+
model="claude-3-5-sonnet-20240620",
|
50 |
+
max_tokens=500,
|
51 |
+
temperature=0.7,
|
52 |
+
system="You are a character designer specializing in creating compelling antagonists for games.",
|
53 |
+
messages=[
|
54 |
+
{
|
55 |
+
"role": "user",
|
56 |
+
"content": [
|
57 |
+
{
|
58 |
+
"type": "text",
|
59 |
+
"text": description_prompt
|
60 |
+
}
|
61 |
+
]
|
62 |
+
}
|
63 |
+
]
|
64 |
+
)
|
65 |
+
return message.content
|
66 |
+
|
67 |
+
def generate_game_story(environment, protagonist, antagonist):
|
68 |
+
description_prompt = (
|
69 |
+
f"Create a compelling game story based on the following details:\n"
|
70 |
+
f"Game Environment: {environment}\n"
|
71 |
+
f"Protagonist: {protagonist}\n"
|
72 |
+
f"Antagonist: {antagonist}\n"
|
73 |
+
"Please provide a narrative that ties these elements together in an engaging way."
|
74 |
+
)
|
75 |
+
message = client.messages.create(
|
76 |
+
model="claude-3-5-sonnet-20240620",
|
77 |
+
max_tokens=1000,
|
78 |
+
temperature=0.7,
|
79 |
+
system="You are a master storyteller. Generate an engaging game story from the given details.",
|
80 |
+
messages=[
|
81 |
+
{
|
82 |
+
"role": "user",
|
83 |
+
"content": [
|
84 |
+
{
|
85 |
+
"type": "text",
|
86 |
+
"text": description_prompt
|
87 |
+
}
|
88 |
+
]
|
89 |
+
}
|
90 |
+
]
|
91 |
+
)
|
92 |
+
return message.content
|
93 |
|
94 |
def generate_game_design(environment, protagonist, antagonist):
|
95 |
+
# Generate each part of the game design
|
96 |
+
env_description = generate_game_environment(environment)
|
97 |
+
prot_description = generate_protagonist(protagonist)
|
98 |
+
antag_description = generate_antagonist(antagonist)
|
99 |
+
game_story = generate_game_story(env_description, prot_description, antag_description)
|
100 |
+
|
101 |
+
return env_description, prot_description, antag_description, game_story
|
102 |
|
103 |
def main():
|
104 |
with gr.Blocks() as demo:
|
|
|
116 |
gr.Markdown("## Protagonist")
|
117 |
gr.Markdown("## Antagonist")
|
118 |
gr.Markdown("## Game Story")
|
119 |
+
env_output = gr.Textbox(label="Game Environment", interactive=False)
|
120 |
+
prot_output = gr.Textbox(label="Protagonist", interactive=False)
|
121 |
+
antag_output = gr.Textbox(label="Antagonist", interactive=False)
|
122 |
game_story_output = gr.Textbox(label="Game Story", interactive=False)
|
123 |
|
124 |
+
submit_btn.click(generate_game_design, inputs=[environment, protagonist, antagonist], outputs=[env_output, prot_output, antag_output, game_story_output])
|
125 |
|
126 |
demo.launch()
|
127 |
|
128 |
if __name__ == "__main__":
|
129 |
main()
|
130 |
+
|
131 |
+
|
132 |
+
|