Spaces:
Sleeping
Sleeping
Download app.py from Muqadas-13/Game: direct link, hf CLI and curl.
- Browser
- Download file 1.03 kB
-
https://huggingface.co/spaces/Muqadas-13/Game/resolve/main/app.py
- Command line
-
hf download hf://spaces/Muqadas-13/Game/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Muqadas-13/Game/resolve/main/app.py
1.03 kB
| import gradio as gr | |
| import random | |
| # Global variable to store the secret number | |
| secret_number = random.randint(1, 100) | |
| def guess_number(user_guess): | |
| global secret_number | |
| try: | |
| guess = int(user_guess) | |
| except ValueError: | |
| return "❌ Please enter a valid number." | |
| if guess < 1 or guess > 100: | |
| return "⚠️ Guess must be between 1 and 100." | |
| if guess < secret_number: | |
| return "🔻 Too low! Try again." | |
| elif guess > secret_number: | |
| return "🔺 Too high! Try again." | |
| else: | |
| # Reset the number after a correct guess | |
| secret_number = random.randint(1, 100) | |
| return "🎉 Correct! I've picked a new number. Try guessing again!" | |
| # Gradio interface | |
| iface = gr.Interface( | |
| fn=guess_number, | |
| inputs=gr.Textbox(label="Enter a number between 1 and 100"), | |
| outputs="text", | |
| title="🎯 Number Guessing Game", | |
| description="Guess the number I'm thinking of (between 1 and 100). I'll tell you if you're too high or too low." | |
| ) | |
| iface.launch() | |