ginipick commited on
Commit
3407b2a
ยท
verified ยท
1 Parent(s): 5a60a35

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -6
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
- Gemini API๋ฅผ ๋‘ ๋ฒˆ ํ˜ธ์ถœํ•˜์—ฌ ํ…์ŠคํŠธ ์ˆ˜์ •๋œ ์ด๋ฏธ์ง€ 2๊ฐœ(๋ฒ„์ „ A, B)๋ฅผ ๋ฐ˜ํ™˜.
112
- """
113
- if original_image is None:
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
- print(f"[DEBUG] Google Gemini API์— ๋ณด๋‚ด๋Š” ์ง€์‹œ์‚ฌํ•ญ: {mod_instruction}")
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๋ฅผ ์‚ฌ์šฉํ•ด ํ…์ŠคํŠธ ๋ Œ๋”๋ง์„ ์ ์šฉ.