neuroama commited on
Commit
7e560f7
·
1 Parent(s): f7b31ad

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from transformers import pipeline
2
+ from fastapi import FastAPI
3
+
4
+ app = FastAPI()
5
+
6
+ # Load the model using Hugging Face Transformers
7
+ generator = pipeline("text-generation", model="EleutherAI/gpt-neo-1.3B")
8
+
9
+ @app.post("/generate")
10
+ def generate_text(prompt: str):
11
+ # Generate text using the loaded model
12
+ text = generator(prompt, max_length=50, num_return_sequences=1)[0]['generated_text']
13
+
14
+ # Save the generated text to a file
15
+ with open("generated_text.txt", "w") as file:
16
+ file.write(text)
17
+
18
+ # Return the path to the saved file
19
+ return {"message": "Text generated successfully", "file_path": "generated_text.txt"}