本项目基于Hugging Face的transformers库,实现了图片到文本的任务。
# python version == 3.11.2
pip install -r requirements.txt -i https://pypi.tuna.tsinghua.edu.cn/simple- 文件比较大,如果失败请多尝试,或者单独把模型下载到本地
- 文档https://hf-mirror.com/
把下载的models解压到predict_model 下面
目录结构
predict_model
├── __init__.py
├── base_model.py
├── bicl_model.py
├── models
│ └── blip-image-captioning-large
│ ├── README.md
│ ├── config.json
│ ├── model.safetensors
│ ├── preprocessor_config.json
│ ├── pytorch_model.bin
│ ├── special_tokens_map.json
│ ├── tf_model.h5
│ ├── tokenizer.json
│ ├── tokenizer_config.json
│ └── vocab.txt
# linux or mac 设置环境变量
export HF_ENDPOINT=https://hf-mirror.com
# windows cmd 设置环境变量
set HF_ENDPOINT=https://hf-mirror.com
# Windows Powershell
$env:HF_ENDPOINT="https://hf-mirror.com"
# 下载模型
# 地址https://hf-mirror.com/Salesforce/blip-image-captioning-large/tree/main
cd predict_model
huggingface-cli download --resume-download --local-dir-use-symlinks False Salesforce/blip-image-captioning-large --local-dir models/blip-image-captioning-large
cp .env.example .env目前支持讯飞、chatgpt
- xunfei
讯飞开放平台账号、APPID、APIKey、API_SECRET 具体可参考讯飞开放平台 目前讯飞提供了免费token,可申请试用,有效期为一年,参考这个介绍讯飞api,申请文档 需要实名认证,几分钟就可以认证好了
- chatgpt
申请完成后,会获得一个API Key,将其填入.env文件中
python manage.py makemigrations
python manage.py migrate
python manage.py runserver


