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