lukmanaj's picture
Update app.py
fe01c8c verified
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("""
<div style="text-align: center; padding: 20px;">
<h1>๐Ÿฐ Mythic Realms: AI Fantasy RPG</h1>
<p>Embark on an epic adventure in Aethermoor, a world of floating cities and sky whales!</p>
<p><em>Type 'start game' to begin your journey</em></p>
</div>
""")
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("""
<div style="text-align: center; margin-top: 20px; padding: 10px; background-color: #aba0ab; border-radius: 10px;">
<p><strong>๐ŸŽฏ Game Tips:</strong></p>
<p>โ€ข Use natural language to describe your actions</p>
<p>โ€ข Interact with NPCs to learn about the world</p>
<p>โ€ข Manage your inventory wisely</p>
<p>โ€ข Explore different locations for unique adventures</p>
</div>
""")
return demo
# Launch the app
if __name__ == "__main__":
demo = create_interface()
demo.launch()