Update app.py
Browse files
app.py
CHANGED
|
@@ -141,7 +141,7 @@ def generate_response(user_prompt):
|
|
| 141 |
timeout=15
|
| 142 |
)
|
| 143 |
# ChatCompletion 응답 텍스트 반환
|
| 144 |
-
return response.choices[0].message.content
|
| 145 |
except openai.OpenAIError as e:
|
| 146 |
# OpenAI 관련 에러 처리
|
| 147 |
return f"OpenAI API 오류: {str(e)}"
|
|
@@ -214,7 +214,7 @@ def jsonl_to_description(json_data):
|
|
| 214 |
|
| 215 |
|
| 216 |
# 최종 결과물 생성
|
| 217 |
-
def generate_final_output(text_result, image_result):
|
| 218 |
name = text_result.get("Name", "Unknown name")
|
| 219 |
description = text_result.get("Description", "Unknown description")
|
| 220 |
magic = text_result.get("Magic", "Unknown name")
|
|
@@ -240,7 +240,7 @@ def generate_final_output(text_result, image_result):
|
|
| 240 |
|
| 241 |
now = datetime.datetime.now()
|
| 242 |
date_str = now.strftime('%Y.%m.%d')
|
| 243 |
-
cert = date_str + '\n' +
|
| 244 |
|
| 245 |
draw.multiline_text((523, 911), cert, fill="#B49F91", font=font_cert, anchor='ra', align='right')
|
| 246 |
|
|
@@ -252,13 +252,13 @@ def generate_final_output(text_result, image_result):
|
|
| 252 |
# Gradio 인터페이스 설정
|
| 253 |
def generate_combined_response(user_prompt):
|
| 254 |
# GPT 응답 생성
|
| 255 |
-
gpt_response = generate_response(user_prompt)
|
| 256 |
# GPT 응답을 텍스트로 출력하고 Stable Diffusion으로 이미지 생성
|
| 257 |
gpt_jsonl = json.loads(gpt_response) # JSON은 쌍따옴표를 사용해야 함
|
| 258 |
print(gpt_response)
|
| 259 |
sd_prompt = jsonl_to_description(gpt_jsonl)
|
| 260 |
image = generate_image(sd_prompt)
|
| 261 |
-
final_image = generate_final_output(gpt_jsonl, image)
|
| 262 |
|
| 263 |
|
| 264 |
now_str = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|
|
|
|
| 141 |
timeout=15
|
| 142 |
)
|
| 143 |
# ChatCompletion 응답 텍스트 반환
|
| 144 |
+
return user_prompt, response.choices[0].message.content
|
| 145 |
except openai.OpenAIError as e:
|
| 146 |
# OpenAI 관련 에러 처리
|
| 147 |
return f"OpenAI API 오류: {str(e)}"
|
|
|
|
| 214 |
|
| 215 |
|
| 216 |
# 최종 결과물 생성
|
| 217 |
+
def generate_final_output(text_result, image_result, inputText):
|
| 218 |
name = text_result.get("Name", "Unknown name")
|
| 219 |
description = text_result.get("Description", "Unknown description")
|
| 220 |
magic = text_result.get("Magic", "Unknown name")
|
|
|
|
| 240 |
|
| 241 |
now = datetime.datetime.now()
|
| 242 |
date_str = now.strftime('%Y.%m.%d')
|
| 243 |
+
cert = date_str + '\n' + inputText
|
| 244 |
|
| 245 |
draw.multiline_text((523, 911), cert, fill="#B49F91", font=font_cert, anchor='ra', align='right')
|
| 246 |
|
|
|
|
| 252 |
# Gradio 인터페이스 설정
|
| 253 |
def generate_combined_response(user_prompt):
|
| 254 |
# GPT 응답 생성
|
| 255 |
+
inputText, gpt_response = generate_response(user_prompt)
|
| 256 |
# GPT 응답을 텍스트로 출력하고 Stable Diffusion으로 이미지 생성
|
| 257 |
gpt_jsonl = json.loads(gpt_response) # JSON은 쌍따옴표를 사용해야 함
|
| 258 |
print(gpt_response)
|
| 259 |
sd_prompt = jsonl_to_description(gpt_jsonl)
|
| 260 |
image = generate_image(sd_prompt)
|
| 261 |
+
final_image = generate_final_output(gpt_jsonl, image, inputText)
|
| 262 |
|
| 263 |
|
| 264 |
now_str = datetime.datetime.now().strftime("%Y%m%d_%H%M%S")
|