Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -16,58 +16,38 @@ client = Groq(
|
|
16 |
|
17 |
# Function to generate the game environment
|
18 |
def generate_game_environment(environment):
|
19 |
-
if not environment:
|
20 |
-
return "Please provide a valid game environment."
|
21 |
-
|
22 |
message = f"Describe the setting of a game in the environment: {environment}."
|
23 |
-
|
24 |
chat_completion = client.chat.completions.create(
|
25 |
messages=[{"role": "user", "content": message}],
|
26 |
model="llama3-8b-8192",
|
27 |
)
|
28 |
-
|
29 |
return chat_completion.choices[0].message.content
|
30 |
|
31 |
# Function to generate the protagonist
|
32 |
def generate_protagonist(protagonist):
|
33 |
-
if not protagonist:
|
34 |
-
return "Please provide a valid protagonist."
|
35 |
-
|
36 |
message = f"Create a detailed description of the protagonist: {protagonist}."
|
37 |
-
|
38 |
chat_completion = client.chat.completions.create(
|
39 |
messages=[{"role": "user", "content": message}],
|
40 |
model="llama3-8b-8192",
|
41 |
)
|
42 |
-
|
43 |
return chat_completion.choices[0].message.content
|
44 |
|
45 |
# Function to generate the antagonist
|
46 |
def generate_antagonist(antagonist):
|
47 |
-
if not antagonist:
|
48 |
-
return "Please provide a valid antagonist."
|
49 |
-
|
50 |
message = f"Create a detailed description of the antagonist: {antagonist}."
|
51 |
-
|
52 |
chat_completion = client.chat.completions.create(
|
53 |
messages=[{"role": "user", "content": message}],
|
54 |
model="llama3-8b-8192",
|
55 |
)
|
56 |
-
|
57 |
return chat_completion.choices[0].message.content
|
58 |
|
59 |
# Function to generate the game story
|
60 |
def generate_game_story(environment, protagonist, antagonist):
|
61 |
-
if not (environment and protagonist and antagonist):
|
62 |
-
return "Please provide all the required details (environment, protagonist, antagonist)."
|
63 |
-
|
64 |
message = f"Create a compelling game story set in {environment}, featuring {protagonist} as the protagonist and {antagonist} as the antagonist."
|
65 |
-
|
66 |
chat_completion = client.chat.completions.create(
|
67 |
messages=[{"role": "user", "content": message}],
|
68 |
model="llama3-8b-8192",
|
69 |
)
|
70 |
-
|
71 |
return chat_completion.choices[0].message.content
|
72 |
|
73 |
|
@@ -81,33 +61,27 @@ game_environment = st.sidebar.text_input("Enter the Game Environment:", placehol
|
|
81 |
protagonist = st.sidebar.text_input("Enter the Protagonist:", placeholder="e.g., A young hacker with a mysterious past")
|
82 |
antagonist = st.sidebar.text_input("Enter the Antagonist:", placeholder="e.g., A corrupt government official controlling the city")
|
83 |
|
84 |
-
#
|
85 |
-
|
86 |
-
|
87 |
-
#
|
88 |
-
|
89 |
-
st.header("Game Environment")
|
90 |
-
if game_environment:
|
91 |
-
st.write(generate_game_environment(game_environment))
|
92 |
else:
|
93 |
-
|
|
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
st.write("Please provide details in the sidebar.")
|
100 |
|
101 |
-
|
102 |
-
|
103 |
-
st.header("Protagonist")
|
104 |
-
if protagonist:
|
105 |
-
st.write(generate_protagonist(protagonist))
|
106 |
-
else:
|
107 |
-
st.write("Please provide a protagonist in the sidebar.")
|
108 |
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
|
|
|
|
|
16 |
|
17 |
# Function to generate the game environment
|
18 |
def generate_game_environment(environment):
|
|
|
|
|
|
|
19 |
message = f"Describe the setting of a game in the environment: {environment}."
|
|
|
20 |
chat_completion = client.chat.completions.create(
|
21 |
messages=[{"role": "user", "content": message}],
|
22 |
model="llama3-8b-8192",
|
23 |
)
|
|
|
24 |
return chat_completion.choices[0].message.content
|
25 |
|
26 |
# Function to generate the protagonist
|
27 |
def generate_protagonist(protagonist):
|
|
|
|
|
|
|
28 |
message = f"Create a detailed description of the protagonist: {protagonist}."
|
|
|
29 |
chat_completion = client.chat.completions.create(
|
30 |
messages=[{"role": "user", "content": message}],
|
31 |
model="llama3-8b-8192",
|
32 |
)
|
|
|
33 |
return chat_completion.choices[0].message.content
|
34 |
|
35 |
# Function to generate the antagonist
|
36 |
def generate_antagonist(antagonist):
|
|
|
|
|
|
|
37 |
message = f"Create a detailed description of the antagonist: {antagonist}."
|
|
|
38 |
chat_completion = client.chat.completions.create(
|
39 |
messages=[{"role": "user", "content": message}],
|
40 |
model="llama3-8b-8192",
|
41 |
)
|
|
|
42 |
return chat_completion.choices[0].message.content
|
43 |
|
44 |
# Function to generate the game story
|
45 |
def generate_game_story(environment, protagonist, antagonist):
|
|
|
|
|
|
|
46 |
message = f"Create a compelling game story set in {environment}, featuring {protagonist} as the protagonist and {antagonist} as the antagonist."
|
|
|
47 |
chat_completion = client.chat.completions.create(
|
48 |
messages=[{"role": "user", "content": message}],
|
49 |
model="llama3-8b-8192",
|
50 |
)
|
|
|
51 |
return chat_completion.choices[0].message.content
|
52 |
|
53 |
|
|
|
61 |
protagonist = st.sidebar.text_input("Enter the Protagonist:", placeholder="e.g., A young hacker with a mysterious past")
|
62 |
antagonist = st.sidebar.text_input("Enter the Antagonist:", placeholder="e.g., A corrupt government official controlling the city")
|
63 |
|
64 |
+
# Generate button
|
65 |
+
if st.sidebar.button("Generate"):
|
66 |
+
if not game_environment or not protagonist or not antagonist:
|
67 |
+
# If any of the fields are empty, show an error message
|
68 |
+
st.error("Please fill in all the fields (Game Environment, Protagonist, Antagonist) before generating the story.")
|
|
|
|
|
|
|
69 |
else:
|
70 |
+
# Main content layout
|
71 |
+
col1, col2 = st.columns(2)
|
72 |
|
73 |
+
# Column 1: Environment and Story
|
74 |
+
with col1:
|
75 |
+
st.header("Game Environment")
|
76 |
+
st.write(generate_game_environment(game_environment))
|
|
|
77 |
|
78 |
+
st.header("Game Story")
|
79 |
+
st.write(generate_game_story(game_environment, protagonist, antagonist))
|
|
|
|
|
|
|
|
|
|
|
80 |
|
81 |
+
# Column 2: Protagonist and Antagonist
|
82 |
+
with col2:
|
83 |
+
st.header("Protagonist")
|
84 |
+
st.write(generate_protagonist(protagonist))
|
85 |
+
|
86 |
+
st.header("Antagonist")
|
87 |
+
st.write(generate_antagonist(antagonist))
|