Skip to content
/ GPT Public

Text Generation demo using GPT-2 + Gradio/FastAPI

Notifications You must be signed in to change notification settings

pyyush/GPT

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Text Generation GPT-2

This repository contains code for a text generation demo using GPT-2 with Gradio/FastAPI. The GPT-2 model is a language model developed by OpenAI that generates text based on the input text prompt.

Setup

Before running the code, please ensure that you have installed the required dependencies mentioned in the requirements.txt file. You can do this by running the following command in your terminal:

pip3 install -r requirements.txt

FastAPI

To run the FastAPI web server, you can use the following command in your terminal:

uvicorn fastAPI:app 

Once the server is up and running, you can access the Swagger documentation for the API at http://127.0.0.1:8000/docs
Alternatively, you can use the curl command to generate text as shown below:

curl -X 'POST' \
  'http://127.0.0.1:8000/generate' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "prompt": "I love playing volleyball",
  "max_tokens_to_generate": 50
}'

Gradio

To run the Gradio web application, you can use the following command in your terminal:

python3 Gradio.py

Once the server is up and running, you can access the web application at http://127.0.0.1:7860
The web application allows you to enter a text prompt and generate text using the GPT-2 model. You can also select the maximum number of tokens to generate.