Spaces:
Runtime error
Runtime error
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") | |
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"} | |