Upload folder using huggingface_hub
Browse files- server/gradio_ui.py +60 -19
- server/standalone_app.py +7 -4
server/gradio_ui.py
CHANGED
|
@@ -71,42 +71,91 @@ def make_guess(guess_input: str, history: List) -> Tuple[str, str, str, str, str
|
|
| 71 |
if history.empty:
|
| 72 |
history = []
|
| 73 |
else:
|
| 74 |
-
|
|
|
|
| 75 |
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
| 82 |
|
| 83 |
# Format status message
|
| 84 |
if obs.hint == "correct":
|
| 85 |
status = f"๐ **Congratulations!** You found the number {guess} in {len(history)} attempts!"
|
| 86 |
hint_display = "โจ **Last Hint:** ๐ฏ CORRECT! You won!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 87 |
elif obs.hint == "game over":
|
| 88 |
secret = obs.metadata.get('secret_number', '?')
|
| 89 |
status = f"๐ข **Game Over!** The number was {secret}. Try again!"
|
| 90 |
hint_display = f"โ **Last Hint:** Out of attempts. The answer was {secret}."
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 91 |
elif obs.hint.startswith("invalid"):
|
| 92 |
status = "โ ๏ธ **Invalid Guess!** Number must be between 1 and 100."
|
| 93 |
hint_display = f"โ ๏ธ **Last Hint:** {obs.hint}"
|
|
|
|
| 94 |
elif obs.hint == "higher":
|
| 95 |
status = f"๐ The number is **HIGHER** than {guess}"
|
| 96 |
hint_display = f"โฌ๏ธ **Last Hint:** Go HIGHER than {guess}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 97 |
elif obs.hint == "lower":
|
| 98 |
status = f"๐ The number is **LOWER** than {guess}"
|
| 99 |
hint_display = f"โฌ๏ธ **Last Hint:** Go LOWER than {guess}"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
else:
|
| 101 |
status = f"๐ค Hint: {obs.hint}"
|
| 102 |
hint_display = f"๐ก **Last Hint:** {obs.hint}"
|
|
|
|
| 103 |
|
| 104 |
# Update other displays
|
| 105 |
attempts = f"๐ **Attempts Remaining:** {obs.attempts_remaining}"
|
| 106 |
-
reward_display = f"๐ **Total Reward:** {sum(float(h['Reward']) for h in history):.1f}"
|
| 107 |
|
| 108 |
-
#
|
| 109 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
|
| 111 |
# Clear input for next guess
|
| 112 |
next_input = ""
|
|
@@ -123,15 +172,7 @@ def create_gradio_interface() -> gr.Blocks:
|
|
| 123 |
"""
|
| 124 |
# ๐ฏ Number Guessing Game Environment
|
| 125 |
|
| 126 |
-
Welcome to the **OpenEnv Number Guessing Game**!
|
| 127 |
-
a secret number between 1 and 100. You'll get hints after each guess to help you narrow
|
| 128 |
-
down the answer.
|
| 129 |
-
|
| 130 |
-
**Perfect for:**
|
| 131 |
-
- ๐ค Training RL agents with binary search strategies
|
| 132 |
-
- ๐ง Testing reasoning and planning algorithms
|
| 133 |
-
- ๐ Learning reinforcement learning concepts
|
| 134 |
-
- ๐ฎ Having fun!
|
| 135 |
"""
|
| 136 |
)
|
| 137 |
|
|
|
|
| 71 |
if history.empty:
|
| 72 |
history = []
|
| 73 |
else:
|
| 74 |
+
# Convert DataFrame to list of lists (not dicts!)
|
| 75 |
+
history = history.values.tolist()
|
| 76 |
|
| 77 |
+
# Append new guess as a list, not a dict
|
| 78 |
+
history.append([
|
| 79 |
+
len(history) + 1, # Guess #
|
| 80 |
+
guess, # Your Guess
|
| 81 |
+
obs.hint, # Hint
|
| 82 |
+
f"{obs.reward:+.1f}" # Reward
|
| 83 |
+
])
|
| 84 |
|
| 85 |
# Format status message
|
| 86 |
if obs.hint == "correct":
|
| 87 |
status = f"๐ **Congratulations!** You found the number {guess} in {len(history)} attempts!"
|
| 88 |
hint_display = "โจ **Last Hint:** ๐ฏ CORRECT! You won!"
|
| 89 |
+
welcome_msg = f"""
|
| 90 |
+
# ๐ Victory!
|
| 91 |
+
|
| 92 |
+
You successfully found the secret number **{guess}**!
|
| 93 |
+
|
| 94 |
+
It took you **{len(history)} attempts**.
|
| 95 |
+
|
| 96 |
+
Click "๐ New Game" to play again!
|
| 97 |
+
"""
|
| 98 |
elif obs.hint == "game over":
|
| 99 |
secret = obs.metadata.get('secret_number', '?')
|
| 100 |
status = f"๐ข **Game Over!** The number was {secret}. Try again!"
|
| 101 |
hint_display = f"โ **Last Hint:** Out of attempts. The answer was {secret}."
|
| 102 |
+
welcome_msg = f"""
|
| 103 |
+
# ๐ข Game Over
|
| 104 |
+
|
| 105 |
+
You ran out of attempts!
|
| 106 |
+
|
| 107 |
+
The secret number was **{secret}**.
|
| 108 |
+
|
| 109 |
+
Click "๐ New Game" to try again!
|
| 110 |
+
"""
|
| 111 |
elif obs.hint.startswith("invalid"):
|
| 112 |
status = "โ ๏ธ **Invalid Guess!** Number must be between 1 and 100."
|
| 113 |
hint_display = f"โ ๏ธ **Last Hint:** {obs.hint}"
|
| 114 |
+
welcome_msg = None # Don't update
|
| 115 |
elif obs.hint == "higher":
|
| 116 |
status = f"๐ The number is **HIGHER** than {guess}"
|
| 117 |
hint_display = f"โฌ๏ธ **Last Hint:** Go HIGHER than {guess}"
|
| 118 |
+
welcome_msg = f"""
|
| 119 |
+
# ๐ฏ Number Guessing Game
|
| 120 |
+
|
| 121 |
+
Keep going! The number is **between {guess + 1} and 100**.
|
| 122 |
+
|
| 123 |
+
You have **{obs.attempts_remaining} attempts** remaining.
|
| 124 |
+
|
| 125 |
+
Try a higher number!
|
| 126 |
+
"""
|
| 127 |
elif obs.hint == "lower":
|
| 128 |
status = f"๐ The number is **LOWER** than {guess}"
|
| 129 |
hint_display = f"โฌ๏ธ **Last Hint:** Go LOWER than {guess}"
|
| 130 |
+
welcome_msg = f"""
|
| 131 |
+
# ๐ฏ Number Guessing Game
|
| 132 |
+
|
| 133 |
+
Keep going! The number is **between 1 and {guess - 1}**.
|
| 134 |
+
|
| 135 |
+
You have **{obs.attempts_remaining} attempts** remaining.
|
| 136 |
+
|
| 137 |
+
Try a lower number!
|
| 138 |
+
"""
|
| 139 |
else:
|
| 140 |
status = f"๐ค Hint: {obs.hint}"
|
| 141 |
hint_display = f"๐ก **Last Hint:** {obs.hint}"
|
| 142 |
+
welcome_msg = None # Don't update
|
| 143 |
|
| 144 |
# Update other displays
|
| 145 |
attempts = f"๐ **Attempts Remaining:** {obs.attempts_remaining}"
|
|
|
|
| 146 |
|
| 147 |
+
# Calculate total reward safely from list of lists
|
| 148 |
+
total_reward = 0.0
|
| 149 |
+
for h in history:
|
| 150 |
+
try:
|
| 151 |
+
# h is now a list: [guess_num, guess, hint, reward_str]
|
| 152 |
+
reward_str = h[3] # Index 3 is the reward column
|
| 153 |
+
# Remove '+' sign if present and convert to float
|
| 154 |
+
total_reward += float(reward_str.replace('+', ''))
|
| 155 |
+
except (ValueError, TypeError, IndexError):
|
| 156 |
+
pass
|
| 157 |
+
|
| 158 |
+
reward_display = f"๐ **Total Reward:** {total_reward:.1f}"
|
| 159 |
|
| 160 |
# Clear input for next guess
|
| 161 |
next_input = ""
|
|
|
|
| 172 |
"""
|
| 173 |
# ๐ฏ Number Guessing Game Environment
|
| 174 |
|
| 175 |
+
Welcome to the **OpenEnv Number Guessing Game**!
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 176 |
"""
|
| 177 |
)
|
| 178 |
|
server/standalone_app.py
CHANGED
|
@@ -221,11 +221,14 @@ try:
|
|
| 221 |
from gradio_ui import gradio_app
|
| 222 |
import gradio as gr
|
| 223 |
|
| 224 |
-
# Mount Gradio app at /web path
|
| 225 |
-
app = gr.mount_gradio_app(app, gradio_app, path="/web")
|
| 226 |
-
except ImportError:
|
| 227 |
# Gradio not available, skip web interface
|
| 228 |
-
|
|
|
|
|
|
|
|
|
|
| 229 |
|
| 230 |
|
| 231 |
@app.get("/")
|
|
|
|
| 221 |
from gradio_ui import gradio_app
|
| 222 |
import gradio as gr
|
| 223 |
|
| 224 |
+
# Mount Gradio app at /web path (Gradio 5.x syntax)
|
| 225 |
+
app = gr.mount_gradio_app(app, gradio_app, path="/web", root_path="/web")
|
| 226 |
+
except ImportError as e:
|
| 227 |
# Gradio not available, skip web interface
|
| 228 |
+
print(f"Gradio not available: {e}")
|
| 229 |
+
except Exception as e:
|
| 230 |
+
# Other errors during Gradio mounting
|
| 231 |
+
print(f"Error mounting Gradio: {e}")
|
| 232 |
|
| 233 |
|
| 234 |
@app.get("/")
|