Rename app.py to start.sh
Browse files
app.py
DELETED
@@ -1,27 +0,0 @@
|
|
1 |
-
import gradio as gr
|
2 |
-
import os
|
3 |
-
from dotenv import load_dotenv
|
4 |
-
|
5 |
-
# 加载环境变量
|
6 |
-
load_dotenv()
|
7 |
-
|
8 |
-
def start_web_service():
|
9 |
-
# 这里添加启动 Web 服务的逻辑
|
10 |
-
# 可能需要调用原镜像的启动方法
|
11 |
-
pass
|
12 |
-
|
13 |
-
# 创建 Gradio 接口
|
14 |
-
def create_interface():
|
15 |
-
iface = gr.Interface(
|
16 |
-
fn=start_web_service,
|
17 |
-
inputs=None,
|
18 |
-
outputs=gr.Textbox(label="服务状态"),
|
19 |
-
title="Long Novel GPT",
|
20 |
-
description="长文本生成服务"
|
21 |
-
)
|
22 |
-
return iface
|
23 |
-
|
24 |
-
# 启动服务
|
25 |
-
if __name__ == "__main__":
|
26 |
-
interface = create_interface()
|
27 |
-
interface.launch(server_name="0.0.0.0", server_port=7860)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
start.sh
ADDED
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
#!/bin/bash
|
2 |
+
|
3 |
+
# 设置默认值
|
4 |
+
FRONTEND_PORT=${FRONTEND_PORT:-80}
|
5 |
+
BACKEND_PORT=${BACKEND_PORT:-7860}
|
6 |
+
BACKEND_HOST=${BACKEND_HOST:-0.0.0.0}
|
7 |
+
WORKERS=${WORKERS:-4}
|
8 |
+
THREADS=${THREADS:-2}
|
9 |
+
TIMEOUT=${TIMEOUT:-120}
|
10 |
+
|
11 |
+
# 在Linux环境下添加host.docker.internal解析
|
12 |
+
# if ! grep -q "host.docker.internal" /etc/hosts; then
|
13 |
+
# DOCKER_INTERNAL_HOST="$(ip route | grep default | awk '{print $3}')"
|
14 |
+
# echo "$DOCKER_INTERNAL_HOST host.docker.internal" >> /etc/hosts
|
15 |
+
# fi
|
16 |
+
|
17 |
+
# 替换nginx配置中的端口
|
18 |
+
sed -i "s/listen 80/listen $FRONTEND_PORT/g" /etc/nginx/conf.d/default.conf
|
19 |
+
sed -i "s/host.docker.internal:7860/localhost:$BACKEND_PORT/g" /etc/nginx/conf.d/default.conf
|
20 |
+
|
21 |
+
# 启动nginx
|
22 |
+
nginx
|
23 |
+
|
24 |
+
# 启动gunicorn
|
25 |
+
gunicorn --bind $BACKEND_HOST:$BACKEND_PORT \
|
26 |
+
--workers $WORKERS \
|
27 |
+
--threads $THREADS \
|
28 |
+
--worker-class gthread \
|
29 |
+
--timeout $TIMEOUT \
|
30 |
+
--access-logfile - \
|
31 |
+
--error-logfile - \
|
32 |
+
app:app
|