File size: 644 Bytes
7e560f7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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"}