lukmanaj commited on
Commit
18b61a0
·
verified ·
1 Parent(s): a92ab4a

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +77 -0
app.py ADDED
@@ -0,0 +1,77 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from game_world import GameWorld, GameSession
3
+
4
+ # Initialize game
5
+ world = GameWorld()
6
+ game_session = GameSession(world)
7
+
8
+ def main_game_loop(message, history):
9
+ """Main game loop function for Gradio interface"""
10
+ return game_session.run_action(message, history)
11
+
12
+ # Create Gradio interface
13
+ def create_interface():
14
+ with gr.Blocks(theme=gr.themes.Soft(), title="Mythic Realms") as demo:
15
+ gr.HTML("""
16
+ <div style="text-align: center; padding: 20px;">
17
+ <h1>🏰 Mythic Realms: AI Fantasy RPG</h1>
18
+ <p>Embark on an epic adventure in Aethermoor, a world of floating cities and sky whales!</p>
19
+ <p><em>Type 'start game' to begin your journey</em></p>
20
+ </div>
21
+ """)
22
+
23
+ chatbot = gr.Chatbot(
24
+ height=500,
25
+ placeholder="🎮 Ready to start your adventure? Type 'start game' to begin!",
26
+ show_label=False,
27
+ container=True,
28
+ bubble_full_width=False
29
+ )
30
+
31
+ with gr.Row():
32
+ msg = gr.Textbox(
33
+ placeholder="What do you do next? (e.g., 'Look around', 'Talk to Captain Zara', 'Explore the docks')",
34
+ container=False,
35
+ scale=4
36
+ )
37
+ submit_btn = gr.Button("🚀 Act", scale=1, variant="primary")
38
+
39
+ with gr.Row():
40
+ gr.Examples(
41
+ examples=[
42
+ "Start game",
43
+ "Look around the docks",
44
+ "Talk to Captain Zara Windwhisper",
45
+ "Explore the market",
46
+ "Ask about sky ships",
47
+ "Check my inventory",
48
+ "Look for adventure"
49
+ ],
50
+ inputs=msg
51
+ )
52
+
53
+ # Set up the chat interface
54
+ def respond(message, history):
55
+ response = main_game_loop(message, history)
56
+ history.append((message, response))
57
+ return history, ""
58
+
59
+ msg.submit(respond, [msg, chatbot], [chatbot, msg])
60
+ submit_btn.click(respond, [msg, chatbot], [chatbot, msg])
61
+
62
+ gr.HTML("""
63
+ <div style="text-align: center; margin-top: 20px; padding: 10px; background-color: #f0f0f0; border-radius: 10px;">
64
+ <p><strong>🎯 Game Tips:</strong></p>
65
+ <p>• Use natural language to describe your actions</p>
66
+ <p>• Interact with NPCs to learn about the world</p>
67
+ <p>• Manage your inventory wisely</p>
68
+ <p>• Explore different locations for unique adventures</p>
69
+ </div>
70
+ """)
71
+
72
+ return demo
73
+
74
+ # Launch the app
75
+ if __name__ == "__main__":
76
+ demo = create_interface()
77
+ demo.launch()