Spaces:
Build error
Build error
Download utils.py from ShynBui/Describe_things: direct link, hf CLI and curl.
- Browser
- Download file 711 Bytes
-
https://huggingface.co/spaces/ShynBui/Describe_things/resolve/main/utils.py
- Command line
-
hf download hf://spaces/ShynBui/Describe_things/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/ShynBui/Describe_things/resolve/main/utils.py
711 Bytes
| from pkgs import QuotaManager, executor | |
| import os | |
| import base64 | |
| from PIL import Image | |
| import io | |
| def answer(selected, input_img): | |
| # print(input_img) | |
| # print(selected) | |
| buffer = io.BytesIO() | |
| input_img.save(buffer, format="PNG") | |
| image_data = base64.b64encode(buffer.getvalue()).decode('utf-8') | |
| # Xác định model_input dựa trên tùy chọn của người dùng | |
| model_input = os.environ['PROMPT'] if selected == "Describe things" else os.environ['PROMPT_OCR'] | |
| # Thực thi mô hình với hình ảnh đã mã hóa và đầu vào mô hình | |
| response = executor.execute_with_image(user_input='', model_input=model_input, base64_image=image_data) | |
| return response |