Spaces:
Runtime error
Runtime error
Commit
·
d0a1189
1
Parent(s):
74fa87d
✨ Add Casino game functionality: implement Roulette and Slots games with betting options; integrate into Gradio interface.
Browse files
app.py
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
from pymongo import MongoClient
|
|
|
|
| 2 |
from dotenv import load_dotenv
|
| 3 |
from Purify import PurifyHtml
|
| 4 |
from typing import Literal
|
|
@@ -191,6 +192,53 @@ def Plot(GiveExamplePrompt: bool = True) -> list[str]:
|
|
| 191 |
else:
|
| 192 |
return [Prompt, '']
|
| 193 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 194 |
# ╭─────────────────────────────╮
|
| 195 |
# │ Text Processing Tools │
|
| 196 |
# ╰─────────────────────────────╯
|
|
@@ -445,6 +493,15 @@ with gradio.Blocks(
|
|
| 445 |
PlotExampleOutput = gradio.Text(label='Example Plot Prompt 📜', interactive=False)
|
| 446 |
PlotBtn = gradio.Button('Get Plot 🎥', variant='primary')
|
| 447 |
PlotBtn.click(Plot, inputs=[PlotExample], outputs=[PlotOutput, PlotExampleOutput])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 448 |
|
| 449 |
with gradio.TabItem('Text Processing 📝'):
|
| 450 |
with gradio.TabItem('Text Reversal 🔄'):
|
|
|
|
| 1 |
from pymongo import MongoClient
|
| 2 |
+
from collections import Counter
|
| 3 |
from dotenv import load_dotenv
|
| 4 |
from Purify import PurifyHtml
|
| 5 |
from typing import Literal
|
|
|
|
| 192 |
else:
|
| 193 |
return [Prompt, '']
|
| 194 |
|
| 195 |
+
def Casino(Game: Literal['Roulette', 'Slots'], Input: None | Literal['Red', 'Black', 'Green'], Bet: float) -> str:
|
| 196 |
+
'''Generate a random casino game result.
|
| 197 |
+
Args:
|
| 198 |
+
Game (Literal['Roulette', 'Slots']): The casino game to simulate.
|
| 199 |
+
Input (None | Literal['Red', 'Black', 'Green']): The input color for Roulette.
|
| 200 |
+
Bet (float): The amount of money to bet.
|
| 201 |
+
Returns:
|
| 202 |
+
str: A random casino game result.
|
| 203 |
+
'''
|
| 204 |
+
match Game:
|
| 205 |
+
case 'Roulette':
|
| 206 |
+
if Input is None:
|
| 207 |
+
return 'Place your bet on a color (Red, Black, Green) for Roulette.'
|
| 208 |
+
else:
|
| 209 |
+
Payout = {
|
| 210 |
+
'red': 2,
|
| 211 |
+
'black': 2,
|
| 212 |
+
'green': 18
|
| 213 |
+
}
|
| 214 |
+
Wheel = ['green'] + ['red'] * 18 + ['black'] * 18
|
| 215 |
+
Result = random.choice(Wheel)
|
| 216 |
+
if Result == Input.lower():
|
| 217 |
+
return f'You played Roulette and won! 🎉 You bet €{Bet} on {Input} and the result was {Result.capitalize()}.\nYou\'ve won €{Bet * Payout[Result]}'
|
| 218 |
+
else:
|
| 219 |
+
return f'You played Roulette and lost! 😢 You bet €{Bet} on {Input} and the result was {Result.capitalize()}.'
|
| 220 |
+
|
| 221 |
+
case 'Slots':
|
| 222 |
+
Reels = ['🍒', '🍋', '🍊', '🍉', '🍇', '🔔', '⭐']
|
| 223 |
+
SpinResult = random.choices(Reels, k=3)
|
| 224 |
+
Counts = Counter(SpinResult)
|
| 225 |
+
MostCommon = Counts.most_common(1)[0]
|
| 226 |
+
Symbol, Count = MostCommon
|
| 227 |
+
|
| 228 |
+
if Count == 3:
|
| 229 |
+
if Symbol == '⭐':
|
| 230 |
+
return f'You played Slots and hit the jackpot! 🎰 You spun [{' | '.join(SpinResult)}] and won €{Bet * 50}!'
|
| 231 |
+
elif Symbol == '🔔':
|
| 232 |
+
return f'You played Slots and won! 🎉 You spun [{' | '.join(SpinResult)}] and won €{Bet * 25}!'
|
| 233 |
+
elif Symbol == '🍒':
|
| 234 |
+
return f'You played Slots and won! 🎉 You spun [{' | '.join(SpinResult)}] and won €{Bet * 10}!'
|
| 235 |
+
else:
|
| 236 |
+
return f'You played Slots and won! 🎉 You spun [{' | '.join(SpinResult)}] and won €{Bet * 5}!'
|
| 237 |
+
elif Count == 2:
|
| 238 |
+
return f'You played Slots and got a pair! 🎰 You spun [{' | '.join(SpinResult)}] and won €{Bet * 1.5}!'
|
| 239 |
+
else:
|
| 240 |
+
return f'You played Slots and lost! 😢 You spun [{' | '.join(SpinResult)}] and won nothing.'
|
| 241 |
+
|
| 242 |
# ╭─────────────────────────────╮
|
| 243 |
# │ Text Processing Tools │
|
| 244 |
# ╰─────────────────────────────╯
|
|
|
|
| 493 |
PlotExampleOutput = gradio.Text(label='Example Plot Prompt 📜', interactive=False)
|
| 494 |
PlotBtn = gradio.Button('Get Plot 🎥', variant='primary')
|
| 495 |
PlotBtn.click(Plot, inputs=[PlotExample], outputs=[PlotOutput, PlotExampleOutput])
|
| 496 |
+
|
| 497 |
+
with gradio.TabItem('Casino Games 🎰'):
|
| 498 |
+
with gradio.Group():
|
| 499 |
+
CasinoGame = gradio.Radio(label='Casino Game 🎲', choices=['Roulette', 'Slots'], value='Roulette', interactive=True)
|
| 500 |
+
CasinoBet = gradio.Slider(label='Bet Amount 💰', minimum=1, maximum=1000, step=0.5, value=10, interactive=True)
|
| 501 |
+
CasinoWheel = gradio.Radio(label='Roulette Color 🎡', choices=['Red', 'Black', 'Green'], value=None, interactive=True)
|
| 502 |
+
CasinoOutput = gradio.Text(label='Casino Result 🎰', interactive=False)
|
| 503 |
+
CasinoBtn = gradio.Button('Play Casino 🎲', variant='primary')
|
| 504 |
+
CasinoBtn.click(Casino, inputs=[CasinoGame, CasinoWheel, CasinoBet], outputs=CasinoOutput)
|
| 505 |
|
| 506 |
with gradio.TabItem('Text Processing 📝'):
|
| 507 |
with gradio.TabItem('Text Reversal 🔄'):
|