CoolFace
Apppublic

kong3333/react-a11y-auto-caption-server

sourceHugging Facemitupdated 5mo agoView on Hugging Face
0likes
README.md187 linesDownload Raw Back to root
1---2title: react-a11y-auto-caption-server3emoji: 🖼️4colorFrom: blue5colorTo: green6sdk: docker7app_port: 78608pinned: false9license: mit10---11 12# react-a11y-auto-caption-server13 14Local AI caption server for `react-a11y-auto-caption`.15 16Run a FastAPI image-captioning server with one command:17 18```bash19npx react-a11y-auto-caption-server20```21 22This server uses the ViT-GPT2 image captioning model to generate alt text for images.23 24---25 26## Features27 28- Run the server with `npx`29- Automatic Python environment setup30- Local-first image captioning31- Works with `react-a11y-auto-caption`32- Uses GPU if available, otherwise falls back to CPU33 34---35 36## Requirements37 38- Node.js 18+39- Python 3.8+40- pip41 42Check your environment:43 44```bash45node --version46python --version47pip --version48```49 50---51 52## Quick Start53 54```bash55npx react-a11y-auto-caption-server56```57 58The server starts at:59 60```txt61http://127.0.0.1:800062```63 64Caption endpoint:65 66```txt67http://127.0.0.1:8000/api/generate-caption68```69 70---71 72## First Run Notice73 74The first run may take a few minutes.75 76The CLI will:77 78- create a Python virtual environment79- install Python dependencies80- start the FastAPI server81 82The AI model may also be downloaded on the first caption request.  83After the first setup, future runs should be faster.84 85---86 87## Usage with React88 89Install the React package:90 91```bash92npm install react-a11y-auto-caption93```94 95Start the local server:96 97```bash98npx react-a11y-auto-caption-server99```100 101Use it in your app:102 103```tsx104import { SmartImage } from "react-a11y-auto-caption";105 106export default function Example() {107  return (108    <SmartImage109      src="/example.jpg"110      apiEndpoint="http://127.0.0.1:8000/api/generate-caption"111    />112  );113}114```115 116---117 118## API119 120### `POST /api/generate-caption`121 122Request:123 124- `Content-Type: multipart/form-data`125- Body field: `file`126 127Example:128 129```bash130curl -X POST "http://127.0.0.1:8000/api/generate-caption" \131  -F "file=@/path/to/image.jpg"132```133 134Response:135 136```json137{138  "status": "success",139  "caption": "a dog running through a grassy field"140}141```142 143---144 145## Manual Development146 147```bash148git clone https://github.com/kong33/SmartImage.git149cd SmartImage150 151python -m venv venv152.\venv\Scripts\activate153 154pip install -r requirements.txt155uvicorn main:app --host 127.0.0.1 --port 8000 --reload156```157 158For macOS/Linux:159 160```bash161source venv/bin/activate162```163 164---165 166## Environment167 168If you use CORS settings, create a `.env` file:169 170```env171ALLOWED_ORIGINS=http://localhost:3000,http://localhost:5173172```173 174Do not commit `.env`.175 176---177 178## Related179 180- `react-a11y-auto-caption`181 182---183 184## License185 186MIT187