hackmebroo commited on
Commit
e4274a2
·
verified ·
1 Parent(s): 21622be

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -6
app.py CHANGED
@@ -9,13 +9,14 @@ from Gradio_UI import GradioUI
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def random_polyphonic_chars(_: str, __: str) -> str:
13
- """Generates 10 random Chinese polyphonic characters (多音字).
14
  Args:
15
- _: Unused argument.
16
- __: Unused argument.
17
  """
18
  import random
 
19
  polyphonic_chars = [
20
  "行", "重", "长", "乐", "和",
21
  "难", "好", "觉", "着", "藏",
@@ -23,8 +24,17 @@ def random_polyphonic_chars(_: str, __: str) -> str:
23
  "干", "差", "空", "折", "弹"
24
  ]
25
 
26
- selected = random.sample(polyphonic_chars, 10)
27
- return "随机选出的10个多音字是:" + "、".join(selected)
 
 
 
 
 
 
 
 
 
28
 
29
  @tool
30
  def get_current_time_in_timezone(timezone: str) -> str:
 
9
 
10
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
+ def random_polyphonic_chars(n_str: str, _: str) -> str:
13
+ """随机生成n个多音字.
14
  Args:
15
+ n_str: Number of polyphonic characters to generate (as string).
16
+ _: Unused second argument.
17
  """
18
  import random
19
+
20
  polyphonic_chars = [
21
  "行", "重", "长", "乐", "和",
22
  "难", "好", "觉", "着", "藏",
 
24
  "干", "差", "空", "折", "弹"
25
  ]
26
 
27
+ try:
28
+ n = int(n_str)
29
+ if n <= 0:
30
+ return "请输入大于0的数字。"
31
+ if n > len(polyphonic_chars):
32
+ return f"最多只能生成 {len(polyphonic_chars)} 个不同的多音字。"
33
+
34
+ selected = random.sample(polyphonic_chars, n)
35
+ return f"随机生成的 {n} 个多音字是:" + "、".join(selected)
36
+ except ValueError:
37
+ return "请输入有效的整数作为参数。"
38
 
39
  @tool
40
  def get_current_time_in_timezone(timezone: str) -> str: