Spaces:
Sleeping
Sleeping
haepa_mac
commited on
Commit
·
2419f30
1
Parent(s):
44e0e84
Fix: 한글 폰트 및 이미지 처리 오류 수정, Docker 지원 추가
Browse files- Dockerfile +33 -0
- app.py +43 -24
- docker-compose.yml +14 -0
Dockerfile
ADDED
@@ -0,0 +1,33 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
FROM python:3.10-slim
|
2 |
+
|
3 |
+
WORKDIR /app
|
4 |
+
|
5 |
+
# 시스템 의존성 설치
|
6 |
+
RUN apt-get update && apt-get install -y \
|
7 |
+
build-essential \
|
8 |
+
libgl1-mesa-glx \
|
9 |
+
libglib2.0-0 \
|
10 |
+
fonts-nanum \
|
11 |
+
&& rm -rf /var/lib/apt/lists/*
|
12 |
+
|
13 |
+
# 한글 폰트 설정
|
14 |
+
RUN mkdir -p /usr/share/fonts/truetype/nanum
|
15 |
+
COPY fonts/*.ttf /usr/share/fonts/truetype/nanum/ 2>/dev/null || :
|
16 |
+
RUN fc-cache -f -v
|
17 |
+
|
18 |
+
# 애플리케이션 파일 복사
|
19 |
+
COPY . /app/
|
20 |
+
|
21 |
+
# Python 패키지 설치
|
22 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
23 |
+
|
24 |
+
# 데이터 디렉토리 생성
|
25 |
+
RUN mkdir -p /app/data/personas /app/data/conversations
|
26 |
+
|
27 |
+
# 환경 변수 설정
|
28 |
+
ENV PYTHONUNBUFFERED=1
|
29 |
+
ENV GRADIO_SERVER_NAME=0.0.0.0
|
30 |
+
ENV GRADIO_SERVER_PORT=7860
|
31 |
+
|
32 |
+
# 앱 실행
|
33 |
+
CMD ["python", "app.py"]
|
app.py
CHANGED
@@ -11,6 +11,7 @@ import base64
|
|
11 |
import io
|
12 |
import uuid
|
13 |
from datetime import datetime
|
|
|
14 |
|
15 |
# Import modules
|
16 |
from modules.persona_generator import PersonaGenerator
|
@@ -136,16 +137,13 @@ def create_backend_view_html(persona):
|
|
136 |
def generate_personality_chart(persona):
|
137 |
"""Generate a radar chart for personality traits"""
|
138 |
if not persona or "성격특성" not in persona:
|
139 |
-
# Return empty image
|
140 |
-
|
141 |
-
|
142 |
-
|
143 |
-
|
144 |
-
|
145 |
-
|
146 |
-
buf.seek(0)
|
147 |
-
plt.close(fig)
|
148 |
-
return buf
|
149 |
|
150 |
# Get traits
|
151 |
traits = persona["성격특성"]
|
@@ -161,6 +159,9 @@ def generate_personality_chart(persona):
|
|
161 |
# Convert to radians
|
162 |
angles = np.linspace(0, 2*np.pi, len(categories), endpoint=True)
|
163 |
|
|
|
|
|
|
|
164 |
# Create plot
|
165 |
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
|
166 |
|
@@ -170,24 +171,42 @@ def generate_personality_chart(persona):
|
|
170 |
# Draw lines
|
171 |
ax.plot(angles, values, 'o-', linewidth=2, color='#6366f1')
|
172 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
173 |
# Fill labels
|
174 |
-
ax.set_thetagrids(angles[:-1] * 180/np.pi,
|
175 |
ax.set_rlim(0, 100)
|
176 |
|
177 |
-
# Add titles
|
178 |
name = persona.get("기본정보", {}).get("이름", "Unknown")
|
179 |
-
plt.title(f"{name}
|
180 |
|
181 |
# Styling
|
182 |
ax.grid(True, linestyle='--', alpha=0.7)
|
183 |
|
184 |
-
# Save to buffer
|
185 |
-
|
186 |
-
|
187 |
-
|
188 |
plt.close(fig)
|
189 |
|
190 |
-
return
|
191 |
|
192 |
def soul_awakening(image, object_name=None):
|
193 |
"""Analyze image and awaken the soul of the object"""
|
@@ -222,15 +241,15 @@ def soul_awakening(image, object_name=None):
|
|
222 |
frontend_html = create_frontend_view_html(frontend_persona)
|
223 |
backend_html = create_backend_view_html(backend_persona)
|
224 |
|
225 |
-
# Generate personality chart
|
226 |
-
|
227 |
|
228 |
return (
|
229 |
analysis_result,
|
230 |
gr.update(visible=False, value=""),
|
231 |
frontend_html,
|
232 |
backend_html,
|
233 |
-
|
234 |
)
|
235 |
|
236 |
def start_chat(current_persona):
|
@@ -311,9 +330,9 @@ def load_selected_persona(selected_row, personas_list):
|
|
311 |
backend_html = create_backend_view_html(backend_view)
|
312 |
|
313 |
# Generate personality chart
|
314 |
-
|
315 |
|
316 |
-
return persona, f"{persona['기본정보']['이름']}을(를) 로드했습니다.", frontend_html, backend_html,
|
317 |
|
318 |
except Exception as e:
|
319 |
return None, f"페르소나 로딩 중 오류 발생: {str(e)}", None, None, None
|
@@ -561,4 +580,4 @@ with gr.Blocks(title="놈팽쓰 테스트 앱", theme=theme, css=css) as app:
|
|
561 |
)
|
562 |
|
563 |
if __name__ == "__main__":
|
564 |
-
app.launch()
|
|
|
11 |
import io
|
12 |
import uuid
|
13 |
from datetime import datetime
|
14 |
+
import PIL.ImageDraw
|
15 |
|
16 |
# Import modules
|
17 |
from modules.persona_generator import PersonaGenerator
|
|
|
137 |
def generate_personality_chart(persona):
|
138 |
"""Generate a radar chart for personality traits"""
|
139 |
if not persona or "성격특성" not in persona:
|
140 |
+
# Return empty image with default PIL
|
141 |
+
img = Image.new('RGB', (400, 400), color='white')
|
142 |
+
draw = PIL.ImageDraw.Draw(img)
|
143 |
+
draw.text((150, 180), "데이터 없음", fill='black')
|
144 |
+
img_path = os.path.join("data", "temp_chart.png")
|
145 |
+
img.save(img_path)
|
146 |
+
return img_path
|
|
|
|
|
|
|
147 |
|
148 |
# Get traits
|
149 |
traits = persona["성격특성"]
|
|
|
159 |
# Convert to radians
|
160 |
angles = np.linspace(0, 2*np.pi, len(categories), endpoint=True)
|
161 |
|
162 |
+
# Use a simple English font for labels
|
163 |
+
plt.rcParams['font.family'] = 'DejaVu Sans'
|
164 |
+
|
165 |
# Create plot
|
166 |
fig, ax = plt.subplots(figsize=(6, 6), subplot_kw=dict(polar=True))
|
167 |
|
|
|
171 |
# Draw lines
|
172 |
ax.plot(angles, values, 'o-', linewidth=2, color='#6366f1')
|
173 |
|
174 |
+
# Translate Korean labels to English or use simplified labels
|
175 |
+
translated_labels = []
|
176 |
+
for label in categories[:-1]:
|
177 |
+
if label == "온기":
|
178 |
+
translated_labels.append("Warmth")
|
179 |
+
elif label == "능력":
|
180 |
+
translated_labels.append("Ability")
|
181 |
+
elif label == "신뢰성":
|
182 |
+
translated_labels.append("Trust")
|
183 |
+
elif label == "친화성":
|
184 |
+
translated_labels.append("Friendly")
|
185 |
+
elif label == "창의성":
|
186 |
+
translated_labels.append("Creative")
|
187 |
+
elif label == "유머감각":
|
188 |
+
translated_labels.append("Humor")
|
189 |
+
else:
|
190 |
+
translated_labels.append(label)
|
191 |
+
|
192 |
# Fill labels
|
193 |
+
ax.set_thetagrids(angles[:-1] * 180/np.pi, translated_labels)
|
194 |
ax.set_rlim(0, 100)
|
195 |
|
196 |
+
# Add titles (in English)
|
197 |
name = persona.get("기본정보", {}).get("이름", "Unknown")
|
198 |
+
plt.title(f"{name} Personality Traits", size=15, color='#333333', y=1.1)
|
199 |
|
200 |
# Styling
|
201 |
ax.grid(True, linestyle='--', alpha=0.7)
|
202 |
|
203 |
+
# Save to file instead of buffer
|
204 |
+
img_path = os.path.join("data", f"chart_{int(time.time())}.png")
|
205 |
+
os.makedirs(os.path.dirname(img_path), exist_ok=True)
|
206 |
+
plt.savefig(img_path, format='png', bbox_inches='tight')
|
207 |
plt.close(fig)
|
208 |
|
209 |
+
return img_path
|
210 |
|
211 |
def soul_awakening(image, object_name=None):
|
212 |
"""Analyze image and awaken the soul of the object"""
|
|
|
241 |
frontend_html = create_frontend_view_html(frontend_persona)
|
242 |
backend_html = create_backend_view_html(backend_persona)
|
243 |
|
244 |
+
# Generate personality chart (now returns a file path)
|
245 |
+
chart_image_path = generate_personality_chart(frontend_persona)
|
246 |
|
247 |
return (
|
248 |
analysis_result,
|
249 |
gr.update(visible=False, value=""),
|
250 |
frontend_html,
|
251 |
backend_html,
|
252 |
+
chart_image_path
|
253 |
)
|
254 |
|
255 |
def start_chat(current_persona):
|
|
|
330 |
backend_html = create_backend_view_html(backend_view)
|
331 |
|
332 |
# Generate personality chart
|
333 |
+
chart_image_path = generate_personality_chart(frontend_view)
|
334 |
|
335 |
+
return persona, f"{persona['기본정보']['이름']}을(를) 로드했습니다.", frontend_html, backend_html, chart_image_path
|
336 |
|
337 |
except Exception as e:
|
338 |
return None, f"페르소나 로딩 중 오류 발생: {str(e)}", None, None, None
|
|
|
580 |
)
|
581 |
|
582 |
if __name__ == "__main__":
|
583 |
+
app.launch(server_name="0.0.0.0", share=False)
|
docker-compose.yml
ADDED
@@ -0,0 +1,14 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
version: '3'
|
2 |
+
|
3 |
+
services:
|
4 |
+
nompang-app:
|
5 |
+
build: .
|
6 |
+
container_name: nompang-test
|
7 |
+
ports:
|
8 |
+
- "7860:7860"
|
9 |
+
volumes:
|
10 |
+
- ./data:/app/data
|
11 |
+
environment:
|
12 |
+
- GRADIO_SERVER_NAME=0.0.0.0
|
13 |
+
- GRADIO_SERVER_PORT=7860
|
14 |
+
restart: unless-stopped
|