AI Text Generator – Beginner Prototype
Submitted By: ____________________
Roll No.: ____________________
Course: ____________________
Date: ____________________
Abstract
This project demonstrates a simple Generative AI text generator for beginners using Python. It
takes a short prompt from the user and generates extended text using a pre-trained GPT-2 model.
The system uses only basic tools and modules, making it easy to run on any local machine. It
introduces students to AI text generation without complex installations or GPU requirements.
Objective
The objective of this project is to build a simple text generator that: 1. Takes a user prompt as input.
2. Generates coherent text using a pre-trained AI model. 3. Runs locally with minimal setup.
Tools & Modules
- Python 3.x
- pip (Python package installer)
- Modules:
• transformers (Hugging Face for pre-trained models)
• torch (backend for model computation)
Working Principle
1. User inputs a prompt.
2. The pre-trained model predicts the next words.
3. The system generates extended text based on the prompt.
Code
from transformers import pipeline
# Step 1: Load a pre-trained text generation model
generator = pipeline("text-generation", model="gpt2")
# Step 2: Take user input
prompt = input("Enter your prompt: ")
# Step 3: Generate text
result = generator(prompt, max_length=50, num_return_sequences=1)
# Step 4: Display output
print("\nGenerated Text:\n", result[0]['generated_text'])
How to Run
1. Save the file as text_generator.py
2. Open a terminal or command prompt.
3. Run: python text_generator.py
4. Type a prompt and view the generated output.
Output Example
Input Prompt AI Generated Output
AI will change the world AI will change the world in ways we can barely imagine. From healthcare innovation
Limitations
- Uses small model (gpt2) so output may not be perfect.
- Requires internet for first-time model download.
- Basic interface (text only).
Future Enhancements
- Add GUI using Tkinter or Streamlit.
- Add summarization or translation.
- Implement safety filters for inappropriate content.