2024-11-12 17:57:40 +08:00
|
|
|
import time
|
2024-11-12 16:39:19 +08:00
|
|
|
import requests
|
|
|
|
import base64
|
|
|
|
|
|
|
|
def file2b64(file_path):
|
|
|
|
# 读取文件内容
|
|
|
|
with open(file_path, 'rb') as file:
|
|
|
|
file_content = file.read()
|
|
|
|
|
|
|
|
# 将文件内容转换为Base64编码
|
|
|
|
base64_encoded_data = base64.b64encode(file_content)
|
|
|
|
|
|
|
|
# 将Base64编码的数据转换为字符串
|
|
|
|
base64_encoded_str = base64_encoded_data.decode('utf-8')
|
|
|
|
|
|
|
|
return base64_encoded_str
|
|
|
|
|
|
|
|
while True:
|
|
|
|
print('prompt:')
|
|
|
|
p = input()
|
|
|
|
print('input image path:')
|
|
|
|
i = input()
|
|
|
|
if p == '' or i == '':
|
|
|
|
continue
|
2024-11-12 17:57:40 +08:00
|
|
|
t1 = time.time()
|
2024-11-12 17:59:43 +08:00
|
|
|
ret = requests.post('http://pd4e.com:10090/api',
|
|
|
|
data={
|
2024-11-12 16:39:19 +08:00
|
|
|
'prompt':p,
|
|
|
|
'image':file2b64(i)
|
|
|
|
})
|
2024-11-12 17:57:40 +08:00
|
|
|
t2 = time.time()
|
|
|
|
print(ret.text, t2 - t1, 'seconds')
|