Spaces:
Sleeping
Sleeping
Empereur-Pirate
commited on
Update main.py
Browse files
main.py
CHANGED
@@ -1,8 +1,20 @@
|
|
1 |
from fastapi import FastAPI
|
|
|
2 |
|
3 |
app = FastAPI()
|
4 |
|
5 |
-
|
6 |
|
7 |
-
def
|
8 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
+
from transformers import pipeline
|
3 |
|
4 |
app = FastAPI()
|
5 |
|
6 |
+
pipe_flan = pipeline("text2text-generation", model="google/flan-t5-small")
|
7 |
|
8 |
+
def t5(input):
|
9 |
+
output = pipe_flan(input)
|
10 |
+
return {"output": output[0]["generated_text"]}
|
11 |
+
|
12 |
+
@app.post("/infer_t5")
|
13 |
+
def infer_endpoint(data: dict):
|
14 |
+
"""Receive input and generate text."""
|
15 |
+
input_text = data.get("input")
|
16 |
+
if input_text is None:
|
17 |
+
return {"error": "No input text detected."}
|
18 |
+
else:
|
19 |
+
result = t5(input_text)
|
20 |
+
return result
|