chen666-666 commited on
Commit
7a29666
·
verified ·
1 Parent(s): 72013e5

Upload 2 files

Browse files
Files changed (2) hide show
  1. Dockerfile +30 -0
  2. app.py +7 -3
Dockerfile ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # 使用官方 Python 轻量镜像
2
+ FROM python:3.10-slim
3
+
4
+ # 安装系统依赖,包括中文字体和其他必需的工具
5
+ RUN apt-get update && \
6
+ apt-get install -y --no-install-recommends \
7
+ fonts-noto-cjk \ # 中文字体
8
+ python3-pip \ # pip
9
+ git \ # git
10
+ curl \ # curl
11
+ && apt-get clean && \
12
+ rm -rf /var/lib/apt/lists/*
13
+
14
+ # 设置 matplotlib 临时缓存目录(防止权限问题)
15
+ ENV MPLCONFIGDIR=/tmp/matplotlib
16
+
17
+ # 设置工作目录
18
+ WORKDIR /app
19
+
20
+ # 拷贝 Python 依赖文件
21
+ COPY requirements.txt .
22
+
23
+ # 安装 Python 库
24
+ RUN pip install --no-cache-dir -r requirements.txt
25
+
26
+ # 拷贝项目代码
27
+ COPY . .
28
+
29
+ # 运行 Gradio 应用
30
+ CMD ["python", "app.py"]
app.py CHANGED
@@ -596,8 +596,12 @@ def generate_kg_image(entities, relations):
596
  plt.tight_layout()
597
 
598
  # === 4. 保存图片 ===
599
- temp_dir = tempfile.mkdtemp()
600
  output_path = os.path.join(temp_dir, "kg.png")
 
 
 
 
601
  plt.savefig(output_path, bbox_inches='tight', pad_inches=0.1)
602
  plt.close()
603
 
@@ -607,8 +611,8 @@ def generate_kg_image(entities, relations):
607
  logging.error(f"[ERROR] 图谱生成失败: {str(e)}")
608
  return None
609
 
610
-
611
-
612
  def process_file(file, model_type="bert"):
613
  try:
614
  with open(file.name, 'rb') as f:
 
596
  plt.tight_layout()
597
 
598
  # === 4. 保存图片 ===
599
+ temp_dir = tempfile.mkdtemp() # 确保在 Docker 容器中有权限写入
600
  output_path = os.path.join(temp_dir, "kg.png")
601
+
602
+ # 打印路径以方便调试
603
+ logging.info(f"Saving graph image to {output_path}")
604
+
605
  plt.savefig(output_path, bbox_inches='tight', pad_inches=0.1)
606
  plt.close()
607
 
 
611
  logging.error(f"[ERROR] 图谱生成失败: {str(e)}")
612
  return None
613
 
614
+
615
+ # ======================== 文件处理 ========================
616
  def process_file(file, model_type="bert"):
617
  try:
618
  with open(file.name, 'rb') as f: