-
Notifications
You must be signed in to change notification settings - Fork 6
/
img_search.py
56 lines (38 loc) · 1.01 KB
/
img_search.py
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
53
54
55
56
from typing import Optional
from arclet.alconna import Alconna, Args, namespace
class Text:
type = "text"
text: str
def __init__(self, t: str):
self.text = t
def __repr__(self):
return self.text
class At:
type = "At"
target: int
def __init__(self, t: int):
self.target = t
def __repr__(self):
return f"At:{self.target}"
class Image:
type = "image"
src: str
def __init__(self, url: str):
self.src = url
def __repr__(self):
return f"Image:{self.src}"
with namespace("test") as np:
np.to_text = lambda x: x.text if x.__class__ is Text else None
alc = Alconna(
"search",
Args.img(Image, optional=True),
)
@alc.bind()
def search(img: Optional[Image] = None):
if not img:
print("Please input your image")
else:
print(f"Searching {img.src} ...")
alc.parse([Text("search")])
alc.parse([Text("search"), Image("https://www.example.com/img")])
alc.parse([Text("search"), At(12345)])