Spaces:
Paused
Paused
lanny xu
commited on
Commit
·
55a0955
1
Parent(s):
fe717e9
add react
Browse files- document_processor.py +2 -5
- run_server.py +26 -8
- server.py +2 -6
document_processor.py
CHANGED
|
@@ -4,12 +4,9 @@
|
|
| 4 |
"""
|
| 5 |
|
| 6 |
try:
|
| 7 |
-
from
|
| 8 |
except ImportError:
|
| 9 |
-
|
| 10 |
-
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 11 |
-
except ImportError:
|
| 12 |
-
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 13 |
|
| 14 |
from langchain_community.document_loaders import WebBaseLoader
|
| 15 |
from langchain_community.vectorstores import Chroma
|
|
|
|
| 4 |
"""
|
| 5 |
|
| 6 |
try:
|
| 7 |
+
from langchain.text_splitter import RecursiveCharacterTextSplitter
|
| 8 |
except ImportError:
|
| 9 |
+
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
from langchain_community.document_loaders import WebBaseLoader
|
| 12 |
from langchain_community.vectorstores import Chroma
|
run_server.py
CHANGED
|
@@ -49,11 +49,17 @@ def start_ngrok():
|
|
| 49 |
|
| 50 |
def start_cloudflared():
|
| 51 |
try:
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 57 |
url = None
|
| 58 |
while True:
|
| 59 |
line = proc.stdout.readline()
|
|
@@ -98,6 +104,18 @@ if __name__ == "__main__":
|
|
| 98 |
# 等待服务器启动
|
| 99 |
time.sleep(3)
|
| 100 |
|
| 101 |
-
|
| 102 |
-
if
|
| 103 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 49 |
|
| 50 |
def start_cloudflared():
|
| 51 |
try:
|
| 52 |
+
cmd = None
|
| 53 |
+
if shutil.which("cloudflared"):
|
| 54 |
+
cmd = ["cloudflared", "tunnel", "--url", "http://localhost:8000", "--no-autoupdate"]
|
| 55 |
+
else:
|
| 56 |
+
try:
|
| 57 |
+
__import__("cloudflared")
|
| 58 |
+
cmd = [sys.executable, "-m", "cloudflared", "tunnel", "--url", "http://localhost:8000", "--no-autoupdate"]
|
| 59 |
+
except Exception:
|
| 60 |
+
print("⚠️ 未找到 cloudflared,可通过 'pip install cloudflared' 安装,或跳过穿透")
|
| 61 |
+
return
|
| 62 |
+
proc = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
| 63 |
url = None
|
| 64 |
while True:
|
| 65 |
line = proc.stdout.readline()
|
|
|
|
| 104 |
# 等待服务器启动
|
| 105 |
time.sleep(3)
|
| 106 |
|
| 107 |
+
use_tunnel = os.environ.get("USE_TUNNEL", "true").lower() == "true"
|
| 108 |
+
if use_tunnel:
|
| 109 |
+
ok = start_ngrok()
|
| 110 |
+
if not ok:
|
| 111 |
+
start_cloudflared()
|
| 112 |
+
else:
|
| 113 |
+
print("\n" + "="*60)
|
| 114 |
+
print("✅ 服务器已启动,局域网访问地址:")
|
| 115 |
+
print("👉 http://127.0.0.1:8000")
|
| 116 |
+
print("="*60 + "\n")
|
| 117 |
+
try:
|
| 118 |
+
while True:
|
| 119 |
+
time.sleep(1)
|
| 120 |
+
except KeyboardInterrupt:
|
| 121 |
+
pass
|
server.py
CHANGED
|
@@ -26,13 +26,8 @@ import shutil
|
|
| 26 |
sys.path.append(os.getcwd())
|
| 27 |
|
| 28 |
try:
|
| 29 |
-
from main import AdaptiveRAGSystem
|
| 30 |
from config import ENABLE_MULTIMODAL
|
| 31 |
-
except
|
| 32 |
-
# 模拟导入,防止在没有依赖的环境下报错
|
| 33 |
-
class AdaptiveRAGSystem:
|
| 34 |
-
def __init__(self, *args, **kwargs): pass
|
| 35 |
-
def query(self, _): return {"answer": "系统未正确初始化", "sources": []}
|
| 36 |
ENABLE_MULTIMODAL = False
|
| 37 |
|
| 38 |
# ============================================================
|
|
@@ -62,6 +57,7 @@ def get_rag_system():
|
|
| 62 |
if rag_system is None:
|
| 63 |
try:
|
| 64 |
print("🔄 初始化 RAG 系统...")
|
|
|
|
| 65 |
rag_system = AdaptiveRAGSystem()
|
| 66 |
print("✅ RAG 系统初始化完成")
|
| 67 |
except Exception as e:
|
|
|
|
| 26 |
sys.path.append(os.getcwd())
|
| 27 |
|
| 28 |
try:
|
|
|
|
| 29 |
from config import ENABLE_MULTIMODAL
|
| 30 |
+
except Exception:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
ENABLE_MULTIMODAL = False
|
| 32 |
|
| 33 |
# ============================================================
|
|
|
|
| 57 |
if rag_system is None:
|
| 58 |
try:
|
| 59 |
print("🔄 初始化 RAG 系统...")
|
| 60 |
+
from main import AdaptiveRAGSystem
|
| 61 |
rag_system = AdaptiveRAGSystem()
|
| 62 |
print("✅ RAG 系统初始化完成")
|
| 63 |
except Exception as e:
|