Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import sys
|
|
| 4 |
import tempfile
|
| 5 |
from io import StringIO
|
| 6 |
import traceback
|
|
|
|
| 7 |
|
| 8 |
# 환경변수에서 각 모듈 코드를 불러와서 실행
|
| 9 |
def load_and_execute_module(module_name):
|
|
@@ -21,20 +22,6 @@ def load_and_execute_module(module_name):
|
|
| 21 |
print(f"{module_name} 모듈 로드 중 오류: {str(e)}")
|
| 22 |
traceback.print_exc()
|
| 23 |
|
| 24 |
-
# 함수 존재 여부 확인 및 기본 함수 설정
|
| 25 |
-
def ensure_function_exists(func_name, fallback_func=None):
|
| 26 |
-
"""함수가 존재하지 않으면 기본 함수로 대체"""
|
| 27 |
-
if func_name not in globals():
|
| 28 |
-
if fallback_func and fallback_func in globals():
|
| 29 |
-
globals()[func_name] = globals()[fallback_func]
|
| 30 |
-
print(f"{func_name} 함수가 없어서 {fallback_func}로 대체했습니다.")
|
| 31 |
-
else:
|
| 32 |
-
# 기본 더미 함수 생성
|
| 33 |
-
def dummy_function(*args, **kwargs):
|
| 34 |
-
return f"{func_name} 함수가 정의되지 않았습니다."
|
| 35 |
-
globals()[func_name] = dummy_function
|
| 36 |
-
print(f"{func_name} 함수가 없어서 더미 함수로 대체했습니다.")
|
| 37 |
-
|
| 38 |
# 각 모듈 로드
|
| 39 |
print("모듈들을 로드하는 중...")
|
| 40 |
|
|
@@ -55,22 +42,169 @@ load_and_execute_module("VISIT_REVIEW_BLOG_CODE")
|
|
| 55 |
|
| 56 |
print("모든 모듈 로드 완료!")
|
| 57 |
|
| 58 |
-
#
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
-
#
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 72 |
|
| 73 |
-
print("
|
| 74 |
|
| 75 |
# Gradio 인터페이스 설계 (Gradio 5.0 이상)
|
| 76 |
def interface():
|
|
@@ -91,8 +225,8 @@ def interface():
|
|
| 91 |
blog_button_1 = gr.Button("블로그 글 생성")
|
| 92 |
blog_output_1 = gr.HTML(label="생성된 블로그 글 (HTML 형식)")
|
| 93 |
|
| 94 |
-
outline_button_1.click(
|
| 95 |
-
blog_button_1.click(
|
| 96 |
|
| 97 |
# 두 번째 탭: 여행
|
| 98 |
with gr.Tab("여행"):
|
|
@@ -108,8 +242,8 @@ def interface():
|
|
| 108 |
blog_button_2 = gr.Button("블로그 글 생성")
|
| 109 |
blog_output_2 = gr.HTML(label="생성된 블로그 글 (HTML 형식)")
|
| 110 |
|
| 111 |
-
outline_button_2.click(
|
| 112 |
-
blog_button_2.click(
|
| 113 |
|
| 114 |
# 세 번째 탭: 상품후기
|
| 115 |
with gr.Tab("상품후기"):
|
|
@@ -125,8 +259,8 @@ def interface():
|
|
| 125 |
blog_button_3 = gr.Button("블로그 글 생성")
|
| 126 |
blog_output_3 = gr.HTML(label="생성된 블로그 글 (HTML 형식)")
|
| 127 |
|
| 128 |
-
outline_button_3.click(
|
| 129 |
-
blog_button_3.click(
|
| 130 |
|
| 131 |
# 네 번째 탭: 핵심기능집중형
|
| 132 |
with gr.Tab("핵심기능집중형"):
|
|
@@ -143,8 +277,8 @@ def interface():
|
|
| 143 |
blog_button_4 = gr.Button("블로그 글 생성")
|
| 144 |
blog_output_4 = gr.HTML(label="생성된 블로그 글 (HTML 형식)")
|
| 145 |
|
| 146 |
-
outline_button_4.click(
|
| 147 |
-
blog_button_4.click(
|
| 148 |
|
| 149 |
# 다섯 번째 탭: 방문후기형
|
| 150 |
with gr.Tab("방문후기형"):
|
|
@@ -162,12 +296,12 @@ def interface():
|
|
| 162 |
blog_output_5 = gr.HTML(label="생성된 블로그 글 (HTML 형식)")
|
| 163 |
|
| 164 |
outline_button_5.click(
|
| 165 |
-
|
| 166 |
inputs=[category_5, style_5, ref1_5, ref2_5, ref3_5, photo_recommendations_5],
|
| 167 |
outputs=outline_output_5
|
| 168 |
)
|
| 169 |
blog_button_5.click(
|
| 170 |
-
|
| 171 |
inputs=[category_5, style_5, ref1_5, ref2_5, ref3_5, outline_5, photo_recommendations_5],
|
| 172 |
outputs=blog_output_5
|
| 173 |
)
|
|
|
|
| 4 |
import tempfile
|
| 5 |
from io import StringIO
|
| 6 |
import traceback
|
| 7 |
+
import inspect
|
| 8 |
|
| 9 |
# 환경변수에서 각 모듈 코드를 불러와서 실행
|
| 10 |
def load_and_execute_module(module_name):
|
|
|
|
| 22 |
print(f"{module_name} 모듈 로드 중 오류: {str(e)}")
|
| 23 |
traceback.print_exc()
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
# 각 모듈 로드
|
| 26 |
print("모듈들을 로드하는 중...")
|
| 27 |
|
|
|
|
| 42 |
|
| 43 |
print("모든 모듈 로드 완료!")
|
| 44 |
|
| 45 |
+
# 래퍼 함수들 정의
|
| 46 |
+
def safe_call_function(func_name, *args, **kwargs):
|
| 47 |
+
"""함수를 안전하게 호출하는 래퍼"""
|
| 48 |
+
try:
|
| 49 |
+
if func_name in globals():
|
| 50 |
+
func = globals()[func_name]
|
| 51 |
+
# 함수의 시그니처 확인
|
| 52 |
+
sig = inspect.signature(func)
|
| 53 |
+
params = list(sig.parameters.keys())
|
| 54 |
+
|
| 55 |
+
# 매개변수 수에 맞게 호출
|
| 56 |
+
if len(args) <= len(params):
|
| 57 |
+
return func(*args[:len(params)])
|
| 58 |
+
else:
|
| 59 |
+
return func(*args)
|
| 60 |
+
else:
|
| 61 |
+
return f"{func_name} 함수를 찾을 수 없습니다."
|
| 62 |
+
except Exception as e:
|
| 63 |
+
return f"{func_name} 호출 중 오류: {str(e)}"
|
| 64 |
+
|
| 65 |
+
# 각 탭별 래퍼 함수들
|
| 66 |
|
| 67 |
+
# 정보성 블로그 래퍼 함수들
|
| 68 |
+
def generate_outline_1_wrapper(category, style, ref1, ref2, ref3):
|
| 69 |
+
"""정보성 블로그 아웃라인 생성 래퍼"""
|
| 70 |
+
try:
|
| 71 |
+
if 'generate_outline_1' in globals():
|
| 72 |
+
return generate_outline_1(category, style, ref1, ref2, ref3)
|
| 73 |
+
elif 'generate_outline' in globals():
|
| 74 |
+
return generate_outline(category, style, ref1, ref2, ref3)
|
| 75 |
+
else:
|
| 76 |
+
return "정보성 블로그 아웃라인 생성 함수를 찾을 수 없습니다."
|
| 77 |
+
except Exception as e:
|
| 78 |
+
return f"정보성 블로그 아웃라인 생성 중 오류: {str(e)}"
|
| 79 |
+
|
| 80 |
+
def generate_blog_post_1_wrapper(category, style, ref1, ref2, ref3, outline):
|
| 81 |
+
"""정보성 블로그 글 생성 래퍼"""
|
| 82 |
+
try:
|
| 83 |
+
if 'generate_blog_post_1' in globals():
|
| 84 |
+
return generate_blog_post_1(category, style, ref1, ref2, ref3, outline)
|
| 85 |
+
elif 'generate_blog_post' in globals():
|
| 86 |
+
return generate_blog_post(category, style, outline, ref1, ref2, ref3)
|
| 87 |
+
else:
|
| 88 |
+
return "정보성 블로그 글 생성 함수를 찾을 수 없습니다."
|
| 89 |
+
except Exception as e:
|
| 90 |
+
return f"정보성 블로그 글 생성 중 오류: {str(e)}"
|
| 91 |
+
|
| 92 |
+
# 여행 블로그 래퍼 함수들
|
| 93 |
+
def generate_outline_2_wrapper(category, style, ref1, ref2, ref3):
|
| 94 |
+
"""여행 블로그 아웃라인 생성 래퍼"""
|
| 95 |
+
try:
|
| 96 |
+
if 'generate_outline_2' in globals():
|
| 97 |
+
return generate_outline_2(category, style, ref1, ref2, ref3)
|
| 98 |
+
elif 'generate_outline' in globals():
|
| 99 |
+
return generate_outline(category, style, ref1, ref2, ref3)
|
| 100 |
+
else:
|
| 101 |
+
return "여행 블로그 아웃라인 생성 함수를 찾을 수 없습니다."
|
| 102 |
+
except Exception as e:
|
| 103 |
+
return f"여행 블로그 아웃라인 생성 중 오류: {str(e)}"
|
| 104 |
+
|
| 105 |
+
def generate_blog_post_2_wrapper(category, style, ref1, ref2, ref3, outline):
|
| 106 |
+
"""여행 블로그 글 생성 래퍼"""
|
| 107 |
+
try:
|
| 108 |
+
if 'generate_blog_post_2' in globals():
|
| 109 |
+
return generate_blog_post_2(category, style, ref1, ref2, ref3, outline)
|
| 110 |
+
elif 'generate_blog_post' in globals():
|
| 111 |
+
return generate_blog_post(category, style, outline, ref1, ref2, ref3)
|
| 112 |
+
else:
|
| 113 |
+
return "여행 블로그 글 생성 함수를 찾을 수 없습니다."
|
| 114 |
+
except Exception as e:
|
| 115 |
+
return f"여행 블로그 글 생성 중 오류: {str(e)}"
|
| 116 |
+
|
| 117 |
+
# 상품후기 블로그 래퍼 함수들
|
| 118 |
+
def generate_outline_3_wrapper(category, style, ref1, ref2, ref3):
|
| 119 |
+
"""상품후기 블로그 아웃라인 생성 래퍼"""
|
| 120 |
+
try:
|
| 121 |
+
if 'generate_outline_3' in globals():
|
| 122 |
+
return generate_outline_3(category, style, ref1, ref2, ref3)
|
| 123 |
+
elif 'generate_outline' in globals():
|
| 124 |
+
return generate_outline(category, style, ref1, ref2, ref3)
|
| 125 |
+
else:
|
| 126 |
+
return "상품후기 블로그 아웃라인 생성 함수를 찾을 수 없습니다."
|
| 127 |
+
except Exception as e:
|
| 128 |
+
return f"상품후기 블로그 아웃라인 생성 중 오류: {str(e)}"
|
| 129 |
+
|
| 130 |
+
def generate_blog_post_3_wrapper(category, style, ref1, ref2, ref3, outline):
|
| 131 |
+
"""상품후기 블로그 글 생성 래퍼"""
|
| 132 |
+
try:
|
| 133 |
+
if 'generate_blog_post_3' in globals():
|
| 134 |
+
return generate_blog_post_3(category, style, ref1, ref2, ref3, outline)
|
| 135 |
+
elif 'generate_blog_post' in globals():
|
| 136 |
+
return generate_blog_post(category, style, outline, ref1, ref2, ref3)
|
| 137 |
+
else:
|
| 138 |
+
return "상품후기 블로그 글 생성 함수를 찾을 수 없습니다."
|
| 139 |
+
except Exception as e:
|
| 140 |
+
return f"상품후기 블로그 글 생성 중 오류: {str(e)}"
|
| 141 |
+
|
| 142 |
+
# 핵심기능집중형 블로그 래퍼 함수들
|
| 143 |
+
def generate_outline_4_wrapper(category, style, ref1, ref2, ref3):
|
| 144 |
+
"""핵심기능집중형 블로그 아웃라인 생성 래퍼"""
|
| 145 |
+
try:
|
| 146 |
+
if 'generate_outline_4' in globals():
|
| 147 |
+
result = generate_outline_4(category, style, ref1, ref2, ref3)
|
| 148 |
+
if isinstance(result, tuple) and len(result) == 3:
|
| 149 |
+
return result
|
| 150 |
+
else:
|
| 151 |
+
return (str(result), "", "")
|
| 152 |
+
elif 'generate_outline' in globals():
|
| 153 |
+
result = generate_outline(category, style, ref1, ref2, ref3)
|
| 154 |
+
return (str(result), "", "")
|
| 155 |
+
else:
|
| 156 |
+
return ("핵심기능집중형 블로그 아웃라인 생성 함수를 찾을 수 없습니다.", "", "")
|
| 157 |
+
except Exception as e:
|
| 158 |
+
return (f"핵심기능집중형 블로그 아웃라인 생성 중 오류: {str(e)}", "", "")
|
| 159 |
+
|
| 160 |
+
def generate_blog_post_4_wrapper(category, style, ref1, ref2, ref3, outline):
|
| 161 |
+
"""핵심기능집중형 블로그 글 생성 래퍼"""
|
| 162 |
+
try:
|
| 163 |
+
if 'generate_blog_post_4' in globals():
|
| 164 |
+
return generate_blog_post_4(category, style, ref1, ref2, ref3, outline)
|
| 165 |
+
elif 'generate_blog_post' in globals():
|
| 166 |
+
return generate_blog_post(category, style, outline, ref1, ref2, ref3)
|
| 167 |
+
else:
|
| 168 |
+
return "핵심기능집중형 블로그 글 생성 함수를 찾을 수 없습니다."
|
| 169 |
+
except Exception as e:
|
| 170 |
+
return f"핵심기능집중형 블로그 글 생성 중 오류: {str(e)}"
|
| 171 |
+
|
| 172 |
+
# 방문후기형 블로그 래퍼 함수들
|
| 173 |
+
def generate_outline_5_wrapper(category, style, ref1, ref2, ref3, photo_recommendations):
|
| 174 |
+
"""방문후기형 블로그 아웃라인 생성 래퍼"""
|
| 175 |
+
try:
|
| 176 |
+
if 'generate_outline_5' in globals():
|
| 177 |
+
return generate_outline_5(category, style, ref1, ref2, ref3, photo_recommendations)
|
| 178 |
+
elif 'generate_outline' in globals():
|
| 179 |
+
# photo_recommendations 매개변수가 있는 경우
|
| 180 |
+
sig = inspect.signature(generate_outline)
|
| 181 |
+
if len(sig.parameters) >= 6:
|
| 182 |
+
return generate_outline(category, style, ref1, ref2, ref3, photo_recommendations)
|
| 183 |
+
else:
|
| 184 |
+
return generate_outline(category, style, ref1, ref2, ref3)
|
| 185 |
+
else:
|
| 186 |
+
return "방문후기형 블로그 아웃라인 생성 함수를 찾을 수 없습니다."
|
| 187 |
+
except Exception as e:
|
| 188 |
+
return f"방문후기형 블로그 아웃라인 생성 중 오류: {str(e)}"
|
| 189 |
+
|
| 190 |
+
def generate_blog_post_5_wrapper(category, style, ref1, ref2, ref3, outline, photo_recommendations):
|
| 191 |
+
"""방문후기형 블로그 글 생성 래퍼"""
|
| 192 |
+
try:
|
| 193 |
+
if 'generate_blog_post_5' in globals():
|
| 194 |
+
return generate_blog_post_5(category, style, ref1, ref2, ref3, outline, photo_recommendations)
|
| 195 |
+
elif 'generate_blog_post' in globals():
|
| 196 |
+
# photo_recommendations 매개변수가 있는 경우
|
| 197 |
+
sig = inspect.signature(generate_blog_post)
|
| 198 |
+
if len(sig.parameters) >= 7:
|
| 199 |
+
return generate_blog_post(category, style, ref1, ref2, ref3, outline, photo_recommendations)
|
| 200 |
+
else:
|
| 201 |
+
return generate_blog_post(category, style, outline, ref1, ref2, ref3)
|
| 202 |
+
else:
|
| 203 |
+
return "방문후기형 블로그 글 생성 함수를 찾을 수 없습니다."
|
| 204 |
+
except Exception as e:
|
| 205 |
+
return f"방문후기형 블로그 글 생성 중 오류: {str(e)}"
|
| 206 |
|
| 207 |
+
print("래퍼 함수��� 정의 완료!")
|
| 208 |
|
| 209 |
# Gradio 인터페이스 설계 (Gradio 5.0 이상)
|
| 210 |
def interface():
|
|
|
|
| 225 |
blog_button_1 = gr.Button("블로그 글 생성")
|
| 226 |
blog_output_1 = gr.HTML(label="생성된 블로그 글 (HTML 형식)")
|
| 227 |
|
| 228 |
+
outline_button_1.click(generate_outline_1_wrapper, inputs=[category_1, style_1, ref1_1, ref2_1, ref3_1], outputs=outline_output_1)
|
| 229 |
+
blog_button_1.click(generate_blog_post_1_wrapper, inputs=[category_1, style_1, ref1_1, ref2_1, ref3_1, outline_1], outputs=blog_output_1)
|
| 230 |
|
| 231 |
# 두 번째 탭: 여행
|
| 232 |
with gr.Tab("여행"):
|
|
|
|
| 242 |
blog_button_2 = gr.Button("블로그 글 생성")
|
| 243 |
blog_output_2 = gr.HTML(label="생성된 블로그 글 (HTML 형식)")
|
| 244 |
|
| 245 |
+
outline_button_2.click(generate_outline_2_wrapper, inputs=[category_2, style_2, ref1_2, ref2_2, ref3_2], outputs=outline_output_2)
|
| 246 |
+
blog_button_2.click(generate_blog_post_2_wrapper, inputs=[category_2, style_2, ref1_2, ref2_2, ref3_2, outline_2], outputs=blog_output_2)
|
| 247 |
|
| 248 |
# 세 번째 탭: 상품후기
|
| 249 |
with gr.Tab("상품후기"):
|
|
|
|
| 259 |
blog_button_3 = gr.Button("블로그 글 생성")
|
| 260 |
blog_output_3 = gr.HTML(label="생성된 블로그 글 (HTML 형식)")
|
| 261 |
|
| 262 |
+
outline_button_3.click(generate_outline_3_wrapper, inputs=[category_3, style_3, ref1_3, ref2_3, ref3_3], outputs=outline_output_3)
|
| 263 |
+
blog_button_3.click(generate_blog_post_3_wrapper, inputs=[category_3, style_3, ref1_3, ref2_3, ref3_3, outline_3], outputs=blog_output_3)
|
| 264 |
|
| 265 |
# 네 번째 탭: 핵심기능집중형
|
| 266 |
with gr.Tab("핵심기능집중형"):
|
|
|
|
| 277 |
blog_button_4 = gr.Button("블로그 글 생성")
|
| 278 |
blog_output_4 = gr.HTML(label="생성된 블로그 글 (HTML 형식)")
|
| 279 |
|
| 280 |
+
outline_button_4.click(generate_outline_4_wrapper, inputs=[category_4, style_4, ref1_4, ref2_4, ref3_4], outputs=[outline_result1, outline_result2, outline_result3])
|
| 281 |
+
blog_button_4.click(generate_blog_post_4_wrapper, inputs=[category_4, style_4, ref1_4, ref2_4, ref3_4, outline_4], outputs=blog_output_4)
|
| 282 |
|
| 283 |
# 다섯 번째 탭: 방문후기형
|
| 284 |
with gr.Tab("방문후기형"):
|
|
|
|
| 296 |
blog_output_5 = gr.HTML(label="생성된 블로그 글 (HTML 형식)")
|
| 297 |
|
| 298 |
outline_button_5.click(
|
| 299 |
+
generate_outline_5_wrapper,
|
| 300 |
inputs=[category_5, style_5, ref1_5, ref2_5, ref3_5, photo_recommendations_5],
|
| 301 |
outputs=outline_output_5
|
| 302 |
)
|
| 303 |
blog_button_5.click(
|
| 304 |
+
generate_blog_post_5_wrapper,
|
| 305 |
inputs=[category_5, style_5, ref1_5, ref2_5, ref3_5, outline_5, photo_recommendations_5],
|
| 306 |
outputs=blog_output_5
|
| 307 |
)
|