Spaces:
Runtime error
Runtime error
TANVEERMAKHDOOM
commited on
Commit
•
458fbe4
1
Parent(s):
9afff54
Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,21 @@
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
import anthropic
|
3 |
|
4 |
-
#
|
5 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
|
7 |
def generate_game_environment(description_prompt):
|
8 |
-
|
|
|
9 |
model="claude-3-5-sonnet-20240620",
|
10 |
max_tokens=500,
|
11 |
temperature=0.7,
|
@@ -22,10 +32,11 @@ def generate_game_environment(description_prompt):
|
|
22 |
}
|
23 |
]
|
24 |
)
|
25 |
-
return
|
26 |
|
27 |
def generate_protagonist(description_prompt):
|
28 |
-
|
|
|
29 |
model="claude-3-5-sonnet-20240620",
|
30 |
max_tokens=500,
|
31 |
temperature=0.7,
|
@@ -42,10 +53,11 @@ def generate_protagonist(description_prompt):
|
|
42 |
}
|
43 |
]
|
44 |
)
|
45 |
-
return
|
46 |
|
47 |
def generate_antagonist(description_prompt):
|
48 |
-
|
|
|
49 |
model="claude-3-5-sonnet-20240620",
|
50 |
max_tokens=500,
|
51 |
temperature=0.7,
|
@@ -62,7 +74,7 @@ def generate_antagonist(description_prompt):
|
|
62 |
}
|
63 |
]
|
64 |
)
|
65 |
-
return
|
66 |
|
67 |
def generate_game_story(environment, protagonist, antagonist):
|
68 |
description_prompt = (
|
@@ -72,7 +84,8 @@ def generate_game_story(environment, protagonist, antagonist):
|
|
72 |
f"Antagonist: {antagonist}\n"
|
73 |
"Please provide a narrative that ties these elements together in an engaging way."
|
74 |
)
|
75 |
-
|
|
|
76 |
model="claude-3-5-sonnet-20240620",
|
77 |
max_tokens=1000,
|
78 |
temperature=0.7,
|
@@ -89,7 +102,7 @@ def generate_game_story(environment, protagonist, antagonist):
|
|
89 |
}
|
90 |
]
|
91 |
)
|
92 |
-
return
|
93 |
|
94 |
def generate_game_design(environment, protagonist, antagonist):
|
95 |
# Generate each part of the game design
|
@@ -127,6 +140,3 @@ def main():
|
|
127 |
|
128 |
if __name__ == "__main__":
|
129 |
main()
|
130 |
-
|
131 |
-
|
132 |
-
|
|
|
1 |
+
import os
|
2 |
+
from dotenv import load_dotenv
|
3 |
import gradio as gr
|
4 |
import anthropic
|
5 |
|
6 |
+
# Load environment variables from .env file
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
# Get the API key from environment variables
|
10 |
+
def get_client():
|
11 |
+
api_key = os.getenv("ANTHROPIC_API_KEY")
|
12 |
+
if not api_key:
|
13 |
+
raise ValueError("API key not found. Please set the ANTHROPIC_API_KEY environment variable.")
|
14 |
+
return anthropic.Anthropic(api_key=api_key)
|
15 |
|
16 |
def generate_game_environment(description_prompt):
|
17 |
+
client = get_client()
|
18 |
+
response = client.messages.create(
|
19 |
model="claude-3-5-sonnet-20240620",
|
20 |
max_tokens=500,
|
21 |
temperature=0.7,
|
|
|
32 |
}
|
33 |
]
|
34 |
)
|
35 |
+
return response['choices'][0]['text'].strip()
|
36 |
|
37 |
def generate_protagonist(description_prompt):
|
38 |
+
client = get_client()
|
39 |
+
response = client.messages.create(
|
40 |
model="claude-3-5-sonnet-20240620",
|
41 |
max_tokens=500,
|
42 |
temperature=0.7,
|
|
|
53 |
}
|
54 |
]
|
55 |
)
|
56 |
+
return response['choices'][0]['text'].strip()
|
57 |
|
58 |
def generate_antagonist(description_prompt):
|
59 |
+
client = get_client()
|
60 |
+
response = client.messages.create(
|
61 |
model="claude-3-5-sonnet-20240620",
|
62 |
max_tokens=500,
|
63 |
temperature=0.7,
|
|
|
74 |
}
|
75 |
]
|
76 |
)
|
77 |
+
return response['choices'][0]['text'].strip()
|
78 |
|
79 |
def generate_game_story(environment, protagonist, antagonist):
|
80 |
description_prompt = (
|
|
|
84 |
f"Antagonist: {antagonist}\n"
|
85 |
"Please provide a narrative that ties these elements together in an engaging way."
|
86 |
)
|
87 |
+
client = get_client()
|
88 |
+
response = client.messages.create(
|
89 |
model="claude-3-5-sonnet-20240620",
|
90 |
max_tokens=1000,
|
91 |
temperature=0.7,
|
|
|
102 |
}
|
103 |
]
|
104 |
)
|
105 |
+
return response['choices'][0]['text'].strip()
|
106 |
|
107 |
def generate_game_design(environment, protagonist, antagonist):
|
108 |
# Generate each part of the game design
|
|
|
140 |
|
141 |
if __name__ == "__main__":
|
142 |
main()
|
|
|
|
|
|