Spaces:
Build error
Build error
Download app.py from SpatialWebAgent/dockerb: direct link, hf CLI and curl.
- Browser
- Download file 727 Bytes
-
https://huggingface.co/spaces/SpatialWebAgent/dockerb/resolve/main/app.py
- Command line
-
hf download hf://spaces/SpatialWebAgent/dockerb/app.py
-
curl -L -o app.py https://huggingface.co/spaces/SpatialWebAgent/dockerb/resolve/main/app.py
727 Bytes
| import gradio as gr | |
| import spacy | |
| import os | |
| import uuid | |
| # 自动创建保存目录 | |
| os.makedirs("saved", exist_ok=True) | |
| # 加载模型(初始化只加载一次) | |
| nlp = spacy.load("en_core_web_md") | |
| def process_text(input_text): | |
| doc = nlp(input_text) | |
| # 保存为 JSON | |
| json_path = f"saved/{uuid.uuid4().hex}.json" | |
| with open(json_path, "w") as f: | |
| f.write(doc.to_json(indent=2)) | |
| # 返回下载链接 | |
| return json_path | |
| # Gradio 接口 | |
| demo = gr.Interface( | |
| fn=process_text, | |
| inputs=gr.Textbox(label="输入文本"), | |
| outputs=gr.File(label="下载文件"), | |
| title="📦 文本处理 → 下载 JSON", | |
| allow_flagging="never" | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch() | |