Spaces:
Sleeping

byte-vortex commited on
Commit
ffc9cc9
ยท
verified ยท
1 Parent(s): 738800d

Deploy Myco from CI

Browse files
Files changed (1) hide show
  1. 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
- .gradio-container { background: #1a1a2e !important; }
166
- .gr-html, iframe, .html-container {
167
- transition: none !important;
168
- animation: none !important;
169
- }
170
- /* Prevent white flash on component updates */
171
- * {
172
- transition: opacity 0.15s ease !important;
173
- }
174
- .pending, .generating {
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
- # โ”€โ”€ State โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
186
- current_mushroom = gr.State(None)
187
- collection = gr.State([])
188
- player_position = gr.State(START_POSITION)
189
 
190
- # โ”€โ”€ Hero โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
191
- gr.HTML(hero_markdown())
192
-
193
- with gr.Tabs(selected="home") as tabs:
194
-
195
- # โ”€โ”€ HOME โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€
196
- with gr.Tab("๐Ÿ  Home", id="home"):
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
- with gr.Row():
215
- with gr.Column(scale=1):
216
- search_button = gr.Button("๐ŸŽฎ Search Clearing", variant="primary", size="lg")
217
- with gr.Column(scale=1):
218
- gr.Markdown("**Move Myco**")
219
- with gr.Row():
220
- gr.HTML("<div></div>")
221
- north_button = gr.Button("โฌ†๏ธ", size="sm")
222
- gr.HTML("<div></div>")
223
- with gr.Row():
224
- west_button = gr.Button("โฌ…๏ธ", size="sm")
225
- pick_button = gr.Button("๐Ÿ„ Pick", variant="primary", size="sm")
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"):