This repository contains a FastAPI application that provides a simple text generation API using Hugging Face's transformers library. It leverages the google/flan-t5-small model to generate text based on input prompts, making it ideal for quick text generation or experimentation with NLP models.
- FastAPI Framework: A modern, fast (high-performance), web framework for building APIs with Python 3.9+.
- Text Generation Model: Uses Hugging Face's
google/flan-t5-smallmodel for text2text generation. - Dockerized Setup: Simplifies the process of building and running the app with Docker, ensuring compatibility across environments.
- API Endpoints:
/: A home endpoint that returns a simple greeting message./generate: Accepts atextquery parameter and returns generated text based on the input.
Make sure you have Docker installed, or you can run the app locally with Python 3.9+ and the required dependencies.
git clone https://github.com/yourusername/fastapi-text-generation-api.git
cd fastapi-text-generation-api-
Build the Docker Image: First, build the Docker image from the provided Dockerfile.
docker build -t fastapi-app . -
Run the Docker Container: Once the image is built, run the container on port 7860.
docker run -p 7860:7860 fastapi-app
If you'd like to run the app locally without Docker, make sure you have Python 3.9+ and the required dependencies installed:
-
Install the Requirements:
pip install -r requirements.txt
-
Start the FastAPI Server:
uvicorn app:app --host 0.0.0.0 --port 7860
Your app will be available at
http://localhost:7860.
- URL:
/ - Method:
GET - Response:
{ "message" : "Hello, World!" }
- URL:
/generate?text={input_text} - Method:
GET - Query Parameter:
text(string) - Input text to generate from. - Response:
{ "output" : "Generated text based on the input text." }
For a live demo of the text generation API, visit the Hugging Face Space:
Text Generation API on Hugging Face Space (click on Try it out button)
You can try out the API and explore further documentation and example queries there.
- FastAPI: Fast and asynchronous web framework for building APIs in Python.
- Hugging Face Transformers: Python library for state-of-the-art Natural Language Processing (NLP).
- Docker: Containerization for consistent and portable application deployment.