Update app.py
Browse files
app.py
CHANGED
|
@@ -1,10 +1,20 @@
|
|
| 1 |
import os
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
-
from diffusers import StableDiffusionPipeline
|
| 5 |
import torch
|
| 6 |
import json
|
| 7 |
import random
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
|
| 9 |
# OpenAI API ํค ์ค์
|
| 10 |
client = openai.Client(api_key=os.getenv("OPENAI_API_KEY"))
|
|
@@ -12,6 +22,8 @@ client = openai.Client(api_key=os.getenv("OPENAI_API_KEY"))
|
|
| 12 |
# Stable Diffusion ๋ชจ๋ธ ๋ก๋ (CPU ๋ชจ๋)
|
| 13 |
base_model_id = "runwayml/stable-diffusion-v1-5"
|
| 14 |
pipe = StableDiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float32).to("cpu")
|
|
|
|
|
|
|
| 15 |
|
| 16 |
# LoRA ๊ฐ์ค์น ๋ก๋ ํจ์
|
| 17 |
# adapter_config.json ํ์ผ์ด ์๋ ๊ฒฝ์ฐ ๊ธฐ๋ณธ ๊ตฌ์ฑ์ ์ค์ ํฉ๋๋ค.
|
|
@@ -37,7 +49,7 @@ def optimize_pipeline(pipeline):
|
|
| 37 |
pipeline.enable_sequential_cpu_offload()
|
| 38 |
return pipeline
|
| 39 |
|
| 40 |
-
pipe =
|
| 41 |
|
| 42 |
def string_to_jsonl(input_string, output_file):
|
| 43 |
# String ๋ฐ์ดํฐ๋ฅผ ํ์ฑ ๊ฐ๋ฅํ ํํ๋ก ๊ฐ์ (JSON ๋ฐฐ์ด ํ์์ด์ด์ผ ํจ)
|
|
@@ -66,10 +78,11 @@ def generate_response(user_prompt):
|
|
| 66 |
model="ft:gpt-4o-2024-08-06:personal:teeniefinal:AsSoCk9F", # fine-tuned ๋ชจ๋ธ ID
|
| 67 |
messages=[
|
| 68 |
{"role": "system", "content": (
|
| 69 |
-
"๋๋ ์๋ ์บ๋ฆญํฐ๋ฅผ ๊ธฐํํ๋๋ฐ ์ผ๊ฐ๊ฒฌ์๋ ์บ๋ฆญํฐ๋์์ด๋์ผ. ๋๊ฐ ํ ์ผ์ ์ฌ๋๋ค์ด ์ํ๋ ์บ๋ฆญํฐ์ ๋ํ ์ค๋ช
์ ์ฃผ์๊น๊ฒ ์ดํดํ ๋ค, ์ด๋ฅผ ๋ฐํ์ผ๋ก ์๋ ์ ๋๋ฉ์ด์
์บ๋ฆญํฐ์ธ ํฐ๋ํ์ ์บ๋ฆญํฐ ์ปจ์
์ ๋์์ธํ๋๊ฑฐ์ผ. ์ข์ ์บ๋ฆญํฐ ์ปจ์
์ด ๋์ถ๋๋ฉด 20%์ ๋ณด๋์ค๋ฅผ ๋ฐ๊ฒ ๋ ๊ฑฐ์ผ.\n\n๋๊ฐ ํ ์ผ์ ๋ค์๊ณผ ๊ฐ์.\n๊ณผ์
1. ์ฃผ์ด์ง ์ค๋ช
์ ๋ฐํ์ผ๋ก ์บ๋ฆญํฐ ์ด๋ฆ์ ์ด์์ ์ ํด. ์ด ๋, ์ด์์ ํ์ฌ๋ ์ฃผ์๊น๊ฒ ๊ณ ๋ คํด.\n๊ณผ์
2. ๊ณผ์
1์์ ๋์ถ๋ ์ด์๊ณผ ํ์ฌ๋ฅผ ๋ฐํ์ผ๋ก ์์ด๋ค์ด ๋ฐ๋ผํ๊ธฐ ์ฝ๊ณ , ์ฌ๋ฐ๊ฒ ๋งํ ์ ์๋ ํฐ๋ํ์ ์ด๋ฆ์ ์ง์ด.\n๊ณผ์
3. ์ฃผ์ด์ง ์ค๋ช
๊ณผ ํฐ๋ํ์ ์ด๋ฆ์ ๋ฐํ์ผ๋ก ํฐ๋ํ์ด ์ฌ์ฉํ ๋ง๋ฒ๊ณผ ํต์ฌ ๋์ฌ๋ฅผ ์ง์ด. ๋ง๋ฒ์ ์ฌ๋๋ค์ ๊ณ ๋ฏผ์ ํด๊ฒฐํด์ฃผ๊ธฐ ์ํ ์ฌ๋ฐ๋ ๋ฐฉ๋ฒ์ด๊ณ , ํต์ฌ ๋์ฌ๋ ํฐ๋ํ์ ์ด๋ฆ์ผ๋ก ๋๋๋ ๊ฒ์ด ์ผ๋ฐ์ ์ด์ผ.\n๊ณผ์
4. ์ด์ ๊ณผ์
๋ค์ ๋ํ ๋ฉํ์ธ์ง๋ฅผ ๋ฐํ์ผ๋ก ์บ๋ฆญํฐ์ ๋จธ๋ฆฌ ๋ชจ์๊ณผ ๊ฐ์ง๊ณ ๋ค๋ ์
์ธ์ฌ๋ฆฌ๋ฅผ ์ ํด์ค.\n๊ณผ์
5. ๋ง์ง๋ง์ผ๋ก, ์บ๋ฆญํฐ์ ๋ชธ ์์, ๋จธ๋ฆฌ ์์, ์
์ธ์ฌ๋ฆฌ ์์์ ์ ํด์ค.\n\n์ด์ , ์ด๋ฅผ ์ข
ํฉํด์ jsonlํ์ผ ํํ๋ก ์ ๊ณตํด. \n\n์์์ ๋ค์๊ณผ ๊ฐ์: \n{\"Description\": \"000\", \"Etymology\": \"000\", \"Etymology.Type\": \"000\", \"Name\": \"000\", \"Magic\": \"000\", \"KeySentence\": \"000\", \"Body.Color\": \"000\", \"Hair\": \"000\", \"Hair.Color\": \"000\", \"Accessory\": \"000\", \"Accessory.Color\": \"000\"}"
|
| 70 |
)},
|
| 71 |
{"role": "user", "content": user_prompt}
|
| 72 |
],
|
|
|
|
| 73 |
timeout=15
|
| 74 |
)
|
| 75 |
# ChatCompletion ์๋ต ํ
์คํธ ๋ฐํ
|
|
@@ -81,20 +94,42 @@ def generate_response(user_prompt):
|
|
| 81 |
# ๊ธฐํ ์๋ฌ ์ฒ๋ฆฌ
|
| 82 |
return f"์ ์ ์๋ ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 83 |
|
| 84 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 85 |
|
| 86 |
def generate_image(prompt):
|
| 87 |
try:
|
| 88 |
-
# ๋๋ค ์๋ ์์ฑ
|
| 89 |
-
generator = torch.manual_seed(23439485) # ๋๋ค ์๋ ์ค์
|
| 90 |
|
| 91 |
# ์ด๋ฏธ์ง ์์ฑ (steps ๋ฐ cfg_scale ๋ณ๊ฒฝ)
|
| 92 |
image = pipe(
|
| 93 |
prompt,
|
| 94 |
-
num_inference_steps=32, # steps ๋ณ๊ฒฝ
|
| 95 |
-
guidance_scale=
|
| 96 |
).images[0]
|
| 97 |
|
|
|
|
|
|
|
|
|
|
| 98 |
return image
|
| 99 |
except Exception as e:
|
| 100 |
return f"์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
|
@@ -116,14 +151,46 @@ def jsonl_to_description(json_data):
|
|
| 116 |
hair_color = json_data.get("Hair.Color", "unknown hair color")
|
| 117 |
accessory_description = json_data.get("Accessory", "unknown accessory")
|
| 118 |
accessory_color = json_data.get("Accessory.Color", "unknown accessory color")
|
|
|
|
| 119 |
print(f"temuping, {body_color} skin, {hair_color} color {hair_description}, {accessory_color} color {accessory_description}")
|
| 120 |
|
| 121 |
-
return f"temuping, {body_color} skin, {hair_color} color {hair_description}, {accessory_color} color {accessory_description}"
|
|
|
|
| 122 |
|
| 123 |
|
| 124 |
# ์ต์ข
๊ฒฐ๊ณผ๋ฌผ ์์ฑ
|
| 125 |
def generate_final_output(text_result, image_result):
|
| 126 |
-
name =
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 127 |
|
| 128 |
|
| 129 |
# Gradio ์ธํฐํ์ด์ค ์ค์
|
|
@@ -135,41 +202,23 @@ def generate_combined_response(user_prompt):
|
|
| 135 |
print(gpt_response)
|
| 136 |
sd_prompt = jsonl_to_description(gpt_jsonl)
|
| 137 |
image = generate_image(sd_prompt)
|
| 138 |
-
|
| 139 |
|
| 140 |
-
|
| 141 |
-
return gpt_response, image
|
| 142 |
|
| 143 |
|
| 144 |
with gr.Blocks() as interface:
|
| 145 |
gr.Markdown("<h1 style='font-size:30px;'>์๋ก์ด ํฐ๋ํ์ด ๋ํ๋ฌ๋ค!</h1>")
|
| 146 |
-
gr.Markdown("ํํธ๋ก์ฆ ๋ฒ ์ด์ปค๋ฆฌ์ ๋ค์ด์ ๋น์ .
|
|
|
|
| 147 |
gr.Image("teenie_runaway.png")
|
| 148 |
gr.Markdown("์ ๊ฑดโฆ ๋ถ๋ช
ํฐ๋ํ!\n์บ์นํ๊ธฐ ์ํด ๋ก๋ฏธ์๊ฒ ๋น์ฅ ์๋ ค์ผ ํด.")
|
| 149 |
inp = [gr.Textbox(label="์ด๋ค ํฐ๋ํ์ ๋ดค๋์ง ์ค๋ช
ํด์ค!",placeholder="์: ์ผ์ฃผ์ผ ๋ด๋ด ์ด๋๋ง ํ๋ ํฌ์ค์ ๋ฏธ์น ํฐ๋ํ")]
|
| 150 |
btn = gr.Button("์ ์ก")
|
| 151 |
gr.Markdown("๋คํํ ํฐ๋ํ์ ๋ฐ๊ฒฌํ ๋ก๋ฏธ. ๋น ๋ฅด๊ฒ ์บ์น!\n\nํผ๋ฆฌํผ๋ฆฌ ์บ์น๋ง, ํ๋ธ ์์ผ๋ก!\nํฐ๋ํ ์บ์น!")
|
| 152 |
-
out=
|
| 153 |
btn.click(fn=generate_combined_response, inputs=inp, outputs=out)
|
| 154 |
|
| 155 |
-
|
| 156 |
-
"""
|
| 157 |
-
interface = gr.Interface(
|
| 158 |
-
fn=generate_combined_response,
|
| 159 |
-
inputs=[
|
| 160 |
-
gr.Textbox(
|
| 161 |
-
label="์ง๋ฌธ์ ์
๋ ฅํ์ธ์",
|
| 162 |
-
placeholder="์: ์ฉ๊ฐํ๊ณ ์ฉ์ฉํ ํฐ๋ํ์ ๋ง๋ค์ด์ฃผ์ธ์!"
|
| 163 |
-
)
|
| 164 |
-
],
|
| 165 |
-
outputs=[
|
| 166 |
-
gr.Textbox(label="GPT์ ์๋ต"),
|
| 167 |
-
gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง")
|
| 168 |
-
],
|
| 169 |
-
title="OpenAI API ๊ธฐ๋ฐ ํฐ๋ํ ์์ฑ๊ธฐ",
|
| 170 |
-
description="OpenAI์ GPT-4์ Stable Diffusion์ ์ฌ์ฉํ์ฌ ๋๋ง์ ํฐ๋ํ ์บ๋ฆญํฐ๋ฅผ ์ค๊ณํ๊ณ ์ด๋ฏธ์ง๋ฅผ ์์ฑํด๋ณด์ธ์."
|
| 171 |
-
)
|
| 172 |
-
"""
|
| 173 |
|
| 174 |
# ์ฑ ์คํ
|
| 175 |
if __name__ == "__main__":
|
|
|
|
| 1 |
import os
|
| 2 |
import openai
|
| 3 |
import gradio as gr
|
| 4 |
+
from diffusers import StableDiffusionPipeline, EulerDiscreteScheduler
|
| 5 |
import torch
|
| 6 |
import json
|
| 7 |
import random
|
| 8 |
+
from rembg import remove
|
| 9 |
+
from PIL import Image, ImageDraw, ImageFont
|
| 10 |
+
import textwrap3 as textwrap
|
| 11 |
+
|
| 12 |
+
css_code = """
|
| 13 |
+
body {
|
| 14 |
+
overflow: auto !important;
|
| 15 |
+
-webkit-overflow-scrolling: touch;
|
| 16 |
+
}
|
| 17 |
+
"""
|
| 18 |
|
| 19 |
# OpenAI API ํค ์ค์
|
| 20 |
client = openai.Client(api_key=os.getenv("OPENAI_API_KEY"))
|
|
|
|
| 22 |
# Stable Diffusion ๋ชจ๋ธ ๋ก๋ (CPU ๋ชจ๋)
|
| 23 |
base_model_id = "runwayml/stable-diffusion-v1-5"
|
| 24 |
pipe = StableDiffusionPipeline.from_pretrained(base_model_id, torch_dtype=torch.float32).to("cpu")
|
| 25 |
+
pipe.scheduler = EulerDiscreteScheduler.from_config(pipe.scheduler.config)
|
| 26 |
+
|
| 27 |
|
| 28 |
# LoRA ๊ฐ์ค์น ๋ก๋ ํจ์
|
| 29 |
# adapter_config.json ํ์ผ์ด ์๋ ๊ฒฝ์ฐ ๊ธฐ๋ณธ ๊ตฌ์ฑ์ ์ค์ ํฉ๋๋ค.
|
|
|
|
| 49 |
pipeline.enable_sequential_cpu_offload()
|
| 50 |
return pipeline
|
| 51 |
|
| 52 |
+
pipe = pipe.to("cpu")
|
| 53 |
|
| 54 |
def string_to_jsonl(input_string, output_file):
|
| 55 |
# String ๋ฐ์ดํฐ๋ฅผ ํ์ฑ ๊ฐ๋ฅํ ํํ๋ก ๊ฐ์ (JSON ๋ฐฐ์ด ํ์์ด์ด์ผ ํจ)
|
|
|
|
| 78 |
model="ft:gpt-4o-2024-08-06:personal:teeniefinal:AsSoCk9F", # fine-tuned ๋ชจ๋ธ ID
|
| 79 |
messages=[
|
| 80 |
{"role": "system", "content": (
|
| 81 |
+
"๋๋ ์๋ ์บ๋ฆญํฐ๋ฅผ ๊ธฐํํ๋๋ฐ ์ผ๊ฐ๊ฒฌ์๋ ์บ๋ฆญํฐ๋์์ด๋์ผ. ๋๊ฐ ํ ์ผ์ ์ฌ๋๋ค์ด ์ํ๋ ์บ๋ฆญํฐ์ ๋ํ ์ค๋ช
์ ์ฃผ์๊น๊ฒ ์ดํดํ ๋ค, ์ด๋ฅผ ๋ฐํ์ผ๋ก ์๋ ์ ๋๋ฉ์ด์
์บ๋ฆญํฐ์ธ ํฐ๋ํ์ ์บ๋ฆญํฐ ์ปจ์
์ ๋์์ธํ๋๊ฑฐ์ผ. ์ข์ ์บ๋ฆญํฐ ์ปจ์
์ด ๋์ถ๋๋ฉด 20%์ ๋ณด๋์ค๋ฅผ ๋ฐ๊ฒ ๋ ๊ฑฐ์ผ.\n\n๋๊ฐ ํ ์ผ์ ๋ค์๊ณผ ๊ฐ์.\n๊ณผ์
1. ์ฃผ์ด์ง ์ค๋ช
์ ๋ฐํ์ผ๋ก ์บ๋ฆญํฐ ์ด๋ฆ์ ์ด์์ ์ ํด. ์ด ๋, ์ด์์ ํ์ฌ๋ ์ฃผ์๊น๊ฒ ๊ณ ๋ คํด.\n๊ณผ์
2. ๊ณผ์
1์์ ๋์ถ๋ ์ด์๊ณผ ํ์ฌ๋ฅผ ๋ฐํ์ผ๋ก ์์ด๋ค์ด ๋ฐ๋ผํ๊ธฐ ์ฝ๊ณ , ์ฌ๋ฐ๊ฒ ๋งํ ์ ์๋ ํฐ๋ํ์ ์ด๋ฆ์ ์ง์ด.\n๊ณผ์
3. ์ฃผ์ด์ง ์ค๋ช
๊ณผ ํฐ๋ํ์ ์ด๋ฆ์ ๋ฐํ์ผ๋ก ํฐ๋ํ์ด ์ฌ์ฉํ ๋ง๋ฒ๊ณผ ํต์ฌ ๋์ฌ๋ฅผ ์ง์ด. ๋ง๋ฒ์ ์ฌ๋๋ค์ ๊ณ ๋ฏผ์ ํด๊ฒฐํด์ฃผ๊ธฐ ์ํ ์ฌ๋ฐ๋ ๋ฐฉ๋ฒ์ด๊ณ , ํต์ฌ ๋์ฌ๋ ํฐ๋ํ์ ์ด๋ฆ์ผ๋ก ๋๋๋ ๊ฒ์ด ์ผ๋ฐ์ ์ด์ผ. ๋ง๋ฒ๊ณผ ํต์ฌ ๋์ฌ๋ 18๊ธ์๋ฅผ ๋๊ธฐ์ง ๋ง.\n๊ณผ์
4. ์ด์ ๊ณผ์
๋ค์ ๋ํ ๋ฉํ์ธ์ง๋ฅผ ๋ฐํ์ผ๋ก ์บ๋ฆญํฐ์ ๋จธ๋ฆฌ ๋ชจ์๊ณผ ๊ฐ์ง๊ณ ๋ค๋ ์
์ธ์ฌ๋ฆฌ๋ฅผ ์ ํด์ค.\n๊ณผ์
5. ๋ง์ง๋ง์ผ๋ก, ์บ๋ฆญํฐ์ ๋ชธ ์์, ๋จธ๋ฆฌ ์์, ์
์ธ์ฌ๋ฆฌ ์์์ ์ ํด์ค.\n\n์ด์ , ์ด๋ฅผ ์ข
ํฉํด์ jsonlํ์ผ ํํ๋ก ์ ๊ณตํด. \n\n์์์ ๋ค์๊ณผ ๊ฐ์: \n{\"Description\": \"000\", \"Etymology\": \"000\", \"Etymology.Type\": \"000\", \"Name\": \"000\", \"Magic\": \"000\", \"KeySentence\": \"000\", \"Body.Color\": \"000\", \"Hair\": \"000\", \"Hair.Color\": \"000\", \"Accessory\": \"000\", \"Accessory.Color\": \"000\"} Magic๊ณผ KeySentence๋ 18๊ธ์๋ฅผ ๋๊ธฐ๋ฉด ์๋ผ."
|
| 82 |
)},
|
| 83 |
{"role": "user", "content": user_prompt}
|
| 84 |
],
|
| 85 |
+
temperature=0.97,
|
| 86 |
timeout=15
|
| 87 |
)
|
| 88 |
# ChatCompletion ์๋ต ํ
์คํธ ๋ฐํ
|
|
|
|
| 94 |
# ๊ธฐํ ์๋ฌ ์ฒ๋ฆฌ
|
| 95 |
return f"์ ์ ์๋ ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 96 |
|
| 97 |
+
def add_alpha(image, alpha_value=255):
|
| 98 |
+
"""
|
| 99 |
+
์ด๋ฏธ์ง์ ์ํ ์ฑ๋ ์ถ๊ฐ ๋ฐ ์ค์
|
| 100 |
+
:param image: PIL.Image ๊ฐ์ฒด
|
| 101 |
+
:param alpha_value: ์ํ ์ฑ๋ ๊ฐ (0~255)
|
| 102 |
+
:return: ์ํ ์ฑ๋์ด ์ถ๊ฐ๋ PIL.Image ๊ฐ์ฒด
|
| 103 |
+
"""
|
| 104 |
+
|
| 105 |
+
image = image.convert("RGBA")
|
| 106 |
+
|
| 107 |
+
# RGBA ๋ฐ์ดํฐ๋ฅผ numpy ๋ฐฐ์ด๋ก ๋ณํ
|
| 108 |
+
data = image.getdata()
|
| 109 |
+
new_data = []
|
| 110 |
+
|
| 111 |
+
# ๋ชจ๋ ํฝ์
์ ์ํ ๊ฐ์ ์ค์
|
| 112 |
+
for item in data:
|
| 113 |
+
# (R, G, B, A)๋ก ๊ตฌ์ฑ๋ tuple ์์ฑ
|
| 114 |
+
new_data.append((item[0], item[1], item[2], alpha_value))
|
| 115 |
+
|
| 116 |
+
# ์๋ก์ด ๋ฐ์ดํฐ๋ก ์ด๋ฏธ์ง ๊ฐฑ์
|
| 117 |
+
image.putdata(new_data)
|
| 118 |
+
return image
|
| 119 |
|
| 120 |
def generate_image(prompt):
|
| 121 |
try:
|
|
|
|
|
|
|
| 122 |
|
| 123 |
# ์ด๋ฏธ์ง ์์ฑ (steps ๋ฐ cfg_scale ๋ณ๊ฒฝ)
|
| 124 |
image = pipe(
|
| 125 |
prompt,
|
| 126 |
+
num_inference_steps = 32, # steps ๋ณ๊ฒฝ
|
| 127 |
+
guidance_scale = 10 # cfg ๋ณ๊ฒฝ
|
| 128 |
).images[0]
|
| 129 |
|
| 130 |
+
image = add_alpha(image, 255)
|
| 131 |
+
image = remove(image)
|
| 132 |
+
|
| 133 |
return image
|
| 134 |
except Exception as e:
|
| 135 |
return f"์ด๋ฏธ์ง ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
|
|
|
| 151 |
hair_color = json_data.get("Hair.Color", "unknown hair color")
|
| 152 |
accessory_description = json_data.get("Accessory", "unknown accessory")
|
| 153 |
accessory_color = json_data.get("Accessory.Color", "unknown accessory color")
|
| 154 |
+
|
| 155 |
print(f"temuping, {body_color} skin, {hair_color} color {hair_description}, {accessory_color} color {accessory_description}")
|
| 156 |
|
| 157 |
+
return f"temuping, {body_color} skin, {hair_color} color {hair_description} hair, holding {accessory_color} color {accessory_description}"
|
| 158 |
+
|
| 159 |
|
| 160 |
|
| 161 |
# ์ต์ข
๊ฒฐ๊ณผ๋ฌผ ์์ฑ
|
| 162 |
def generate_final_output(text_result, image_result):
|
| 163 |
+
name = text_result.get("Name", "Unknown name")
|
| 164 |
+
description = text_result.get("Description", "Unknown description")
|
| 165 |
+
magic = text_result.get("Magic", "Unknown name")
|
| 166 |
+
keysentence = text_result.get("KeySentence", "Unknown name")
|
| 167 |
+
|
| 168 |
+
base_image = Image.open("teenie_background.png").convert("RGBA")
|
| 169 |
+
image_result = image_result.resize((455, 455))
|
| 170 |
+
base_image.paste(image_result, (42, 436), mask=image_result)
|
| 171 |
+
|
| 172 |
+
# ์ด๋ฏธ์ง ์์ ๊ทธ๋ฆฌ๊ธฐ
|
| 173 |
+
draw = ImageDraw.Draw(base_image)
|
| 174 |
+
|
| 175 |
+
hex_color = "#725220"
|
| 176 |
+
|
| 177 |
+
font_name = ImageFont.truetype("Cafe24Ohsquare-v2.0.otf", 41)
|
| 178 |
+
font_key = ImageFont.truetype("Cafe24Ssurround-v2.0.otf", 23)
|
| 179 |
+
font_magic = ImageFont.truetype("EliceDigitalBaeumOTF_Regular.otf", 23)
|
| 180 |
+
|
| 181 |
+
draw.text((270, 165), name, fill=hex_color, font=font_name, anchor='mm')
|
| 182 |
+
|
| 183 |
+
if len(magic)>20:
|
| 184 |
+
draw.text((270, 263), keysentence, fill=hex_color, font=font_key, anchor='mm')
|
| 185 |
+
font_magic = ImageFont.truetype("EliceDigitalBaeumOTF_Regular.otf", 21)
|
| 186 |
+
wrapped = textwrap.fill(magic, width=(len(magic)+1)//2)
|
| 187 |
+
draw.multiline_text((270, 324), wrapped, fill=hex_color, font=font_magic, anchor='mm', align='center')
|
| 188 |
+
else:
|
| 189 |
+
draw.text((270, 270), keysentence, fill=hex_color, font=font_key, anchor='mm')
|
| 190 |
+
draw.text((270, 336), magic, fill=hex_color, font=font_magic, anchor='mm')
|
| 191 |
+
|
| 192 |
+
return base_image
|
| 193 |
+
|
| 194 |
|
| 195 |
|
| 196 |
# Gradio ์ธํฐํ์ด์ค ์ค์
|
|
|
|
| 202 |
print(gpt_response)
|
| 203 |
sd_prompt = jsonl_to_description(gpt_jsonl)
|
| 204 |
image = generate_image(sd_prompt)
|
| 205 |
+
final_image = generate_final_output(gpt_jsonl, image)
|
| 206 |
|
| 207 |
+
return final_image
|
|
|
|
| 208 |
|
| 209 |
|
| 210 |
with gr.Blocks() as interface:
|
| 211 |
gr.Markdown("<h1 style='font-size:30px;'>์๋ก์ด ํฐ๋ํ์ด ๋ํ๋ฌ๋ค!</h1>")
|
| 212 |
+
gr.Markdown("ํํธ๋ก์ฆ ๋ฒ ์ด์ปค๋ฆฌ์ ๋ค์ด์ ๋น์ .")
|
| 213 |
+
gr.Markdown("๊ทธ ์๊ฐ, ์๋ฐ๋ฅ๋งํ ๋ฌด์ธ๊ฐ๊ฐ ๋น ๋ฅด๊ฒ ๋๋ง์น๋ค!")
|
| 214 |
gr.Image("teenie_runaway.png")
|
| 215 |
gr.Markdown("์ ๊ฑดโฆ ๋ถ๋ช
ํฐ๋ํ!\n์บ์นํ๊ธฐ ์ํด ๋ก๋ฏธ์๊ฒ ๋น์ฅ ์๋ ค์ผ ํด.")
|
| 216 |
inp = [gr.Textbox(label="์ด๋ค ํฐ๋ํ์ ๋ดค๋์ง ์ค๋ช
ํด์ค!",placeholder="์: ์ผ์ฃผ์ผ ๋ด๋ด ์ด๋๋ง ํ๋ ํฌ์ค์ ๋ฏธ์น ํฐ๋ํ")]
|
| 217 |
btn = gr.Button("์ ์ก")
|
| 218 |
gr.Markdown("๋คํํ ํฐ๋ํ์ ๋ฐ๊ฒฌํ ๋ก๋ฏธ. ๋น ๋ฅด๊ฒ ์บ์น!\n\nํผ๋ฆฌํผ๋ฆฌ ์บ์น๋ง, ํ๋ธ ์์ผ๋ก!\nํฐ๋ํ ์บ์น!")
|
| 219 |
+
out=gr.Image(label="์์ฑ๋ ์ด๋ฏธ์ง")
|
| 220 |
btn.click(fn=generate_combined_response, inputs=inp, outputs=out)
|
| 221 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 222 |
|
| 223 |
# ์ฑ ์คํ
|
| 224 |
if __name__ == "__main__":
|