Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,12 +1,76 @@
|
|
1 |
import os
|
2 |
import streamlit as st
|
|
|
3 |
from groq import Groq
|
4 |
|
5 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
6 |
client = Groq(
|
7 |
-
api_key=
|
8 |
)
|
9 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
10 |
# Streamlit app title and description
|
11 |
st.title("StoryForge")
|
12 |
st.write("StoryForge is an app designed to help game developers generate comprehensive Game Design Documents by providing essential details about their game's environment, protagonist, and antagonist.")
|
@@ -20,37 +84,30 @@ antagonist = st.sidebar.text_input("Enter the Antagonist:", placeholder="e.g., A
|
|
20 |
# Main content layout
|
21 |
col1, col2 = st.columns(2)
|
22 |
|
23 |
-
# Column 1
|
24 |
with col1:
|
25 |
st.header("Game Environment")
|
26 |
-
|
|
|
|
|
|
|
27 |
|
28 |
st.header("Game Story")
|
29 |
if game_environment and protagonist and antagonist:
|
30 |
-
|
31 |
-
message = f"Create a compelling game story set in {game_environment}, featuring {protagonist} as the protagonist and {antagonist} as the antagonist."
|
32 |
-
|
33 |
-
# Get completion from Groq
|
34 |
-
chat_completion = client.chat.completions.create(
|
35 |
-
messages=[
|
36 |
-
{
|
37 |
-
"role": "user",
|
38 |
-
"content": message,
|
39 |
-
}
|
40 |
-
],
|
41 |
-
model="llama3-8b-8192",
|
42 |
-
)
|
43 |
-
|
44 |
-
# Return generated story content
|
45 |
-
story = chat_completion.choices[0].message.content
|
46 |
-
st.write(story)
|
47 |
else:
|
48 |
st.write("Please provide details in the sidebar.")
|
49 |
|
50 |
-
# Column 2
|
51 |
with col2:
|
52 |
st.header("Protagonist")
|
53 |
-
|
|
|
|
|
|
|
54 |
|
55 |
st.header("Antagonist")
|
56 |
-
|
|
|
|
|
|
|
|
1 |
import os
|
2 |
import streamlit as st
|
3 |
+
from dotenv import load_dotenv
|
4 |
from groq import Groq
|
5 |
|
6 |
+
# Load environment variables from .env file
|
7 |
+
load_dotenv()
|
8 |
+
|
9 |
+
# Fetch API key from environment variables
|
10 |
+
api_key = os.getenv("groq_api_key")
|
11 |
+
|
12 |
+
# Initialize Groq client using the API key from .env
|
13 |
client = Groq(
|
14 |
+
api_key=api_key, # API key fetched securely from .env
|
15 |
)
|
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 |
+
|
74 |
# Streamlit app title and description
|
75 |
st.title("StoryForge")
|
76 |
st.write("StoryForge is an app designed to help game developers generate comprehensive Game Design Documents by providing essential details about their game's environment, protagonist, and antagonist.")
|
|
|
84 |
# Main content layout
|
85 |
col1, col2 = st.columns(2)
|
86 |
|
87 |
+
# Column 1: Environment and Story
|
88 |
with col1:
|
89 |
st.header("Game Environment")
|
90 |
+
if game_environment:
|
91 |
+
st.write(generate_game_environment(game_environment))
|
92 |
+
else:
|
93 |
+
st.write("Please provide a game environment in the sidebar.")
|
94 |
|
95 |
st.header("Game Story")
|
96 |
if game_environment and protagonist and antagonist:
|
97 |
+
st.write(generate_game_story(game_environment, protagonist, antagonist))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
98 |
else:
|
99 |
st.write("Please provide details in the sidebar.")
|
100 |
|
101 |
+
# Column 2: Protagonist and Antagonist
|
102 |
with col2:
|
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 |
st.header("Antagonist")
|
110 |
+
if antagonist:
|
111 |
+
st.write(generate_antagonist(antagonist))
|
112 |
+
else:
|
113 |
+
st.write("Please provide an antagonist in the sidebar.")
|