Nanny7's picture
feat: add Gradio web UI and Docker deployment for Hugging Face Spaces
9191def
raw
history blame contribute delete
925 Bytes
import os
import glob
import shutil
import gradio as gr
from main import Run
def download_novel(book_id: str):
"""
下载指定小说 ID 并返回生成的 txt 文件路径
"""
save_path = "downloads"
# 清理旧文件
if os.path.exists(save_path):
shutil.rmtree(save_path)
os.makedirs(save_path, exist_ok=True)
# 调用下载逻辑
Run(book_id, save_path)
# 查找生成的 txt 文件
files = glob.glob(os.path.join(save_path, "*.txt"))
if files:
return files[0]
else:
return None
# Gradio 界面
iface = gr.Interface(
fn=download_novel,
inputs=gr.Textbox(label="小说 ID"),
outputs=gr.File(label="下载的小说文件"),
title="番茄小说在线下载器",
description="请输入小说 ID,点击下载后可获得 txt 文件。",
)
if __name__ == "__main__":
iface.launch(server_name="0.0.0.0", server_port=7860)