GitHunt
AS

asifnoushadsharafudeen/ai_story_generator

GPT-2 via Hugging Face Transformers --> Story creation through prompts.

Cover Image

๐Ÿค– 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:

  1. Phase 1 โ€“ Command-line GPT-2 story generator.
  2. Phase 2 โ€“ FastAPI backend with JSON-based generation.
  3. 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 the generate_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 /generate endpoint.

๐Ÿ“ธ Swagger UI Demo

Swagger UI Screenshot


๐Ÿ–ผ๏ธ 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

Gradio UI


๐Ÿง  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

asifnoushadsharafudeen/ai_story_generator | GitHunt