Download app.py from lhnjames/test01: direct link, hf CLI and curl.
- Browser
- Download file 918 Bytes
-
https://huggingface.co/spaces/lhnjames/test01/resolve/main/app.py
- Command line
-
hf download hf://spaces/lhnjames/test01/app.py
-
curl -L -o app.py https://huggingface.co/spaces/lhnjames/test01/resolve/main/app.py
918 Bytes
| import gradio as gr | |
| import main | |
| import os | |
| import subprocess | |
| # 设置 Matplotlib 的缓存目录 | |
| os.environ['MPLCONFIGDIR'] = '/tmp/matplotlib' | |
| # 设置 Hugging Face Transformers 的缓存目录 | |
| os.environ['TRANSFORMERS_CACHE'] = '/tmp/huggingface_cache' | |
| # 确保这些目录存在 | |
| os.makedirs(os.environ['MPLCONFIGDIR'], exist_ok=True) | |
| os.makedirs(os.environ['TRANSFORMERS_CACHE'], exist_ok=True) | |
| # 确保 Weaviate 已初始化 | |
| main.init_weaviate() | |
| def query_weaviate(input_text): | |
| result = main.use_weaviate(input_text) | |
| return result | |
| iface = gr.Interface( | |
| fn=query_weaviate, | |
| inputs=gr.Textbox(lines=2, placeholder="请输入查询的文本..."), | |
| outputs=gr.Text(), | |
| title="Weaviate Query Interface", | |
| description="输入查询文本,获取最相似的句子。", | |
| flagging_dir='/tmp/flagged' # 设置 flagging_dir 为可写目录 | |
| ) | |
| if __name__ == "__main__": | |
| iface.launch() | |