story-forge / app.py
Arfa-ilyas's picture
Update app.py
9660c93 verified
import os
import streamlit as st
from dotenv import load_dotenv
from transformers import pipeline
# Load environment variables from .env file
load_dotenv()
# Initialize the Hugging Face pipeline for text generation
api_key = os.getenv("HF_API_KEY")
if not api_key:
st.error("HF_API_KEY environment variable not set.")
st.stop()
# Set up the text generation pipeline
generator = pipeline(
"text-generation",
model="huggingface/claude-sonnet-3.5",
tokenizer="huggingface/claude-sonnet-3.5",
config={"use_auth_token": api_key}
)
def generate_content(prompt):
"""
Generate content using the Claude Sonnet 3.5 model from Hugging Face.
"""
response = generator(prompt, max_length=200, num_return_sequences=1)
return response[0]['generated_text']
def generate_game_environment():
"""
Generate a description of the game environment using the Claude Sonnet 3.5 model.
"""
prompt = "Describe an intriguing and immersive game environment."
return generate_content(prompt)
def generate_game_story():
"""
Generate a captivating game story using the Claude Sonnet 3.5 model.
"""
prompt = "Create a compelling and engaging game story."
return generate_content(prompt)
def generate_antagonist():
"""
Generate a detailed description of a game antagonist using the Claude Sonnet 3.5 model.
"""
prompt = "Describe a complex and intriguing antagonist for a game."
return generate_content(prompt)
def generate_protagonist():
"""
Generate a detailed description of a game protagonist using the Claude Sonnet 3.5 model.
"""
prompt = "Describe a compelling and relatable protagonist for a game."
return generate_content(prompt)
# Streamlit app
st.title("Story-Forge")
st.write("""
Welcome to Story-Forge! This app helps game developers generate a Game Design Document by collecting information about your game's environment, protagonists, and antagonists. Fill in the details in the sidebar, and see your GDD organized below.
""")
# Sidebar for user input
st.sidebar.header("Game Details")
game_environment_input = st.sidebar.text_input("Game Environment", "e.g., Fantasy Forest, Cyberpunk City")
antagonist_input = st.sidebar.text_input("Antagonist", "e.g., Dark Sorcerer, Rogue AI")
protagonist_input = st.sidebar.text_input("Protagonist", "e.g., Brave Knight, Skilled Hacker")
# Buttons to generate content
if st.sidebar.button("Generate Game Environment"):
game_environment = generate_game_environment()
else:
game_environment = game_environment_input
if st.sidebar.button("Generate Antagonist"):
antagonist = generate_antagonist()
else:
antagonist = antagonist_input
if st.sidebar.button("Generate Protagonist"):
protagonist = generate_protagonist()
else:
protagonist = protagonist_input
if st.sidebar.button("Generate Game Story"):
game_story = generate_game_story()
else:
game_story = "Please generate a story to see it here."
# Main content area with two columns
col1, col2 = st.columns(2)
with col1:
st.header("Game Environment")
st.write(f"**Environment:** {game_environment}")
with col2:
st.header("Game Story")
st.write(f"**Protagonist:** {protagonist}")
st.write(f"**Antagonist:** {antagonist}")
st.write(f"**Story:** {game_story}")
# Add any additional content or formatting here if needed