roxqtang commited on
Commit
9a0ae2d
·
1 Parent(s): 71ea189

Fix Matplotlib config directory permissions issue and improve file handling

Browse files
Files changed (3) hide show
  1. Dockerfile +5 -0
  2. gemini_chatbot.py +9 -0
  3. requirements_hf.txt +9 -0
Dockerfile CHANGED
@@ -11,6 +11,11 @@ RUN mkdir -p uploads
11
 
12
  # 设置环境变量
13
  ENV PYTHONUNBUFFERED=1
 
 
 
 
 
14
 
15
  # 暴露端口
16
  EXPOSE 7860
 
11
 
12
  # 设置环境变量
13
  ENV PYTHONUNBUFFERED=1
14
+ # 设置Matplotlib配置目录到应用有权限的/tmp目录
15
+ ENV MPLCONFIGDIR=/tmp/matplotlib
16
+
17
+ # 创建Matplotlib配置目录
18
+ RUN mkdir -p /tmp/matplotlib
19
 
20
  # 暴露端口
21
  EXPOSE 7860
gemini_chatbot.py CHANGED
@@ -12,6 +12,15 @@ import traceback
12
  import jieba # 中文分词
13
  import re
14
  from collections import Counter
 
 
 
 
 
 
 
 
 
15
  from wordcloud import WordCloud
16
  import matplotlib
17
  matplotlib.use('Agg') # 设置Matplotlib为非交互模式
 
12
  import jieba # 中文分词
13
  import re
14
  from collections import Counter
15
+
16
+ # 设置Matplotlib配置目录环境变量,在导入matplotlib前设置
17
+ if 'MPLCONFIGDIR' not in os.environ:
18
+ os.environ['MPLCONFIGDIR'] = '/tmp/matplotlib'
19
+ try:
20
+ os.makedirs('/tmp/matplotlib', exist_ok=True)
21
+ except:
22
+ logging.warning("无法创建Matplotlib配置目录,将使用系统默认值")
23
+
24
  from wordcloud import WordCloud
25
  import matplotlib
26
  matplotlib.use('Agg') # 设置Matplotlib为非交互模式
requirements_hf.txt ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ flask==2.2.3
2
+ requests==2.28.2
3
+ python-dotenv==1.0.0
4
+ pypdf2==3.0.1
5
+ jieba
6
+ Werkzeug==2.2.3
7
+ wordcloud
8
+ matplotlib
9
+ gunicorn