Spaces:
Runtime error
Runtime error
File size: 539 Bytes
0799413 4faab24 6a7675b 7658b28 0799413 350d2be 0799413 350d2be 0799413 4faab24 6a7675b ac98b98 6a7675b 0799413 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
import os
from fastapi import FastAPI
from transformers import pipeline
# Configurar el directorio de caché de Hugging Face
os.environ['TRANSFORMERS_CACHE'] = '/tmp/cache'
# Crear el directorio de caché si no existe
os.makedirs('/tmp/cache', exist_ok=True)
app = FastAPI()
# Cargar el modelo de GPT-Neo
generator = pipeline('text-generation', model='EleutherAI/gpt-neo-2.7B')
@app.post("/generate")
async def generate(prompt: str):
response = generator(prompt, max_length=100)
return {"text": response[0]["generated_text"]}
|