
GPT-2 text generation
Pricing
Pay per usage
Go to Store

GPT-2 text generation
This actor uses the GPT-2 language model to generate text.
0.0 (0)
Pricing
Pay per usage
3
Total users
203
Monthly users
28
Runs succeeded
>99%
Last modified
2 years ago
src/__init__.py
1
src/__main__.py
1import asyncio2import logging3
4from apify.log import ActorLogFormatter5
6from .main import main7
8handler = logging.StreamHandler()9handler.setFormatter(ActorLogFormatter())10
11apify_client_logger = logging.getLogger('apify_client')12apify_client_logger.setLevel(logging.INFO)13apify_client_logger.addHandler(handler)14
15apify_logger = logging.getLogger('apify')16apify_logger.setLevel(logging.DEBUG)17apify_logger.addHandler(handler)18
19asyncio.run(main())
src/main.py
1import os2from transformers import pipeline3from apify import Actor4
5async def main():6 async with Actor:7 actor_input = await Actor.get_input() or {}8
9 generator = pipeline('text-generation', model='gpt2')10 output = generator(actor_input["prompt"], max_length=actor_input["max_length"], num_return_sequences=1)11
12 await Actor.push_data(output)
.dockerignore
# configurations.idea
# crawlee and apify storage foldersapify_storagecrawlee_storagestorage
# installed filesnode_modules
# git folder.git
Dockerfile
FROM huggingface/transformers-pytorch-gpu
COPY requirements.txt ./
RUN echo "Python version:" \ && python3 --version \ && echo "Pip version:" \ && pip --version \ && echo "Installing dependencies from requirements.txt:" \ && pip install -r requirements.txt \ && echo "All installed Python packages:" \ && pip freeze
COPY . ./
RUN python3 -c 'from transformers import pipeline; generator = pipeline("text-generation", model="gpt2")'
CMD ["python3", "-m", "src"]
INPUT_SCHEMA.json
{ "title": "Generate text", "description": "This is actor input schema", "type": "object", "schemaVersion": 1, "properties": { "prompt": { "title": "Initial prompt", "type": "string", "description": "The initial prompt used as basis for text generation", "default": "My name is Apify and I like to", "editor": "textarea" }, "max_length": { "title": "Maximum sequence length", "type": "integer", "description": "The maximum length of the generated sequence", "default": 30, "editor": "number" } }, "required": [ "prompt", "max_length" ]}
requirements.txt
1# Add your dependencies here.2# See https://pip.pypa.io/en/latest/cli/pip_install/#requirements-file-format3# for how to format them4
5apify ~= 1.0.0