Ishita Bhattacharyya commited on
Commit
949d943
·
1 Parent(s): 1ddede7

Add minimal Gradio UI

Browse files
Files changed (1) hide show
  1. app.py +73 -0
app.py CHANGED
@@ -0,0 +1,73 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import random
3
+ import time
4
+
5
+ def game_loop(user_input, history):
6
+ if not user_input:
7
+ return history, gr.update(), gr.update(), gr.update(), ""
8
+ time.sleep(0.6)
9
+ tactician_thought = {
10
+ "status": "Active",
11
+ "analysis": f"Player used '{user_input}'. Pattern match: Balanced.",
12
+ "confidence": round(random.uniform(0.7, 0.98), 2),
13
+ "counter_tactic": "Parry",
14
+ }
15
+ bot_response = f"The Goblin reacts to your '{user_input}' — it shuffles and prepares to counter."
16
+ history.append({"role": "user", "content": user_input})
17
+ history.append({"role": "assistant", "content": bot_response})
18
+ new_player_hp = max(0, random.randint(8, 20))
19
+ new_enemy_hp = max(0, random.randint(5, 20))
20
+ return history, tactician_thought, new_player_hp, new_enemy_hp, ""
21
+
22
+ custom_css = """
23
+ body { background-color: #0b0b0c; color: #e6e6e6; font-family: Inter, Arial, sans-serif; }
24
+ .gradio-container { background: transparent !important; padding: 12px; }
25
+ #hud-container { background: rgba(255,255,255,0.02); padding:8px 10px; border-radius:8px; margin-bottom:12px; }
26
+ """
27
+
28
+ with gr.Blocks(title="EvoDungeon") as demo:
29
+ with gr.Row(elem_id="hud-container", variant="panel"):
30
+ with gr.Column(scale=1):
31
+ gr.Markdown("### ⚔️ **EvoDungeon**")
32
+ with gr.Column(scale=2):
33
+ player_hp = gr.Slider(label="Player HP", minimum=0, maximum=20, value=20, interactive=False)
34
+ with gr.Column(scale=0, min_width=40):
35
+ gr.Markdown("### VS")
36
+ with gr.Column(scale=2):
37
+ enemy_hp = gr.Slider(label="Goblin Scout HP", minimum=0, maximum=20, value=20, interactive=False)
38
+
39
+ with gr.Row():
40
+ with gr.Column(scale=2):
41
+ chatbot = gr.Chatbot(label="Adventure Log", height=350)
42
+ with gr.Row():
43
+ msg = gr.Textbox(label="Action Input", placeholder="Type an action (e.g., 'I swing my sword')", scale=4, autofocus=True)
44
+ btn = gr.Button("Act", variant="primary", scale=1)
45
+
46
+ with gr.Column(scale=1):
47
+ gr.Markdown("### 🔥 Battle Mind")
48
+ brain_output = gr.JSON(value={"status": "Idle", "analysis": "Waiting for input..."}, label="Real-time Analysis")
49
+ gr.Markdown("### 🎒 Inventory")
50
+ gr.Dataframe(
51
+ headers=["Item", "Qty"],
52
+ value=[["Rusty Sword", 1], ["Health Potion", 2], ["Torch", 1]],
53
+ interactive=False,
54
+ row_count=3
55
+ )
56
+ with gr.Accordion("📜 Data Vault ", open=False):
57
+ gr.Markdown("*No vector DB connected*")
58
+ gr.Textbox(value="Goblins fear fire and light.", label="Retrieved Context", interactive=False)
59
+
60
+ triggers = [msg.submit, btn.click]
61
+ for trigger in triggers:
62
+ trigger(
63
+ game_loop,
64
+ inputs=[msg, chatbot],
65
+ outputs=[chatbot, brain_output, player_hp, enemy_hp, msg],
66
+ )
67
+
68
+ if __name__ == "__main__":
69
+ demo.launch(
70
+ theme=gr.themes.Monochrome(radius_size=gr.themes.sizes.radius_md),
71
+ css=custom_css
72
+ #share=True
73
+ )