33 lines
730 B
Python
33 lines
730 B
Python
|
import time
|
||
|
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
|
||
|
t1 = time.time()
|
||
|
ret = requests.post('http://pd4e.com:10090/api',
|
||
|
data={
|
||
|
'prompt':p,
|
||
|
'image':file2b64(i)
|
||
|
})
|
||
|
t2 = time.time()
|
||
|
print(ret.text, t2 - t1, 'seconds')
|