AS
asifnoushadsharafudeen/ai_story_generator
GPT-2 via Hugging Face Transformers --> Story creation through prompts.
๐ค AI Story Generator using GPT-2
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.
๐ Project Overview
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.
โ Phase 1 โ Auto Story Generator (Python Script)
A minimal script that generates a story given a prompt.
๐ง Features
- GPT-2 powered text generation.
- Accepts prompt and optional context.
- Generation tuned for creativity and coherence (
temperature,top_p,repetition_penalty).
๐ File
generate.pyโ Contains thegenerate_story()function and CLI interface.
๐ Phase 2 โ FastAPI Integration (API Serving)
A FastAPI backend that exposes a POST endpoint /generate.
๐ง Features
- Receives prompt in JSON.
- Returns generated story in JSON.
- Swagger UI auto-enabled for testing.
๐ File
main.pyโ FastAPI app with/generateendpoint.
๐ธ Swagger UI Demo
๐ผ๏ธ Phase 3 โ Gradio Interface (Local UI)
A local browser-based UI for interactive story generation.
๐ง Features
- Clean and intuitive layout.
- Accepts prompt via UI.
- Displays story output instantly.
๐ File
app.pyโ Launches Gradio interface.
๐ธ Gradio UI Screenshot
๐ง Tech Stack
| 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 |
โ๏ธ Getting Started
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


