lethaq commited on
Commit
add810a
·
verified ·
1 Parent(s): 42550f4

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -24
app.py CHANGED
@@ -35,32 +35,31 @@ def get_current_time_in_timezone(timezone: str) -> str:
35
 
36
 
37
  @tool
38
- import random
39
- from typing import List
40
-
41
-
42
- @tool
43
- def get_something_to_read(user_tip: str) -> str:
44
- """
45
- 该工具根据用户提示随机推荐书籍。
46
  Args:
47
- user_tip: 一个字符串,代表用户提供的书籍推荐偏好或关键词,例如'fiction'(小说)、'history'(历史)、'romance'(浪漫)等。
48
- Returns:
49
- 一个字符串,代表随机推荐的书籍名称。
50
  """
51
- fiction_books = ["To Kill a Mockingbird", "1984", "Pride and Prejudice"]
52
- history_books = ["Sapiens: A Brief History of Humankind", "The Guns of August", "Guns, Germs, and Steel"]
53
- romance_books = ["Jane Eyre", "Wuthering Heights", "Outlander"]
54
-
55
- if "fiction" in user_tip.lower():
56
- return random.choice(fiction_books)
57
- elif "history" in user_tip.lower():
58
- return random.choice(history_books)
59
- elif "romance" in user_tip.lower():
60
- return random.choice(romance_books)
61
- else:
62
- all_books: List[str] = fiction_books + history_books + romance_books
63
- return random.choice(all_books)
 
 
 
 
 
 
64
 
65
 
66
 
 
35
 
36
 
37
  @tool
38
+ def generate_ascii_art(prompt: str, input_type: str = "text") -> str:
39
+ """根据文本或图像生成ASCII图形
 
 
 
 
 
 
40
  Args:
41
+ prompt: 文本内容或图片路径/URL
42
+ input_type: 输入类型,可选'text'或'image'
 
43
  """
44
+ try:
45
+ if input_type == "text":
46
+ # 使用FIGlet生成文本ASCII艺术(文献3)
47
+ from pyfiglet import Figlet
48
+ custom_fig = Figlet(font='standard')
49
+ return f"文本ASCII艺术:\n{custom_fig.renderText(prompt)}"
50
+
51
+ elif input_type == "image":
52
+ # 使用ascii-image-converter转换图像(文献5)
53
+ from ascii_image_converter import convert_image
54
+ result = convert_image(prompt, char_width=100)
55
+ return f"图像ASCII艺术:\n{result}"
56
+
57
+ return "错误:无效的输入类型,支持'text'或'image'"
58
+
59
+ except ImportError as e:
60
+ return f"错误:缺少依赖库,请安装 {e.name}"
61
+ except Exception as e:
62
+ return f"生成失败:{str(e)}"
63
 
64
 
65