Spaces:
Sleeping
Sleeping
Delete api.py
Browse files
api.py
DELETED
|
@@ -1,42 +0,0 @@
|
|
| 1 |
-
import os
|
| 2 |
-
|
| 3 |
-
from fastapi import FastAPI, WebSocket
|
| 4 |
-
from epub2txt import epub2txt
|
| 5 |
-
|
| 6 |
-
from fastllm_pytools import llm
|
| 7 |
-
|
| 8 |
-
model = llm.model(os.getenv("checkpoint_path"))
|
| 9 |
-
prompt = os.getenv("prompt")
|
| 10 |
-
|
| 11 |
-
app = FastAPI()
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
@app.websocket("/ws")
|
| 15 |
-
async def read_root(websocket: WebSocket):
|
| 16 |
-
await websocket.accept()
|
| 17 |
-
f_name = await websocket.receive_text()
|
| 18 |
-
ch_list = epub2txt(f_name, outputlist=True)
|
| 19 |
-
chapter_titles = epub2txt.content_titles
|
| 20 |
-
title = epub2txt.title
|
| 21 |
-
|
| 22 |
-
idx = 0
|
| 23 |
-
sm_list = []
|
| 24 |
-
for text in ch_list[2:]:
|
| 25 |
-
idx += 1
|
| 26 |
-
docs = []
|
| 27 |
-
for i in range(0, len(text)//2000+1, 2000):
|
| 28 |
-
t = text[i:i+2048]
|
| 29 |
-
if len(t) > 0:
|
| 30 |
-
docs.append(model.response(prompt+t))
|
| 31 |
-
await websocket.send_text(f"chsum: {docs[-1]}")
|
| 32 |
-
hist = docs[0]
|
| 33 |
-
for doc in docs[1:]:
|
| 34 |
-
hist = model.response(prompt+"\n"+hist+"\n"+doc)
|
| 35 |
-
await websocket.send_text(f"draft_sum: {hist}")
|
| 36 |
-
sm_list.append(hist)
|
| 37 |
-
mdobj_str = f"# {title}\n\n{hist}\n\n\n"
|
| 38 |
-
for ct, sm in zip(chapter_titles[2:], sm_list):
|
| 39 |
-
mdobj_str += f"## {ct}\n\n{sm}\n\n\n"
|
| 40 |
-
await websocket.send_text(f"output: {mdobj_str}")
|
| 41 |
-
|
| 42 |
-
# uvicorn api:app --reload
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|