HOPStudio commited on
Commit
51a8816
·
verified ·
1 Parent(s): 1695273

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +26 -13
main.py CHANGED
@@ -5,6 +5,23 @@ import gradio as gr
5
  import requests
6
  import json
7
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
  # 处理 API 请求的函数
10
  def api_call(input_text, model="internlm2.5-latest", temperature=0.8, top_p=0.9, n=1):
@@ -62,14 +79,12 @@ def api_call(input_text, model="internlm2.5-latest", temperature=0.8, top_p=0.9,
62
 
63
  # 创建 frpc.toml 配置文件
64
  def create_frpc_toml():
65
- frpc_toml_path = "/root/modelscope/frpc.toml"
66
  toml_content = """
67
  [common]
68
  server_addr = 182.43.67.222
69
  server_port = 7000
70
  token = token123456
71
- heartbeat_interval = 30 # 心跳包间隔时间(秒)
72
- heartbeat_timeout = 90 # 心跳包超时时间(秒)
73
 
74
  [jupyterlab]
75
  type = tcp
@@ -98,9 +113,9 @@ remote_port = 8188
98
 
99
  # 启动 start_jupyterlab.py 的线程函数
100
  def start_jupyterlab_process():
101
- jupyter_script = "/root/modelscope/start_jupyterlab.py"
102
  if not os.path.exists(jupyter_script):
103
- print("无法找到 start_jupyterlab.py,请确保脚本存在于指定路径。")
104
  return
105
 
106
  try:
@@ -117,8 +132,9 @@ def start_jupyterlab_process():
117
 
118
  # 启动 frp 的线程函数
119
  def start_frp():
120
- frpc_path = "/root/modelscope/frp_0.61.0_linux_amd64/frpc"
121
- frpc_config_path = "/root/modelscope/frpc.toml"
 
122
  if not os.path.exists(frpc_path):
123
  print("frpc 可执行文件不存在,请检查路径。")
124
  return
@@ -128,12 +144,7 @@ def start_frp():
128
  create_frpc_toml()
129
 
130
  try:
131
- subprocess.Popen(
132
- [frpc_path, "-c", frpc_config_path],
133
- stdout=subprocess.PIPE,
134
- stderr=subprocess.PIPE,
135
- text=True
136
- )
137
  print("frp 已启动。")
138
  except Exception as e:
139
  print(f"启动 frp 时出错: {str(e)}")
@@ -167,6 +178,8 @@ def start_gradio():
167
 
168
  # 主函数
169
  def main():
 
 
170
  # 创建 frp 配置文件(如果不存在)
171
  create_frpc_toml()
172
 
 
5
  import requests
6
  import json
7
 
8
+ # 仓库路径
9
+ REPO_URL = "https://hf-mirror.com/HOPStudio/modelscope"
10
+ REPO_PATH = "/root/modelscope"
11
+
12
+ # 确保克隆仓库
13
+ def clone_repository():
14
+ if os.path.exists(REPO_PATH):
15
+ print(f"仓库已存在,跳过克隆: {REPO_PATH}")
16
+ return True
17
+ try:
18
+ print(f"正在克隆仓库到 {REPO_PATH}...")
19
+ subprocess.run(["git", "clone", REPO_URL, REPO_PATH], check=True)
20
+ print("仓库克隆成功!")
21
+ return True
22
+ except subprocess.CalledProcessError as e:
23
+ print(f"克隆仓库时出错: {e}")
24
+ return False
25
 
26
  # 处理 API 请求的函数
27
  def api_call(input_text, model="internlm2.5-latest", temperature=0.8, top_p=0.9, n=1):
 
79
 
80
  # 创建 frpc.toml 配置文件
81
  def create_frpc_toml():
82
+ frpc_toml_path = os.path.join(REPO_PATH, "frpc.toml")
83
  toml_content = """
84
  [common]
85
  server_addr = 182.43.67.222
86
  server_port = 7000
87
  token = token123456
 
 
88
 
89
  [jupyterlab]
90
  type = tcp
 
113
 
114
  # 启动 start_jupyterlab.py 的线程函数
115
  def start_jupyterlab_process():
116
+ jupyter_script = os.path.join(REPO_PATH, "start_jupyterlab.py")
117
  if not os.path.exists(jupyter_script):
118
+ print(f"无法找到 {jupyter_script},请确保脚本存在于仓库中。")
119
  return
120
 
121
  try:
 
132
 
133
  # 启动 frp 的线程函数
134
  def start_frp():
135
+ frpc_path = os.path.join(REPO_PATH, "frp_0.61.0_linux_amd64/frpc")
136
+ frpc_config_path = os.path.join(REPO_PATH, "frpc.toml")
137
+
138
  if not os.path.exists(frpc_path):
139
  print("frpc 可执行文件不存在,请检查路径。")
140
  return
 
144
  create_frpc_toml()
145
 
146
  try:
147
+ subprocess.Popen([frpc_path, "-c", frpc_config_path])
 
 
 
 
 
148
  print("frp 已启动。")
149
  except Exception as e:
150
  print(f"启动 frp 时出错: {str(e)}")
 
178
 
179
  # 主函数
180
  def main():
181
+ clone_repository()
182
+
183
  # 创建 frp 配置文件(如果不存在)
184
  create_frpc_toml()
185