mirror of
https://github.com/haiwen/seahub.git
synced 2025-08-14 05:05:58 +00:00
* image_caption * update * update * update * update * update --------- Co-authored-by: zheng.shen <zheng.shen@seafile.com>
36 lines
946 B
Python
36 lines
946 B
Python
import logging
|
|
import requests
|
|
import jwt
|
|
import time
|
|
from urllib.parse import urljoin
|
|
|
|
from seahub.settings import SEAFILE_AI_SECRET_KEY, SEAFILE_AI_SERVER_URL
|
|
|
|
logger = logging.getLogger(__name__)
|
|
|
|
|
|
def gen_headers():
|
|
payload = {'exp': int(time.time()) + 300, }
|
|
token = jwt.encode(payload, SEAFILE_AI_SECRET_KEY, algorithm='HS256')
|
|
return {"Authorization": "Token %s" % token}
|
|
|
|
|
|
def verify_ai_config():
|
|
if not SEAFILE_AI_SERVER_URL or not SEAFILE_AI_SECRET_KEY:
|
|
return False
|
|
return True
|
|
|
|
|
|
def image_caption(params):
|
|
headers = gen_headers()
|
|
url = urljoin(SEAFILE_AI_SERVER_URL, '/api/v1/image-caption/')
|
|
resp = requests.post(url, json=params, headers=headers, timeout=30)
|
|
return resp
|
|
|
|
|
|
def generate_summary(params):
|
|
headers = gen_headers()
|
|
url = urljoin(SEAFILE_AI_SERVER_URL, '/api/v1/generate-summary')
|
|
resp = requests.post(url, json=params, headers=headers, timeout=30)
|
|
return resp
|