gradiotest / app.py
neuroama's picture
Create app.py
7e560f7
raw
history blame contribute delete
644 Bytes
from transformers import pipeline
from fastapi import FastAPI
app = FastAPI()
# Load the model using Hugging Face Transformers
generator = pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")
@app.post("/generate")
def generate_text(prompt: str):
# Generate text using the loaded model
text = generator(prompt, max_length=50, num_return_sequences=1)[0]['generated_text']
# Save the generated text to a file
with open("generated_text.txt", "w") as file:
file.write(text)
# Return the path to the saved file
return {"message": "Text generated successfully", "file_path": "generated_text.txt"}