Spaces:
Sleeping
Sleeping
Deploy Myco from CI
Browse files- ui/gradio_app.py +0 -45
ui/gradio_app.py
CHANGED
|
@@ -1,9 +1,5 @@
|
|
| 1 |
"""Gradio app composition for Myco."""
|
| 2 |
|
| 3 |
-
import gradio as gr
|
| 4 |
-
|
| 5 |
-
from game.engine import collect_current, discover_mushroom, eat_current, myco_reply, study_current
|
| 6 |
-
from game.state import welcome_history
|
| 7 |
from __future__ import annotations
|
| 8 |
|
| 9 |
import gradio as gr
|
|
@@ -14,26 +10,6 @@ from models.mushroom import Mushroom
|
|
| 14 |
from ui.renderers import dex_markdown, forest_scene, hero_markdown, mushroom_card, progress_markdown
|
| 15 |
|
| 16 |
|
| 17 |
-
def explore(collection):
|
| 18 |
-
def explore(
|
| 19 |
-
collection: CollectionState,
|
| 20 |
-
) -> tuple[str, str, MushroomState, list[dict[str, str]], str, str]:
|
| 21 |
-
"""Gradio callback for the Start Exploring button."""
|
| 22 |
-
mushroom, current, history = discover_mushroom(collection)
|
| 23 |
-
return (
|
| 24 |
-
forest_scene(current, collection),
|
| 25 |
-
mushroom_card(mushroom),
|
| 26 |
-
current,
|
| 27 |
-
history,
|
| 28 |
-
dex_markdown(collection),
|
| 29 |
-
progress_markdown(collection),
|
| 30 |
-
)
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
def ask_myco(message, history, current):
|
| 34 |
-
from ui.renderers import dex_markdown, hero_markdown, mushroom_card, progress_markdown
|
| 35 |
-
|
| 36 |
-
|
| 37 |
def explore(collection: CollectionState) -> tuple[str, MushroomState, list[dict[str, str]], str, str]:
|
| 38 |
"""Gradio callback for the Start Exploring button."""
|
| 39 |
mushroom, current, history = discover_mushroom(collection)
|
|
@@ -49,7 +25,6 @@ def ask_myco(
|
|
| 49 |
return myco_reply(message, history, current)
|
| 50 |
|
| 51 |
|
| 52 |
-
def add_to_dex(current, collection, history):
|
| 53 |
def add_to_dex(
|
| 54 |
current: MushroomState | None,
|
| 55 |
collection: CollectionState,
|
|
@@ -66,13 +41,6 @@ def add_to_dex(
|
|
| 66 |
)
|
| 67 |
|
| 68 |
|
| 69 |
-
def study_mushroom(current, history, collection):
|
| 70 |
-
) -> tuple[CollectionState, str, list[dict[str, str]], str]:
|
| 71 |
-
"""Gradio callback for collecting the current mushroom."""
|
| 72 |
-
updated_collection, updated_history = collect_current(current, collection, history)
|
| 73 |
-
return updated_collection, dex_markdown(updated_collection), updated_history, progress_markdown(updated_collection)
|
| 74 |
-
|
| 75 |
-
|
| 76 |
def study_mushroom(
|
| 77 |
current: MushroomState | None,
|
| 78 |
history: list[dict[str, str]],
|
|
@@ -88,13 +56,6 @@ def study_mushroom(
|
|
| 88 |
)
|
| 89 |
|
| 90 |
|
| 91 |
-
def eat_mushroom(current, history):
|
| 92 |
-
) -> tuple[MushroomState | None, str, list[dict[str, str]]]:
|
| 93 |
-
"""Gradio callback for studying the current mushroom."""
|
| 94 |
-
updated_current, updated_history = study_current(current, history)
|
| 95 |
-
return updated_current, mushroom_card_from_state(updated_current), updated_history
|
| 96 |
-
|
| 97 |
-
|
| 98 |
def eat_mushroom(
|
| 99 |
current: MushroomState | None,
|
| 100 |
history: list[dict[str, str]],
|
|
@@ -103,7 +64,6 @@ def eat_mushroom(
|
|
| 103 |
return eat_current(current, history)
|
| 104 |
|
| 105 |
|
| 106 |
-
def mushroom_card_from_state(current):
|
| 107 |
def mushroom_card_from_state(current: MushroomState | None) -> str:
|
| 108 |
"""Render a mushroom card from Gradio state."""
|
| 109 |
if current is None:
|
|
@@ -111,7 +71,6 @@ def mushroom_card_from_state(current: MushroomState | None) -> str:
|
|
| 111 |
return mushroom_card(Mushroom.from_dict(current))
|
| 112 |
|
| 113 |
|
| 114 |
-
def build_app():
|
| 115 |
def build_app() -> gr.Blocks:
|
| 116 |
"""Build the Gradio interface for Hugging Face Spaces."""
|
| 117 |
with gr.Blocks(title="Myco") as demo:
|
|
@@ -145,7 +104,6 @@ def build_app() -> gr.Blocks:
|
|
| 145 |
explore_button.click(
|
| 146 |
explore,
|
| 147 |
inputs=[collection],
|
| 148 |
-
outputs=[scene, discovery, current_mushroom, chat, dex, progress],
|
| 149 |
outputs=[discovery, current_mushroom, chat, dex, progress],
|
| 150 |
)
|
| 151 |
ask_button.click(ask_myco, inputs=[prompt, chat, current_mushroom], outputs=[prompt, chat])
|
|
@@ -160,9 +118,6 @@ def build_app() -> gr.Blocks:
|
|
| 160 |
inputs=[current_mushroom, chat, collection],
|
| 161 |
outputs=[current_mushroom, scene, discovery, chat],
|
| 162 |
)
|
| 163 |
-
outputs=[collection, dex, chat, progress],
|
| 164 |
-
)
|
| 165 |
-
study_button.click(study_mushroom, inputs=[current_mushroom, chat], outputs=[current_mushroom, discovery, chat])
|
| 166 |
eat_button.click(eat_mushroom, inputs=[current_mushroom, chat], outputs=[chat])
|
| 167 |
|
| 168 |
return demo
|
|
|
|
| 1 |
"""Gradio app composition for Myco."""
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
from __future__ import annotations
|
| 4 |
|
| 5 |
import gradio as gr
|
|
|
|
| 10 |
from ui.renderers import dex_markdown, forest_scene, hero_markdown, mushroom_card, progress_markdown
|
| 11 |
|
| 12 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
def explore(collection: CollectionState) -> tuple[str, MushroomState, list[dict[str, str]], str, str]:
|
| 14 |
"""Gradio callback for the Start Exploring button."""
|
| 15 |
mushroom, current, history = discover_mushroom(collection)
|
|
|
|
| 25 |
return myco_reply(message, history, current)
|
| 26 |
|
| 27 |
|
|
|
|
| 28 |
def add_to_dex(
|
| 29 |
current: MushroomState | None,
|
| 30 |
collection: CollectionState,
|
|
|
|
| 41 |
)
|
| 42 |
|
| 43 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 44 |
def study_mushroom(
|
| 45 |
current: MushroomState | None,
|
| 46 |
history: list[dict[str, str]],
|
|
|
|
| 56 |
)
|
| 57 |
|
| 58 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 59 |
def eat_mushroom(
|
| 60 |
current: MushroomState | None,
|
| 61 |
history: list[dict[str, str]],
|
|
|
|
| 64 |
return eat_current(current, history)
|
| 65 |
|
| 66 |
|
|
|
|
| 67 |
def mushroom_card_from_state(current: MushroomState | None) -> str:
|
| 68 |
"""Render a mushroom card from Gradio state."""
|
| 69 |
if current is None:
|
|
|
|
| 71 |
return mushroom_card(Mushroom.from_dict(current))
|
| 72 |
|
| 73 |
|
|
|
|
| 74 |
def build_app() -> gr.Blocks:
|
| 75 |
"""Build the Gradio interface for Hugging Face Spaces."""
|
| 76 |
with gr.Blocks(title="Myco") as demo:
|
|
|
|
| 104 |
explore_button.click(
|
| 105 |
explore,
|
| 106 |
inputs=[collection],
|
|
|
|
| 107 |
outputs=[discovery, current_mushroom, chat, dex, progress],
|
| 108 |
)
|
| 109 |
ask_button.click(ask_myco, inputs=[prompt, chat, current_mushroom], outputs=[prompt, chat])
|
|
|
|
| 118 |
inputs=[current_mushroom, chat, collection],
|
| 119 |
outputs=[current_mushroom, scene, discovery, chat],
|
| 120 |
)
|
|
|
|
|
|
|
|
|
|
| 121 |
eat_button.click(eat_mushroom, inputs=[current_mushroom, chat], outputs=[chat])
|
| 122 |
|
| 123 |
return demo
|