Spaces:
Running
on
Zero
Running
on
Zero
Update app.py
Browse files
app.py
CHANGED
@@ -22,6 +22,10 @@ import requests
|
|
22 |
from google import genai
|
23 |
from google.genai import types
|
24 |
|
|
|
|
|
|
|
|
|
25 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
26 |
|
27 |
def maybe_translate_to_english(text: str) -> str:
|
@@ -107,11 +111,10 @@ def generate_by_google_genai(text, file_name, model="gemini-2.0-flash-exp"):
|
|
107 |
return image_path, text_response
|
108 |
|
109 |
def change_text_in_image_two_times(original_image, instruction):
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
-
|
114 |
-
raise gr.Error("์ฒ๋ฆฌํ ์ด๋ฏธ์ง๊ฐ ์์ต๋๋ค. ๋จผ์ ์ด๋ฏธ์ง๋ฅผ ์์ฑํด์ฃผ์ธ์.")
|
115 |
results = []
|
116 |
for version_tag in ["(A)", "(B)"]:
|
117 |
mod_instruction = f"{instruction} {version_tag}"
|
@@ -123,7 +126,7 @@ def change_text_in_image_two_times(original_image, instruction):
|
|
123 |
print(f"[DEBUG] Saved image to temporary file: {original_path}")
|
124 |
else:
|
125 |
raise gr.Error(f"์์๋ PIL Image๊ฐ ์๋ {type(original_image)} ํ์
์ด ์ ๊ณต๋์์ต๋๋ค.")
|
126 |
-
|
127 |
image_path, text_response = generate_by_google_genai(
|
128 |
text=mod_instruction,
|
129 |
file_name=original_path
|
@@ -145,6 +148,7 @@ def change_text_in_image_two_times(original_image, instruction):
|
|
145 |
results.append(original_image)
|
146 |
return results
|
147 |
|
|
|
148 |
def gemini_text_rendering(image, rendering_text):
|
149 |
"""
|
150 |
์ฃผ์ด์ง ์ด๋ฏธ์ง์ ๋ํด Gemini API๋ฅผ ์ฌ์ฉํด ํ
์คํธ ๋ ๋๋ง์ ์ ์ฉ.
|
|
|
22 |
from google import genai
|
23 |
from google.genai import types
|
24 |
|
25 |
+
import numpy as np
|
26 |
+
|
27 |
+
|
28 |
+
|
29 |
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')
|
30 |
|
31 |
def maybe_translate_to_english(text: str) -> str:
|
|
|
111 |
return image_path, text_response
|
112 |
|
113 |
def change_text_in_image_two_times(original_image, instruction):
|
114 |
+
# ๋ง์ฝ ์ด๋ฏธ์ง๊ฐ numpy.ndarray ํ์
์ด๋ฉด PIL Image๋ก ๋ณํ
|
115 |
+
if isinstance(original_image, np.ndarray):
|
116 |
+
original_image = Image.fromarray(original_image)
|
117 |
+
|
|
|
118 |
results = []
|
119 |
for version_tag in ["(A)", "(B)"]:
|
120 |
mod_instruction = f"{instruction} {version_tag}"
|
|
|
126 |
print(f"[DEBUG] Saved image to temporary file: {original_path}")
|
127 |
else:
|
128 |
raise gr.Error(f"์์๋ PIL Image๊ฐ ์๋ {type(original_image)} ํ์
์ด ์ ๊ณต๋์์ต๋๋ค.")
|
129 |
+
# ์ดํ Gemini API ํธ์ถ ๋ก์ง ์ ์ง
|
130 |
image_path, text_response = generate_by_google_genai(
|
131 |
text=mod_instruction,
|
132 |
file_name=original_path
|
|
|
148 |
results.append(original_image)
|
149 |
return results
|
150 |
|
151 |
+
|
152 |
def gemini_text_rendering(image, rendering_text):
|
153 |
"""
|
154 |
์ฃผ์ด์ง ์ด๋ฏธ์ง์ ๋ํด Gemini API๋ฅผ ์ฌ์ฉํด ํ
์คํธ ๋ ๋๋ง์ ์ ์ฉ.
|