已添加一个简单的网页版 UI:
Browse files在根路由 / 返回一个 HTML 表单,可输入小说 ID 并提交到 /download。
调整
Dockerfile
:只监听 7860 端口,适配 Hugging Face Spaces 默认端口。
- Dockerfile +3 -2
- server.py +19 -3
Dockerfile
CHANGED
|
@@ -10,7 +10,8 @@ RUN pip install --no-cache-dir -r requirements.txt
|
|
| 10 |
COPY . /app
|
| 11 |
|
| 12 |
# 暴露端口
|
| 13 |
-
|
|
|
|
| 14 |
|
| 15 |
# 启动应用
|
| 16 |
-
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "
|
|
|
|
| 10 |
COPY . /app
|
| 11 |
|
| 12 |
# 暴露端口
|
| 13 |
+
# 监听 7860 端口(Hugging Face Spaces 默认)
|
| 14 |
+
EXPOSE 7860
|
| 15 |
|
| 16 |
# 启动应用
|
| 17 |
+
CMD ["uvicorn", "server:app", "--host", "0.0.0.0", "--port", "7860"]
|
server.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
-
from fastapi.responses import FileResponse
|
| 3 |
import os, shutil, glob
|
| 4 |
from main import Run
|
| 5 |
|
|
@@ -8,9 +8,25 @@ app = FastAPI(
|
|
| 8 |
description="通过 /download?book_id=xxx 获取小说文本文件",
|
| 9 |
)
|
| 10 |
|
| 11 |
-
@app.get("/")
|
| 12 |
def root():
|
| 13 |
-
return
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
@app.get("/download")
|
| 16 |
def download(book_id: str):
|
|
|
|
| 1 |
from fastapi import FastAPI, HTTPException
|
| 2 |
+
from fastapi.responses import FileResponse, HTMLResponse
|
| 3 |
import os, shutil, glob
|
| 4 |
from main import Run
|
| 5 |
|
|
|
|
| 8 |
description="通过 /download?book_id=xxx 获取小说文本文件",
|
| 9 |
)
|
| 10 |
|
| 11 |
+
@app.get("/", response_class=HTMLResponse)
|
| 12 |
def root():
|
| 13 |
+
return """
|
| 14 |
+
<!DOCTYPE html>
|
| 15 |
+
<html lang="zh-CN">
|
| 16 |
+
<head>
|
| 17 |
+
<meta charset="UTF-8">
|
| 18 |
+
<title>番茄小说下载器</title>
|
| 19 |
+
</head>
|
| 20 |
+
<body>
|
| 21 |
+
<h1>番茄小说下载器</h1>
|
| 22 |
+
<form action="/download" method="get">
|
| 23 |
+
<label for="book_id">小说ID:</label>
|
| 24 |
+
<input type="text" id="book_id" name="book_id" required />
|
| 25 |
+
<button type="submit">下载</button>
|
| 26 |
+
</form>
|
| 27 |
+
</body>
|
| 28 |
+
</html>
|
| 29 |
+
"""
|
| 30 |
|
| 31 |
@app.get("/download")
|
| 32 |
def download(book_id: str):
|