CoolFace
Apppublic

Jaswin-27/MetaXSCALER_Hackathon

sourceHugging Faceupdated 6mo agoView on Hugging Face
0likes
ui.py40 linesDownload Raw Back to root
1import streamlit as st
2import requests
3
4API_URL = "https://Jaswin-27-life-simulator.hf.space"
5
6st.title("๐ŸŽฎ Life Simulator")
7
8# Initialize session state
9if "state" not in st.session_state:
10    res = requests.post(f"{API_URL}/reset")
11    st.session_state.state = res.json()
12
13state = st.session_state.state
14
15st.subheader("๐Ÿ“Š Current State")
16st.write(state)
17
18# Buttons
19col1, col2, col3 = st.columns(3)
20
21if col1.button("๐Ÿ’ผ Work"):
22    res = requests.post(f"{API_URL}/step", json={"action": "work"})
23    st.session_state.state = res.json()
24
25if col2.button("๐Ÿ˜ด Rest"):
26    res = requests.post(f"{API_URL}/step", json={"action": "rest"})
27    st.session_state.state = res.json()
28
29if col3.button("๐ŸŽฎ Play"):
30    res = requests.post(f"{API_URL}/step", json={"action": "play"})
31    st.session_state.state = res.json()
32
33# Refresh state
34st.write("### ๐Ÿ”„ Updated State")
35st.write(st.session_state.state)
36
37# Reset button
38if st.button("๐Ÿ” Reset Game"):
39    res = requests.post(f"{API_URL}/reset")
40    st.session_state.state = res.json()