Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vision模型图片上传没压缩? #539

Open
lehhair opened this issue May 14, 2024 · 8 comments
Open

vision模型图片上传没压缩? #539

lehhair opened this issue May 14, 2024 · 8 comments

Comments

@lehhair
Copy link

lehhair commented May 14, 2024

上传大文件模型就报错,小的就正常

@BobDu
Copy link
Member

BobDu commented May 20, 2024

chagpt 自己会压缩分辨率的啊。
是大小直接超过20MB了都? 这个确实没有进一步处理。一般图片不至于这么大吧...

@lehhair
Copy link
Author

lehhair commented May 20, 2024

chagpt 自己会压缩分辨率的啊。 是大小直接超过20MB了都? 这个确实没有进一步处理。一般图片不至于这么大吧...

我也不知道为啥,实测nextweb是没问题的,小文件也没问题,4MB左右的都不行,下次我再排查一下试试吧,我用的oneapi转换的

@BobDu
Copy link
Member

BobDu commented May 20, 2024

前面加nginx了嘛? 如果有加的话需要调一下 nginx的 client_max_body_size

@lehhair
Copy link
Author

lehhair commented May 20, 2024

前面加nginx了嘛? 如果有加的话需要调一下 nginx的 client_max_body_size

加过了,不知道报错在什么地方,等我有空再次复现仔细查看一下日志再向您反馈,感谢

@lehhair
Copy link
Author

lehhair commented May 21, 2024

前面加nginx了嘛? 如果有加的话需要调一下 nginx的 client_max_body_size

确定了一下,就是我的api不兼容大文件,确实是需要压缩一下才能用🙃

@lehhair
Copy link
Author

lehhair commented May 22, 2024

前面加nginx了嘛? 如果有加的话需要调一下 nginx的 client_max_body_size

为了解决这个问题我用python弄了个图片压缩服务器,在请求api的时候多一次图片压缩的请求体转发

from flask import Flask, request, jsonify
import base64
import io
from PIL import Image

app = Flask(__name__)

@app.route('/', defaults={'path': ''}, methods=['POST'])
@app.route('/<path:path>', methods=['POST'])
def compress_image(path):
    data = request.get_json()

    image_data = data.get('image')

    image_bytes = base64.b64decode(image_data)

    image = Image.open(io.BytesIO(image_bytes))

    image = image.convert('RGB')

    quality = 80

    compressed_image_buffer = io.BytesIO()

    image.save(compressed_image_buffer, format='JPEG', optimize=True, quality=quality)

    compressed_image_buffer.seek(0)

    compressed_image_base64 = base64.b64encode(compressed_image_buffer.getvalue()).decode('utf-8')

    return jsonify({'image': compressed_image_base64})

if __name__ == '__main__':
    app.run()

@BobDu
Copy link
Member

BobDu commented May 24, 2024

nodejs有合适的库能干这个么。有的话可以考虑把这个功能集成到项目里面来。

@lehhair
Copy link
Author

lehhair commented May 24, 2024

nodejs有合适的库能干这个么。有的话可以考虑把这个功能集成到项目里面来。

前端的压缩方法挺多的,我只是不会js😵

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants