/ImageToTextProject

通过使用开源模型实现图片生成文章或者古诗诗词

Primary LanguagePython

ImageToTextProject

项目介绍

本项目基于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

LLM 配置

添加环境变量

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

运行截图

详情

详情

详情