Update app.py
Browse files
app.py
CHANGED
|
@@ -1,16 +1,9 @@
|
|
| 1 |
#app.py
|
| 2 |
import gradio as gr
|
|
|
|
| 3 |
import os
|
| 4 |
-
import sys
|
| 5 |
import tempfile
|
| 6 |
import importlib.util
|
| 7 |
-
import re
|
| 8 |
-
from bs4 import BeautifulSoup
|
| 9 |
-
import requests
|
| 10 |
-
from fpdf import FPDF
|
| 11 |
-
import markdown2
|
| 12 |
-
from PIL import Image
|
| 13 |
-
import google.generativeai as genai
|
| 14 |
|
| 15 |
def load_module_from_env(env_var_name, module_name):
|
| 16 |
"""환경변수에서 모듈 코드를 가져와서 동적으로 로드"""
|
|
@@ -18,111 +11,9 @@ def load_module_from_env(env_var_name, module_name):
|
|
| 18 |
if not module_code:
|
| 19 |
raise ValueError(f"환경변수 {env_var_name}가 설정되지 않았습니다.")
|
| 20 |
|
| 21 |
-
# 필요한 임포트문들을 모듈 코드 앞에 추가
|
| 22 |
-
required_imports = """
|
| 23 |
-
import os
|
| 24 |
-
import re
|
| 25 |
-
import random
|
| 26 |
-
import logging
|
| 27 |
-
import requests
|
| 28 |
-
from bs4 import BeautifulSoup
|
| 29 |
-
from fpdf import FPDF
|
| 30 |
-
import markdown2
|
| 31 |
-
from PIL import Image
|
| 32 |
-
import google.generativeai as genai
|
| 33 |
-
from typing import List, Dict, Any, Optional
|
| 34 |
-
import sys
|
| 35 |
-
import tempfile
|
| 36 |
-
import json
|
| 37 |
-
|
| 38 |
-
# Google Generative AI 설정 및 MockClient 정의
|
| 39 |
-
try:
|
| 40 |
-
import google.generativeai as genai
|
| 41 |
-
|
| 42 |
-
# 완전한 MockClient 클래스 정의
|
| 43 |
-
class MockClient:
|
| 44 |
-
def __init__(self, *args, **kwargs):
|
| 45 |
-
self.models = MockModels()
|
| 46 |
-
|
| 47 |
-
def generate_content(self, *args, **kwargs):
|
| 48 |
-
return MockResponse()
|
| 49 |
-
|
| 50 |
-
class MockModels:
|
| 51 |
-
def list(self, *args, **kwargs):
|
| 52 |
-
return []
|
| 53 |
-
|
| 54 |
-
def get(self, model_name):
|
| 55 |
-
return MockModel()
|
| 56 |
-
|
| 57 |
-
class MockModel:
|
| 58 |
-
def __init__(self):
|
| 59 |
-
self.name = "mock-model"
|
| 60 |
-
|
| 61 |
-
def generate_content(self, *args, **kwargs):
|
| 62 |
-
return MockResponse()
|
| 63 |
-
|
| 64 |
-
class MockResponse:
|
| 65 |
-
def __init__(self):
|
| 66 |
-
self.text = "환경설정 문제로 모의 응답을 반환합니다."
|
| 67 |
-
self.candidates = [MockCandidate()]
|
| 68 |
-
|
| 69 |
-
class MockCandidate:
|
| 70 |
-
def __init__(self):
|
| 71 |
-
self.content = MockContent()
|
| 72 |
-
|
| 73 |
-
class MockContent:
|
| 74 |
-
def __init__(self):
|
| 75 |
-
self.parts = [MockPart()]
|
| 76 |
-
|
| 77 |
-
class MockPart:
|
| 78 |
-
def __init__(self):
|
| 79 |
-
self.text = "환경설정 문제로 모의 응답을 반환합니다."
|
| 80 |
-
|
| 81 |
-
# Client 클래스가 없는 경우에만 대체 처리
|
| 82 |
-
if not hasattr(genai, 'Client'):
|
| 83 |
-
genai.Client = MockClient
|
| 84 |
-
print("MockClient로 대체되었습니다.")
|
| 85 |
-
else:
|
| 86 |
-
print("Google Generative AI Client를 사용합니다.")
|
| 87 |
-
|
| 88 |
-
except ImportError as e:
|
| 89 |
-
print(f"Google Generative AI 라이브러리 임포트 오류: {e}")
|
| 90 |
-
|
| 91 |
-
# 완전한 genai 모듈 mock
|
| 92 |
-
class MockGenAI:
|
| 93 |
-
def __init__(self):
|
| 94 |
-
self.Client = MockClient
|
| 95 |
-
|
| 96 |
-
def configure(self, *args, **kwargs):
|
| 97 |
-
pass
|
| 98 |
-
|
| 99 |
-
def list_models(self):
|
| 100 |
-
return []
|
| 101 |
-
|
| 102 |
-
def GenerativeModel(self, model_name):
|
| 103 |
-
return MockModel()
|
| 104 |
-
|
| 105 |
-
genai = MockGenAI()
|
| 106 |
-
"""
|
| 107 |
-
|
| 108 |
-
# 기존 import문들을 제거하고 새로운 import문 추가
|
| 109 |
-
lines = module_code.split('\n')
|
| 110 |
-
filtered_lines = []
|
| 111 |
-
for line in lines:
|
| 112 |
-
stripped = line.strip()
|
| 113 |
-
# import문이나 from문이 아닌 경우만 포함
|
| 114 |
-
if not (stripped.startswith('import ') or stripped.startswith('from ') or stripped.startswith('#')):
|
| 115 |
-
filtered_lines.append(line)
|
| 116 |
-
elif stripped.startswith('#') and not any(keyword in stripped.lower() for keyword in ['import', 'from']):
|
| 117 |
-
# 주석은 import 관련이 아닌 경우만 포함
|
| 118 |
-
filtered_lines.append(line)
|
| 119 |
-
|
| 120 |
-
# 새로운 모듈 코드 구성
|
| 121 |
-
full_module_code = required_imports + '\n' + '\n'.join(filtered_lines)
|
| 122 |
-
|
| 123 |
# 임시 파일 생성
|
| 124 |
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False, encoding='utf-8') as f:
|
| 125 |
-
f.write(
|
| 126 |
temp_file_path = f.name
|
| 127 |
|
| 128 |
try:
|
|
@@ -131,185 +22,31 @@ except ImportError as e:
|
|
| 131 |
module = importlib.util.module_from_spec(spec)
|
| 132 |
spec.loader.exec_module(module)
|
| 133 |
return module
|
| 134 |
-
except Exception as e:
|
| 135 |
-
print(f"모듈 {module_name} 로드 중 오류 발생: {e}")
|
| 136 |
-
return None
|
| 137 |
finally:
|
| 138 |
# 임시 파일 삭제
|
| 139 |
if os.path.exists(temp_file_path):
|
| 140 |
os.unlink(temp_file_path)
|
| 141 |
|
| 142 |
-
#
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
info_blog_module = None
|
| 163 |
-
|
| 164 |
-
try:
|
| 165 |
-
travel_blog_module = load_module_from_env('TRAVEL_BLOG_CODE', 'travel_blog')
|
| 166 |
-
print("✓ TRAVEL_BLOG_CODE 모듈 로드 성공")
|
| 167 |
-
except ValueError as e:
|
| 168 |
-
print(f"✗ TRAVEL_BLOG_CODE 로드 실패: {e}")
|
| 169 |
-
travel_blog_module = None
|
| 170 |
-
|
| 171 |
-
try:
|
| 172 |
-
product_review_blog_module = load_module_from_env('PRODUCT_REVIEW_BLOG_CODE', 'product_review_blog')
|
| 173 |
-
print("✓ PRODUCT_REVIEW_BLOG_CODE 모듈 로드 성공")
|
| 174 |
-
except ValueError as e:
|
| 175 |
-
print(f"✗ PRODUCT_REVIEW_BLOG_CODE 로드 실패: {e}")
|
| 176 |
-
product_review_blog_module = None
|
| 177 |
-
|
| 178 |
-
try:
|
| 179 |
-
feature_focus_blog_module = load_module_from_env('FEATURE_FOCUS_BLOG_CODE', 'feature_focus_blog')
|
| 180 |
-
print("✓ FEATURE_FOCUS_BLOG_CODE 모듈 로드 성공")
|
| 181 |
-
except ValueError as e:
|
| 182 |
-
print(f"✗ FEATURE_FOCUS_BLOG_CODE 로드 실패: {e}")
|
| 183 |
-
feature_focus_blog_module = None
|
| 184 |
-
|
| 185 |
-
try:
|
| 186 |
-
visit_review_blog_module = load_module_from_env('VISIT_REVIEW_BLOG_CODE', 'visit_review_blog')
|
| 187 |
-
print("✓ VISIT_REVIEW_BLOG_CODE 모듈 로드 성공")
|
| 188 |
-
except ValueError as e:
|
| 189 |
-
print(f"✗ VISIT_REVIEW_BLOG_CODE 로드 실패: {e}")
|
| 190 |
-
visit_review_blog_module = None
|
| 191 |
-
|
| 192 |
-
# 로드 실패한 모듈들을 더미로 대체
|
| 193 |
-
class DummyModule:
|
| 194 |
-
def generate_outline_1(self, *args): return "해당 모듈의 환경변수가 설정되지 않았습니다."
|
| 195 |
-
def generate_blog_post_1(self, *args): return "해당 모듈의 환경변수가 설정되지 않았습니다."
|
| 196 |
-
def generate_outline_2(self, *args): return "해당 모듈의 환경변수가 설정되지 않았습니다."
|
| 197 |
-
def generate_blog_post_2(self, *args): return "해당 모듈의 환경변수가 설정되지 않았습니다."
|
| 198 |
-
def generate_outline_3(self, *args): return "해당 모듈의 환경변수가 설정되지 않았습니다."
|
| 199 |
-
def generate_blog_post_3(self, *args): return "해당 모듈의 환경변수가 설정되지 않았습니다."
|
| 200 |
-
def generate_outline_4(self, *args): return "해당 모듈의 환경변수가 설정되지 않았습니다."
|
| 201 |
-
def generate_blog_post_4(self, *args): return "해당 모듈의 환경변수가 설정되지 않았습니다."
|
| 202 |
-
def generate_outline_5(self, *args): return "해당 모듈의 환경변수가 설정되지 않았습니다."
|
| 203 |
-
def generate_blog_post_5(self, *args): return "해당 모듈의 환경변수가 설정되지 않았습니다."
|
| 204 |
-
|
| 205 |
-
dummy = DummyModule()
|
| 206 |
-
if not info_blog_module: info_blog_module = dummy
|
| 207 |
-
if not travel_blog_module: travel_blog_module = dummy
|
| 208 |
-
if not product_review_blog_module: product_review_blog_module = dummy
|
| 209 |
-
if not feature_focus_blog_module: feature_focus_blog_module = dummy
|
| 210 |
-
if not visit_review_blog_module: visit_review_blog_module = dummy
|
| 211 |
-
|
| 212 |
-
# 환경변수에서 로드된 모듈들의 함수를 전역으로 할당 (실제 모듈의 함수명에 맞춰 수정)
|
| 213 |
-
try:
|
| 214 |
-
# 각 모듈에서 실제로 존재하는 함수명들을 확인하고 할당
|
| 215 |
-
print("info_blog_module 함수들:", [attr for attr in dir(info_blog_module) if not attr.startswith('_')])
|
| 216 |
-
print("travel_blog_module 함수들:", [attr for attr in dir(travel_blog_module) if not attr.startswith('_')])
|
| 217 |
-
print("product_review_blog_module 함수들:", [attr for attr in dir(product_review_blog_module) if not attr.startswith('_')])
|
| 218 |
-
print("feature_focus_blog_module 함수들:", [attr for attr in dir(feature_focus_blog_module) if not attr.startswith('_')])
|
| 219 |
-
print("visit_review_blog_module 함수들:", [attr for attr in dir(visit_review_blog_module) if not attr.startswith('_')])
|
| 220 |
-
|
| 221 |
-
# info_blog 모듈 함수 할당 (실제 함수명 확인 후 할당)
|
| 222 |
-
if hasattr(info_blog_module, 'generate_outline_1'):
|
| 223 |
-
generate_outline_1 = info_blog_module.generate_outline_1
|
| 224 |
-
elif hasattr(info_blog_module, 'generate_outline'):
|
| 225 |
-
generate_outline_1 = info_blog_module.generate_outline
|
| 226 |
-
else:
|
| 227 |
-
generate_outline_1 = lambda *args: "info_blog 모듈에서 아웃라인 생성 함수를 찾을 수 없습니다."
|
| 228 |
-
|
| 229 |
-
if hasattr(info_blog_module, 'generate_blog_post_1'):
|
| 230 |
-
generate_blog_post_1 = info_blog_module.generate_blog_post_1
|
| 231 |
-
elif hasattr(info_blog_module, 'generate_blog_post'):
|
| 232 |
-
generate_blog_post_1 = info_blog_module.generate_blog_post
|
| 233 |
-
else:
|
| 234 |
-
generate_blog_post_1 = lambda *args: "info_blog 모듈에서 블로그 생성 함수를 찾을 수 없습니다."
|
| 235 |
-
|
| 236 |
-
# travel_blog 모듈 함수 할당
|
| 237 |
-
if hasattr(travel_blog_module, 'generate_outline_2'):
|
| 238 |
-
generate_outline_2 = travel_blog_module.generate_outline_2
|
| 239 |
-
elif hasattr(travel_blog_module, 'generate_outline'):
|
| 240 |
-
generate_outline_2 = travel_blog_module.generate_outline
|
| 241 |
-
else:
|
| 242 |
-
generate_outline_2 = lambda *args: "travel_blog 모듈에서 아웃라인 생성 함수를 찾을 수 없습니다."
|
| 243 |
-
|
| 244 |
-
if hasattr(travel_blog_module, 'generate_blog_post_2'):
|
| 245 |
-
generate_blog_post_2 = travel_blog_module.generate_blog_post_2
|
| 246 |
-
elif hasattr(travel_blog_module, 'generate_blog_post'):
|
| 247 |
-
generate_blog_post_2 = travel_blog_module.generate_blog_post
|
| 248 |
-
else:
|
| 249 |
-
generate_blog_post_2 = lambda *args: "travel_blog 모듈에서 블로그 생성 함수를 찾을 수 없습니다."
|
| 250 |
-
|
| 251 |
-
# product_review_blog 모듈 함수 할당
|
| 252 |
-
if hasattr(product_review_blog_module, 'generate_outline_3'):
|
| 253 |
-
generate_outline_3 = product_review_blog_module.generate_outline_3
|
| 254 |
-
elif hasattr(product_review_blog_module, 'generate_outline'):
|
| 255 |
-
generate_outline_3 = product_review_blog_module.generate_outline
|
| 256 |
-
else:
|
| 257 |
-
generate_outline_3 = lambda *args: "product_review_blog 모듈에서 아웃라인 생성 함수를 찾을 수 없습니다."
|
| 258 |
-
|
| 259 |
-
if hasattr(product_review_blog_module, 'generate_blog_post_3'):
|
| 260 |
-
generate_blog_post_3 = product_review_blog_module.generate_blog_post_3
|
| 261 |
-
elif hasattr(product_review_blog_module, 'generate_blog_post'):
|
| 262 |
-
generate_blog_post_3 = product_review_blog_module.generate_blog_post
|
| 263 |
-
else:
|
| 264 |
-
generate_blog_post_3 = lambda *args: "product_review_blog 모듈에서 블로그 생성 함수를 찾을 수 없습니다."
|
| 265 |
-
|
| 266 |
-
# feature_focus_blog 모듈 함수 할당
|
| 267 |
-
if hasattr(feature_focus_blog_module, 'generate_outline_4'):
|
| 268 |
-
generate_outline_4 = feature_focus_blog_module.generate_outline_4
|
| 269 |
-
elif hasattr(feature_focus_blog_module, 'generate_outline'):
|
| 270 |
-
generate_outline_4 = feature_focus_blog_module.generate_outline
|
| 271 |
-
else:
|
| 272 |
-
generate_outline_4 = lambda *args: "feature_focus_blog 모듈에서 아웃라인 생성 함수를 찾을 수 없습니다."
|
| 273 |
-
|
| 274 |
-
if hasattr(feature_focus_blog_module, 'generate_blog_post_4'):
|
| 275 |
-
generate_blog_post_4 = feature_focus_blog_module.generate_blog_post_4
|
| 276 |
-
elif hasattr(feature_focus_blog_module, 'generate_blog_post'):
|
| 277 |
-
generate_blog_post_4 = feature_focus_blog_module.generate_blog_post
|
| 278 |
-
else:
|
| 279 |
-
generate_blog_post_4 = lambda *args: "feature_focus_blog 모듈에서 블로그 생성 함수를 찾을 수 없습니다."
|
| 280 |
-
|
| 281 |
-
# visit_review_blog 모듈 함수 할당
|
| 282 |
-
if hasattr(visit_review_blog_module, 'generate_outline_5'):
|
| 283 |
-
generate_outline_5 = visit_review_blog_module.generate_outline_5
|
| 284 |
-
elif hasattr(visit_review_blog_module, 'generate_outline'):
|
| 285 |
-
generate_outline_5 = visit_review_blog_module.generate_outline
|
| 286 |
-
else:
|
| 287 |
-
generate_outline_5 = lambda *args: "visit_review_blog 모듈에서 아웃라인 생성 함수를 찾을 수 없습니다."
|
| 288 |
-
|
| 289 |
-
if hasattr(visit_review_blog_module, 'generate_blog_post_5'):
|
| 290 |
-
generate_blog_post_5 = visit_review_blog_module.generate_blog_post_5
|
| 291 |
-
elif hasattr(visit_review_blog_module, 'generate_blog_post'):
|
| 292 |
-
generate_blog_post_5 = visit_review_blog_module.generate_blog_post
|
| 293 |
-
else:
|
| 294 |
-
generate_blog_post_5 = lambda *args: "visit_review_blog 모듈에서 블로그 생성 함수를 찾을 수 없습니다."
|
| 295 |
-
|
| 296 |
-
print("✓ 모든 함수 할당 완료")
|
| 297 |
-
|
| 298 |
-
except AttributeError as e:
|
| 299 |
-
print(f"함수 할당 에러: {e}")
|
| 300 |
-
# 더미 함수들
|
| 301 |
-
def generate_outline_1(*args): return "환경변수가 설정되지 않았습니다."
|
| 302 |
-
def generate_blog_post_1(*args): return "환경변수가 설정되지 않았습니다."
|
| 303 |
-
def generate_outline_2(*args): return "환경변수가 설정되지 않았습니다."
|
| 304 |
-
def generate_blog_post_2(*args): return "환경변수가 설정되지 않았습니다."
|
| 305 |
-
def generate_outline_3(*args): return "환경변수가 설정되지 않았습니다."
|
| 306 |
-
def generate_blog_post_3(*args): return "환경변수가 설정되지 않았습니다."
|
| 307 |
-
def generate_outline_4(*args): return "환경변수가 설정되지 않았습니다."
|
| 308 |
-
def generate_blog_post_4(*args): return "환경변수가 설정되지 않았습니다."
|
| 309 |
-
def generate_outline_5(*args): return "환경변수가 설정되지 않았습니다."
|
| 310 |
-
def generate_blog_post_5(*args): return "환경변수가 설정되지 않았습니다."
|
| 311 |
-
|
| 312 |
-
# 원본과 동일한 API 함수 정의 (함수명 그대로 유지)
|
| 313 |
def generate_outline_1_api(category, style, ref1, ref2, ref3):
|
| 314 |
result = generate_outline_1(category, style, ref1, ref2, ref3)
|
| 315 |
return result
|
|
@@ -318,7 +55,7 @@ def generate_blog_post_1_api(category, style, ref1, ref2, ref3, outline_input):
|
|
| 318 |
result = generate_blog_post_1(category, style, ref1, ref2, ref3, outline_input)
|
| 319 |
return result
|
| 320 |
|
| 321 |
-
# API 함수 정의 (여행)
|
| 322 |
def generate_outline_2_api(category, style, ref1, ref2, ref3):
|
| 323 |
result = generate_outline_2(category, style, ref1, ref2, ref3)
|
| 324 |
return result
|
|
@@ -327,7 +64,7 @@ def generate_blog_post_2_api(category, style, ref1, ref2, ref3, outline_input):
|
|
| 327 |
result = generate_blog_post_2(category, style, ref1, ref2, ref3, outline_input)
|
| 328 |
return result
|
| 329 |
|
| 330 |
-
# API 함수 정의 (상품후기)
|
| 331 |
def generate_outline_3_api(category, style, ref1, ref2, ref3):
|
| 332 |
result = generate_outline_3(category, style, ref1, ref2, ref3)
|
| 333 |
return result
|
|
@@ -336,7 +73,7 @@ def generate_blog_post_3_api(category, style, ref1, ref2, ref3, outline_input):
|
|
| 336 |
result = generate_blog_post_3(category, style, ref1, ref2, ref3, outline_input)
|
| 337 |
return result
|
| 338 |
|
| 339 |
-
# API 함수 정의 (핵심기능집중형)
|
| 340 |
def generate_outline_4_api(category, style, ref1, ref2, ref3):
|
| 341 |
result = generate_outline_4(category, style, ref1, ref2, ref3)
|
| 342 |
return result
|
|
@@ -345,7 +82,7 @@ def generate_blog_post_4_api(category, style, ref1, ref2, ref3, selected_feature
|
|
| 345 |
result = generate_blog_post_4(category, style, ref1, ref2, ref3, selected_feature)
|
| 346 |
return result
|
| 347 |
|
| 348 |
-
# API 함수 정의 (방문후기형)
|
| 349 |
def generate_outline_5_api(category, style, ref1, ref2, ref3, photo_recommendations):
|
| 350 |
result = generate_outline_5(category, style, ref1, ref2, ref3, photo_recommendations)
|
| 351 |
return result
|
|
|
|
| 1 |
#app.py
|
| 2 |
import gradio as gr
|
| 3 |
+
from gradio_client import Client
|
| 4 |
import os
|
|
|
|
| 5 |
import tempfile
|
| 6 |
import importlib.util
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
def load_module_from_env(env_var_name, module_name):
|
| 9 |
"""환경변수에서 모듈 코드를 가져와서 동적으로 로드"""
|
|
|
|
| 11 |
if not module_code:
|
| 12 |
raise ValueError(f"환경변수 {env_var_name}가 설정되지 않았습니다.")
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
# 임시 파일 생성
|
| 15 |
with tempfile.NamedTemporaryFile(mode='w', suffix='.py', delete=False, encoding='utf-8') as f:
|
| 16 |
+
f.write(module_code)
|
| 17 |
temp_file_path = f.name
|
| 18 |
|
| 19 |
try:
|
|
|
|
| 22 |
module = importlib.util.module_from_spec(spec)
|
| 23 |
spec.loader.exec_module(module)
|
| 24 |
return module
|
|
|
|
|
|
|
|
|
|
| 25 |
finally:
|
| 26 |
# 임시 파일 삭제
|
| 27 |
if os.path.exists(temp_file_path):
|
| 28 |
os.unlink(temp_file_path)
|
| 29 |
|
| 30 |
+
# 환경변수에서 각 모듈 로드 (원본과 동일한 방식)
|
| 31 |
+
info_blog = load_module_from_env('INFO_BLOG_CODE', 'info_blog')
|
| 32 |
+
travel_blog = load_module_from_env('TRAVEL_BLOG_CODE', 'travel_blog')
|
| 33 |
+
product_review_blog = load_module_from_env('PRODUCT_REVIEW_BLOG_CODE', 'product_review_blog')
|
| 34 |
+
feature_focus_blog = load_module_from_env('FEATURE_FOCUS_BLOG_CODE', 'feature_focus_blog')
|
| 35 |
+
visit_review_blog = load_module_from_env('VISIT_REVIEW_BLOG_CODE', 'visit_review_blog')
|
| 36 |
+
|
| 37 |
+
# 환경변수에서 로드된 모듈에서 함수 가져오기 (원본과 동일)
|
| 38 |
+
generate_outline_1 = info_blog.generate_outline_1
|
| 39 |
+
generate_blog_post_1 = info_blog.generate_blog_post_1
|
| 40 |
+
generate_outline_2 = travel_blog.generate_outline_2
|
| 41 |
+
generate_blog_post_2 = travel_blog.generate_blog_post_2
|
| 42 |
+
generate_outline_3 = product_review_blog.generate_outline_3
|
| 43 |
+
generate_blog_post_3 = product_review_blog.generate_blog_post_3
|
| 44 |
+
generate_outline_4 = feature_focus_blog.generate_outline_4
|
| 45 |
+
generate_blog_post_4 = feature_focus_blog.generate_blog_post_4
|
| 46 |
+
generate_outline_5 = visit_review_blog.generate_outline_5
|
| 47 |
+
generate_blog_post_5 = visit_review_blog.generate_blog_post_5
|
| 48 |
+
|
| 49 |
+
# 기존 API 함수 정의 (정보성)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 50 |
def generate_outline_1_api(category, style, ref1, ref2, ref3):
|
| 51 |
result = generate_outline_1(category, style, ref1, ref2, ref3)
|
| 52 |
return result
|
|
|
|
| 55 |
result = generate_blog_post_1(category, style, ref1, ref2, ref3, outline_input)
|
| 56 |
return result
|
| 57 |
|
| 58 |
+
# 기존 API 함수 정의 (여행)
|
| 59 |
def generate_outline_2_api(category, style, ref1, ref2, ref3):
|
| 60 |
result = generate_outline_2(category, style, ref1, ref2, ref3)
|
| 61 |
return result
|
|
|
|
| 64 |
result = generate_blog_post_2(category, style, ref1, ref2, ref3, outline_input)
|
| 65 |
return result
|
| 66 |
|
| 67 |
+
# 기존 API 함수 정의 (상품후기)
|
| 68 |
def generate_outline_3_api(category, style, ref1, ref2, ref3):
|
| 69 |
result = generate_outline_3(category, style, ref1, ref2, ref3)
|
| 70 |
return result
|
|
|
|
| 73 |
result = generate_blog_post_3(category, style, ref1, ref2, ref3, outline_input)
|
| 74 |
return result
|
| 75 |
|
| 76 |
+
# 새로운 API 함수 정의 (핵심기능집중형)
|
| 77 |
def generate_outline_4_api(category, style, ref1, ref2, ref3):
|
| 78 |
result = generate_outline_4(category, style, ref1, ref2, ref3)
|
| 79 |
return result
|
|
|
|
| 82 |
result = generate_blog_post_4(category, style, ref1, ref2, ref3, selected_feature)
|
| 83 |
return result
|
| 84 |
|
| 85 |
+
# 새로운 API 함수 정의 (방문후기형)
|
| 86 |
def generate_outline_5_api(category, style, ref1, ref2, ref3, photo_recommendations):
|
| 87 |
result = generate_outline_5(category, style, ref1, ref2, ref3, photo_recommendations)
|
| 88 |
return result
|