Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- ui/gradio_app.py +55 -95
ui/gradio_app.py
CHANGED
|
@@ -160,108 +160,68 @@ def _safe_pos(position):
|
|
| 160 |
|
| 161 |
def build_app():
|
| 162 |
with gr.Blocks(title="Myco โ AI Forest Game", theme=gr.themes.Soft()) as demo:
|
|
|
|
| 163 |
gr.HTML("""
|
| 164 |
<style>
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
opacity: 0.85 !important;
|
| 176 |
-
background: transparent !important;
|
| 177 |
-
}
|
| 178 |
-
/* Hide the white overlay Gradio adds during updates */
|
| 179 |
-
.progress-level, .progress-level-inner {
|
| 180 |
-
display: none !important;
|
| 181 |
-
}
|
| 182 |
</style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 183 |
""")
|
| 184 |
|
| 185 |
-
#
|
| 186 |
-
current_mushroom = gr.State(None)
|
| 187 |
-
collection = gr.State([])
|
| 188 |
-
player_position = gr.State(START_POSITION)
|
| 189 |
|
| 190 |
-
|
| 191 |
-
|
| 192 |
-
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
gr.Markdown(HOME_MARKDOWN)
|
| 198 |
-
gr.HTML(home_forest_markdown())
|
| 199 |
-
start_play_button = gr.Button(
|
| 200 |
-
"๐ Enter the Forest", variant="primary", size="lg"
|
| 201 |
-
)
|
| 202 |
-
gr.Markdown(f"*{hf_companion_status()}*")
|
| 203 |
-
|
| 204 |
-
# โโ PLAY โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 205 |
-
with gr.Tab("๐ฎ Play", id="play"):
|
| 206 |
-
gr.HTML(game_intro_markdown())
|
| 207 |
-
|
| 208 |
-
# Forest scene + controls
|
| 209 |
-
scene = gr.HTML(
|
| 210 |
-
forest_scene(None, EMPTY_COLLECTION, START_POSITION),
|
| 211 |
-
elem_id="forest-scene",
|
| 212 |
-
)
|
| 213 |
|
| 214 |
-
|
| 215 |
-
|
| 216 |
-
|
| 217 |
-
|
| 218 |
-
|
| 219 |
-
|
| 220 |
-
|
| 221 |
-
|
| 222 |
-
|
| 223 |
-
|
| 224 |
-
|
| 225 |
-
|
| 226 |
-
east_button = gr.Button("โก๏ธ", size="sm")
|
| 227 |
-
with gr.Row():
|
| 228 |
-
gr.HTML("<div></div>")
|
| 229 |
-
south_button = gr.Button("โฌ๏ธ", size="sm")
|
| 230 |
-
gr.HTML("<div></div>")
|
| 231 |
-
|
| 232 |
-
# Quest log
|
| 233 |
-
status = gr.Markdown(
|
| 234 |
-
game_status_markdown(None, EMPTY_COLLECTION, START_POSITION)
|
| 235 |
-
)
|
| 236 |
-
|
| 237 |
-
# Discovery card + action buttons + chat
|
| 238 |
-
with gr.Row(equal_height=True):
|
| 239 |
-
with gr.Column(scale=2):
|
| 240 |
-
gr.Markdown("### ๐ Current Discovery")
|
| 241 |
-
discovery = gr.Markdown(mushroom_card(None))
|
| 242 |
-
with gr.Row():
|
| 243 |
-
study_button = gr.Button("๐ Study", variant="secondary")
|
| 244 |
-
collect_button = gr.Button("๐ Collect", variant="secondary")
|
| 245 |
-
with gr.Row():
|
| 246 |
-
whisper_button = gr.Button("๐ Follow Whisper", variant="secondary")
|
| 247 |
-
eat_button = gr.Button("๐ฝ๏ธ Eat?", variant="stop")
|
| 248 |
-
|
| 249 |
-
with gr.Column(scale=3):
|
| 250 |
-
gr.Markdown("### ๐ฌ Myco Chat")
|
| 251 |
-
chat = gr.Chatbot(
|
| 252 |
-
value=cast(Any, welcome_history()),
|
| 253 |
-
label="Myco",
|
| 254 |
-
height=400,
|
| 255 |
-
show_label=False,
|
| 256 |
-
)
|
| 257 |
-
with gr.Row():
|
| 258 |
-
prompt = gr.Textbox(
|
| 259 |
-
placeholder="Ask Myco anything about the forest...",
|
| 260 |
-
show_label=False,
|
| 261 |
-
scale=4,
|
| 262 |
-
lines=1,
|
| 263 |
-
)
|
| 264 |
-
ask_button = gr.Button("Ask ๐", variant="primary", scale=1)
|
| 265 |
|
| 266 |
# โโ MYCODEX โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 267 |
with gr.Tab("๐ MycoDex"):
|
|
|
|
| 160 |
|
| 161 |
def build_app():
|
| 162 |
with gr.Blocks(title="Myco โ AI Forest Game", theme=gr.themes.Soft()) as demo:
|
| 163 |
+
# โโ 1. Game Feel: Keyboard Inputs & CSS Animations โโ
|
| 164 |
gr.HTML("""
|
| 165 |
<style>
|
| 166 |
+
/* The 'Pop Up' Effect */
|
| 167 |
+
@keyframes pop {
|
| 168 |
+
0% { transform: scale(0.8); opacity: 0; }
|
| 169 |
+
80% { transform: scale(1.1); }
|
| 170 |
+
100% { transform: scale(1); opacity: 1; }
|
| 171 |
+
}
|
| 172 |
+
.mushroom-spawn { animation: pop 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275); }
|
| 173 |
+
|
| 174 |
+
/* Responsive Dark Theme */
|
| 175 |
+
.gradio-container { background: #0b0e14 !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
</style>
|
| 177 |
+
|
| 178 |
+
<script>
|
| 179 |
+
// Pac-Man Style Keyboard Navigation
|
| 180 |
+
document.addEventListener('keydown', function(event) {
|
| 181 |
+
if (['INPUT', 'TEXTAREA'].includes(event.target.nodeName)) return;
|
| 182 |
+
|
| 183 |
+
const keyMap = {
|
| 184 |
+
'w': 'btn-n', 'ArrowUp': 'btn-n',
|
| 185 |
+
'a': 'btn-w', 'ArrowLeft': 'btn-w',
|
| 186 |
+
's': 'btn-s', 'ArrowDown': 'btn-s',
|
| 187 |
+
'd': 'btn-e', 'ArrowRight': 'btn-e',
|
| 188 |
+
'e': 'btn-pick' // 'E' to pick
|
| 189 |
+
};
|
| 190 |
+
|
| 191 |
+
const btnId = keyMap[event.key];
|
| 192 |
+
const btn = document.getElementById(btnId);
|
| 193 |
+
if (btn) {
|
| 194 |
+
btn.click();
|
| 195 |
+
// Visual feedback for the click
|
| 196 |
+
btn.style.transform = 'scale(0.95)';
|
| 197 |
+
setTimeout(() => btn.style.transform = 'scale(1)', 100);
|
| 198 |
+
}
|
| 199 |
+
});
|
| 200 |
+
</script>
|
| 201 |
""")
|
| 202 |
|
| 203 |
+
# ... [State and Hero blocks remain the same] ...
|
|
|
|
|
|
|
|
|
|
| 204 |
|
| 205 |
+
with gr.Tab("๐ฎ Play", id="play"):
|
| 206 |
+
# Forest Scene
|
| 207 |
+
scene = gr.HTML(
|
| 208 |
+
forest_scene(None, EMPTY_COLLECTION, START_POSITION),
|
| 209 |
+
elem_id="forest-scene",
|
| 210 |
+
elem_classes="mushroom-spawn" # Apply the pop animation
|
| 211 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 212 |
|
| 213 |
+
with gr.Row():
|
| 214 |
+
# D-Pad Layout
|
| 215 |
+
with gr.Column(scale=1):
|
| 216 |
+
gr.Markdown("### ๐งญ Move")
|
| 217 |
+
with gr.Row():
|
| 218 |
+
north_button = gr.Button("โฌ๏ธ", size="sm", elem_id="btn-n")
|
| 219 |
+
with gr.Row():
|
| 220 |
+
west_button = gr.Button("โฌ
๏ธ", size="sm", elem_id="btn-w")
|
| 221 |
+
pick_button = gr.Button("๐ Pick", variant="primary", size="sm", elem_id="btn-pick")
|
| 222 |
+
east_button = gr.Button("โก๏ธ", size="sm", elem_id="btn-e")
|
| 223 |
+
with gr.Row():
|
| 224 |
+
south_button = gr.Button("โฌ๏ธ", size="sm", elem_id="btn-s")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 225 |
|
| 226 |
# โโ MYCODEX โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
|
| 227 |
with gr.Tab("๐ MycoDex"):
|