Update main.py
Browse files
main.py
CHANGED
@@ -1,3 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
from fastapi import FastAPI
|
2 |
from fastapi.staticfiles import StaticFiles
|
3 |
from fastapi.responses import FileResponse
|
@@ -6,11 +27,12 @@ from transformers import pipeline
|
|
6 |
|
7 |
app = FastAPI()
|
8 |
|
9 |
-
|
|
|
10 |
|
11 |
@app.get("/infer_t5")
|
12 |
-
def
|
13 |
-
output =
|
14 |
return {"output": output[0]["generated_text"]}
|
15 |
|
16 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
|
|
1 |
+
# from fastapi import FastAPI
|
2 |
+
# from fastapi.staticfiles import StaticFiles
|
3 |
+
# from fastapi.responses import FileResponse
|
4 |
+
|
5 |
+
# from transformers import pipeline
|
6 |
+
|
7 |
+
# app = FastAPI()
|
8 |
+
|
9 |
+
# pipe_flan = pipeline("text2text-generation", model="FreedomIntelligence/Apollo-1.8B",trust_remote_code=True)
|
10 |
+
|
11 |
+
# @app.get("/infer_t5")
|
12 |
+
# def t5(input):
|
13 |
+
# output = pipe_flan(input)
|
14 |
+
# return {"output": output[0]["generated_text"]}
|
15 |
+
|
16 |
+
# app.mount("/", StaticFiles(directory="static", html=True), name="static")
|
17 |
+
|
18 |
+
# @app.get("/")
|
19 |
+
# def index() -> FileResponse:
|
20 |
+
# return FileResponse(path="/app/static/index.html", media_type="text/html")
|
21 |
+
|
22 |
from fastapi import FastAPI
|
23 |
from fastapi.staticfiles import StaticFiles
|
24 |
from fastapi.responses import FileResponse
|
|
|
27 |
|
28 |
app = FastAPI()
|
29 |
|
30 |
+
# 更改pipeline类型到text-generation,并使用一个示例模型(如GPT-2)
|
31 |
+
pipe_gpt = pipeline("text-generation", model="FreedomIntelligence/Apollo-1.8B",trust_remote_code=True)
|
32 |
|
33 |
@app.get("/infer_t5")
|
34 |
+
def infer_gpt(input: str):
|
35 |
+
output = pipe_gpt(input, max_length=50) # 你可以调整max_length来控制生成文本的长度
|
36 |
return {"output": output[0]["generated_text"]}
|
37 |
|
38 |
app.mount("/", StaticFiles(directory="static", html=True), name="static")
|