Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -5,11 +5,10 @@ class LotterySystem:
|
|
5 |
def __init__(self):
|
6 |
self.items = []
|
7 |
|
8 |
-
def
|
9 |
-
if item.strip()
|
10 |
-
|
11 |
-
|
12 |
-
return "請輸入有效的選項"
|
13 |
|
14 |
def draw_lottery(self):
|
15 |
if self.items:
|
@@ -18,12 +17,16 @@ class LotterySystem:
|
|
18 |
return "請先添加一些選項"
|
19 |
|
20 |
def get_items(self):
|
21 |
-
return
|
|
|
|
|
|
|
|
|
22 |
|
23 |
lottery = LotterySystem()
|
24 |
|
25 |
-
def
|
26 |
-
return lottery.
|
27 |
|
28 |
def draw_lottery_interface():
|
29 |
return lottery.draw_lottery()
|
@@ -31,22 +34,29 @@ def draw_lottery_interface():
|
|
31 |
def get_items_interface():
|
32 |
return lottery.get_items()
|
33 |
|
34 |
-
|
35 |
-
|
|
|
|
|
|
|
36 |
|
37 |
with gr.Row():
|
38 |
-
|
39 |
-
add_button = gr.Button("
|
40 |
|
41 |
output_add = gr.Textbox(label="添加結果")
|
42 |
-
add_button.click(
|
43 |
|
44 |
draw_button = gr.Button("抽籤")
|
45 |
output_draw = gr.Textbox(label="抽籤結果")
|
46 |
draw_button.click(draw_lottery_interface, outputs=output_draw)
|
47 |
|
48 |
-
show_items_button = gr.Button("
|
49 |
-
|
50 |
-
|
|
|
|
|
|
|
|
|
51 |
|
52 |
demo.launch()
|
|
|
5 |
def __init__(self):
|
6 |
self.items = []
|
7 |
|
8 |
+
def add_items(self, items):
|
9 |
+
new_items = [item.strip() for item in items.split('\n') if item.strip()]
|
10 |
+
self.items.extend(new_items)
|
11 |
+
return f"已添加: {len(new_items)} 個選項\n當前選項: {', '.join(self.items)}"
|
|
|
12 |
|
13 |
def draw_lottery(self):
|
14 |
if self.items:
|
|
|
17 |
return "請先添加一些選項"
|
18 |
|
19 |
def get_items(self):
|
20 |
+
return '\n'.join(self.items)
|
21 |
+
|
22 |
+
def update_items(self, items):
|
23 |
+
self.items = [item.strip() for item in items.split('\n') if item.strip()]
|
24 |
+
return f"已更新選項列表,當前共有 {len(self.items)} 個選項"
|
25 |
|
26 |
lottery = LotterySystem()
|
27 |
|
28 |
+
def add_items_interface(items):
|
29 |
+
return lottery.add_items(items)
|
30 |
|
31 |
def draw_lottery_interface():
|
32 |
return lottery.draw_lottery()
|
|
|
34 |
def get_items_interface():
|
35 |
return lottery.get_items()
|
36 |
|
37 |
+
def update_items_interface(items):
|
38 |
+
return lottery.update_items(items)
|
39 |
+
|
40 |
+
with gr.Blocks(title="改進的抽籤系統") as demo:
|
41 |
+
gr.Markdown("# 改進的抽籤系統")
|
42 |
|
43 |
with gr.Row():
|
44 |
+
input_items = gr.Textbox(label="輸入選項(每行一個)", lines=5)
|
45 |
+
add_button = gr.Button("批次添加選項")
|
46 |
|
47 |
output_add = gr.Textbox(label="添加結果")
|
48 |
+
add_button.click(add_items_interface, inputs=input_items, outputs=output_add)
|
49 |
|
50 |
draw_button = gr.Button("抽籤")
|
51 |
output_draw = gr.Textbox(label="抽籤結果")
|
52 |
draw_button.click(draw_lottery_interface, outputs=output_draw)
|
53 |
|
54 |
+
show_items_button = gr.Button("顯示/編輯所有選項")
|
55 |
+
edit_items = gr.Textbox(label="當前選項(可編輯)", lines=10)
|
56 |
+
update_button = gr.Button("更新選項")
|
57 |
+
update_result = gr.Textbox(label="更新結果")
|
58 |
+
|
59 |
+
show_items_button.click(get_items_interface, outputs=edit_items)
|
60 |
+
update_button.click(update_items_interface, inputs=edit_items, outputs=update_result)
|
61 |
|
62 |
demo.launch()
|