Spaces:
Sleeping
Sleeping
File size: 1,509 Bytes
6170acf 300f268 6170acf 300f268 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import gradio as gr
import random
class LotterySystem:
def __init__(self):
self.items = []
def add_item(self, item):
if item.strip():
self.items.append(item.strip())
return f"已添加: {item}\n當前選項: {', '.join(self.items)}"
return "請輸入有效的選項"
def draw_lottery(self):
if self.items:
result = random.choice(self.items)
return f"抽籤結果: {result}"
return "請先添加一些選項"
def get_items(self):
return f"當前選項: {', '.join(self.items)}"
lottery = LotterySystem()
def add_item_interface(item):
return lottery.add_item(item)
def draw_lottery_interface():
return lottery.draw_lottery()
def get_items_interface():
return lottery.get_items()
with gr.Blocks(title="抽籤系統") as demo:
gr.Markdown("# 抽籤系統")
with gr.Row():
input_item = gr.Textbox(label="輸入選項")
add_button = gr.Button("添加選項")
output_add = gr.Textbox(label="添加結果")
add_button.click(add_item_interface, inputs=input_item, outputs=output_add)
draw_button = gr.Button("抽籤")
output_draw = gr.Textbox(label="抽籤結果")
draw_button.click(draw_lottery_interface, outputs=output_draw)
show_items_button = gr.Button("顯示所有選項")
output_items = gr.Textbox(label="當前選項")
show_items_button.click(get_items_interface, outputs=output_items)
demo.launch() |