import gradio as gr
from game_world import GameWorld, GameSession
# Initialize game
world = GameWorld()
game_session = GameSession(world)
def main_game_loop(message, history):
"""Main game loop function for Gradio interface"""
return game_session.run_action(message, history)
# Create Gradio interface
def create_interface():
with gr.Blocks(theme=gr.themes.Soft(), title="Mythic Realms") as demo:
gr.HTML("""
🏰 Mythic Realms: AI Fantasy RPG
Embark on an epic adventure in Aethermoor, a world of floating cities and sky whales!
Type 'start game' to begin your journey
""")
chatbot = gr.Chatbot(
height=500,
placeholder="🎮 Ready to start your adventure? Type 'start game' to begin!",
show_label=False,
container=True,
bubble_full_width=False
)
with gr.Row():
msg = gr.Textbox(
placeholder="What do you do next? (e.g., 'Look around', 'Talk to Captain Zara', 'Explore the docks')",
container=False,
scale=4
)
submit_btn = gr.Button("🚀 Act", scale=1, variant="primary")
with gr.Row():
gr.Examples(
examples=[
"Start game",
"Look around the docks",
"Talk to Captain Zara Windwhisper",
"Explore the market",
"Ask about sky ships",
"Check my inventory",
"Look for adventure"
],
inputs=msg
)
# Set up the chat interface
def respond(message, history):
response = main_game_loop(message, history)
history.append((message, response))
return history, ""
msg.submit(respond, [msg, chatbot], [chatbot, msg])
submit_btn.click(respond, [msg, chatbot], [chatbot, msg])
gr.HTML("""
🎯 Game Tips:
• Use natural language to describe your actions
• Interact with NPCs to learn about the world
• Manage your inventory wisely
• Explore different locations for unique adventures
""")
return demo
# Launch the app
if __name__ == "__main__":
demo = create_interface()
demo.launch()