forked from LemonQu-GIT/ChatGLM-6B-Engineering
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclip_utils.py
More file actions
29 lines (26 loc) · 887 Bytes
/
clip_utils.py
File metadata and controls
29 lines (26 loc) · 887 Bytes
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
from PIL import Image
from clip_interrogator import Config, Interrogator
import requests, json
global ci
ci = Interrogator(Config(clip_model_name="ViT-L-14/openai"))
def clip_image(filename):
global ci
image = Image.open(filename).convert('RGB')
return ci.interrogate(image) # type: ignore
def clip_trans(word):
url = "http://fanyi.youdao.com/translate?smartresult=dict&smartresult=rule&smartresult=ugc&sessionFrom=null"
key = {
"type": "AUTO",
"i": word,
"doctype": "json",
"version": "2.1",
"keyfrom": "fanyi.web",
"ue": "UTF-8",
"action": "FY_BY_CLICKBUTTON",
"typoResult": "true",
}
response = requests.post(url, data=key)
if response.status_code == 200:
list_trans = response.text
result = json.loads(list_trans)
return result["translateResult"][0][0]["tgt"]