Create 6
Browse files
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"]}
|