An AI-powered poem generator with a web interface, built using HuggingFace's Inference API, the OpenAI Python SDK, and FastAPI.
🎨 Enter a topic: ocean
📜 Your Poem:
The waves crash softly on the shore,
A rhythm ancient, rich with lore,
The sea breathes deep, the tides align,
In every drop, a world divine...
- 🎨 Generate poems on any topic via a web interface
- 🤖 Powered by Kimi-K2 model via HuggingFace Inference API
- 🌐 FastAPI web server with interactive HTML UI
- 🔐 Secure token management with
.env - 📄 Auto-generated API docs at
/docsand/redoc - ⚡ Fast async responses with Uvicorn
| Technology | Role |
|---|---|
| Python 3.10+ | Core language |
| FastAPI | Web framework |
| Uvicorn | ASGI server |
| HuggingFace Inference API | AI model provider |
| OpenAI SDK | API client (pointed to HuggingFace) |
| Jinja2 | HTML templating |
| python-dotenv | Environment variable management |
- Python 3.10+
- A HuggingFace account + API token
# 1. Clone the repository
git clone https://github.com/Felbrou/huggingface-projectOne.git
cd huggingface-projectOne
# 2. Create and activate virtual environment
python -m venv venv
source venv/bin/activate # Mac/Linux
venv\Scripts\activate # Windows
# 3. Install dependencies
pip install -r requirements.txt
# 4. Configure your token
cp .env.example .env
# Open .env and add your HuggingFace tokenCreate a .env file based on .env.example:
HF_TOKEN=your_huggingface_token_here
Get your token at 👉 https://huggingface.co/settings/tokens
uvicorn app.api:app --reloadThen open your browser at:
http://127.0.0.1:8000 ← Web UI
http://127.0.0.1:8000/docs ← Interactive API docs
http://127.0.0.1:8000/redoc ← Clean API docs
python main.pyhuggingface-projectOne/
│
├── app/
│ ├── __init__.py # Makes app a Python package
│ └── api.py # FastAPI routes and logic
│
├── templates/
│ └── index.html # Web UI template
│
├── main.py # Original CLI script
├── .env # 🔴 Secret tokens (never commit!)
├── .env.example # ✅ Token template (safe to share)
├── requirements.txt # Python dependencies
├── .gitignore # Files excluded from Git
└── README.md # This file
| Method | Endpoint | Description |
|---|---|---|
GET |
/ |
Renders the web UI |
POST |
/generate |
Generates a poem from a topic |
openai
python-dotenv
fastapi
uvicorn
jinja2
python-multipart
Install all with:
pip install -r requirements.txtBrowser → GET / → FastAPI → renders index.html
User types topic
Browser → POST /generate → FastAPI → HuggingFace API → poem → renders page
- ✅ Never commit your
.envfile - ✅ Use
.env.exampleto show required variables - ✅
.envandvenv/are listed in.gitignore
- Add poem style selector (haiku, sonnet, free verse)
- Save generated poems to a file
- Compare output from multiple models
- Deploy to Railway / Render
- Add poem history/gallery
MIT License — feel free to use and modify!
Felbrou
- GitHub: @Felbrou