This project is part of my Generative AI Engineering Portfolio. It uses GPT-2 via Hugging Face Transformers to generate short creative stories based on user-provided prompts.
The project is built in three progressive phases:
- Phase 1 – Command-line GPT-2 story generator.
- Phase 2 – FastAPI backend with JSON-based generation.
- Phase 3 – Gradio-powered interactive UI.
A minimal script that generates a story given a prompt.
- GPT-2 powered text generation.
- Accepts prompt and optional context.
- Generation tuned for creativity and coherence (
temperature,top_p,repetition_penalty).
generate.py– Contains thegenerate_story()function and CLI interface.
A FastAPI backend that exposes a POST endpoint /generate.
- Receives prompt in JSON.
- Returns generated story in JSON.
- Swagger UI auto-enabled for testing.
main.py– FastAPI app with/generateendpoint.
A local browser-based UI for interactive story generation.
- Clean and intuitive layout.
- Accepts prompt via UI.
- Displays story output instantly.
app.py– Launches Gradio interface.
| Tool / Library | Purpose |
|---|---|
| Python | Core programming language |
| Hugging Face Transformers | GPT-2 model pipeline |
| FastAPI | API backend |
| Uvicorn | ASGI server for FastAPI |
| Pydantic | Data validation |
| Gradio | Web UI for LLM interaction |
git clone https://github.com/asifnoushadsharafudeen/ai-story-generator.git cd ai-story-generator pip install -r requirements.txt python gradio_ui.py # or python main.py for API version


