Text Generation
Not-For-All-Audiences
ImRasul1 commited on
Commit
1b6cdab
1 Parent(s): b32a59b
Files changed (1) hide show
  1. 6 +11 -0
6 ADDED
@@ -0,0 +1,11 @@
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ from transformers import pipeline
3
+
4
+ app = FastAPI()
5
+
6
+ generator = pipeline("text-generation", model="gpt2")
7
+
8
+ @app.post("/generate/")
9
+ def generate_text(prompt: str):
10
+ result = generator(prompt, max_length=50, num_return_sequences=1)
11
+ return {"generated_text": result[0]["generated_text"]}