Update app.py
Browse files
app.py
CHANGED
|
@@ -22,12 +22,16 @@ from transformers import pipeline
|
|
| 22 |
from gradio_client import Client
|
| 23 |
from gradio_client.utils import encode_file_to_base64
|
| 24 |
import tempfile
|
| 25 |
-
|
| 26 |
from PIL import Image as PILImage
|
| 27 |
import base64
|
| 28 |
import io
|
| 29 |
from transformers import pipeline as translation_pipeline
|
| 30 |
from gradio_client.utils import encode_file_to_base64
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 31 |
|
| 32 |
translator = translation_pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
| 33 |
|
|
@@ -415,45 +419,59 @@ def process_image(image):
|
|
| 415 |
|
| 416 |
img = img.resize((720, 480), PILImage.LANCZOS)
|
| 417 |
|
| 418 |
-
# ์ด๋ฏธ์ง๋ฅผ
|
| 419 |
-
|
| 420 |
-
|
| 421 |
-
|
| 422 |
-
|
| 423 |
-
|
| 424 |
-
img_json = json.dumps({"image": img_str})
|
| 425 |
-
|
| 426 |
-
return img_json, None
|
| 427 |
except Exception as e:
|
|
|
|
| 428 |
return None, f"์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 429 |
|
| 430 |
def image_to_video(image, prompt, seed, high_resolution, frame_interpolation):
|
|
|
|
|
|
|
|
|
|
|
|
|
| 431 |
if not prompt:
|
| 432 |
return None, None, None, None, "ํ๋กฌํํธ๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์."
|
| 433 |
|
| 434 |
# ํ๋กฌํํธ๋ฅผ ์์ด๋ก ๋ฒ์ญ
|
| 435 |
prompt = translate_to_english(prompt)
|
|
|
|
| 436 |
|
| 437 |
-
|
| 438 |
if error:
|
|
|
|
| 439 |
return None, None, None, None, error
|
| 440 |
|
| 441 |
client = Client("http://hugpu.ai:7916/", auth=("gini", "pick"))
|
| 442 |
|
| 443 |
try:
|
|
|
|
|
|
|
|
|
|
|
|
|
| 444 |
result = client.predict(
|
| 445 |
prompt,
|
| 446 |
-
|
| 447 |
seed,
|
| 448 |
high_resolution,
|
| 449 |
frame_interpolation,
|
| 450 |
api_name="/lambda_2"
|
| 451 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 452 |
|
| 453 |
return result[0]['video'], result[1], result[2], result[3], prompt
|
| 454 |
except Exception as e:
|
| 455 |
-
|
| 456 |
-
|
|
|
|
|
|
|
| 457 |
|
| 458 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css="""
|
| 459 |
footer {
|
|
@@ -729,7 +747,9 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css="""
|
|
| 729 |
outputs=[prompt_input]
|
| 730 |
)
|
| 731 |
|
|
|
|
| 732 |
def handle_generation(image, prompt, seed, high_resolution, frame_interpolation, use_enhanced):
|
|
|
|
| 733 |
if use_enhanced:
|
| 734 |
prompt = enhance_prompt(prompt)
|
| 735 |
|
|
@@ -739,12 +759,14 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css="""
|
|
| 739 |
try:
|
| 740 |
video, video_file, gif_file, used_seed, message = image_to_video(image, prompt, seed, high_resolution, frame_interpolation)
|
| 741 |
if video is None:
|
|
|
|
| 742 |
return [None, None, None, None, None, gr.update(visible=True, value=message)]
|
| 743 |
else:
|
|
|
|
| 744 |
return [video, video_file, gif_file, used_seed, message, gr.update(visible=False)]
|
| 745 |
except Exception as e:
|
| 746 |
error_message = f"๋น๋์ค ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 747 |
-
|
| 748 |
return [None, None, None, None, None, gr.update(visible=True, value=error_message)]
|
| 749 |
|
| 750 |
|
|
|
|
| 22 |
from gradio_client import Client
|
| 23 |
from gradio_client.utils import encode_file_to_base64
|
| 24 |
import tempfile
|
|
|
|
| 25 |
from PIL import Image as PILImage
|
| 26 |
import base64
|
| 27 |
import io
|
| 28 |
from transformers import pipeline as translation_pipeline
|
| 29 |
from gradio_client.utils import encode_file_to_base64
|
| 30 |
+
import logging
|
| 31 |
+
from gradio_client.utils import File
|
| 32 |
+
|
| 33 |
+
logging.basicConfig(level=logging.INFO)
|
| 34 |
+
logger = logging.getLogger(__name__)
|
| 35 |
|
| 36 |
translator = translation_pipeline("translation", model="Helsinki-NLP/opus-mt-ko-en")
|
| 37 |
|
|
|
|
| 419 |
|
| 420 |
img = img.resize((720, 480), PILImage.LANCZOS)
|
| 421 |
|
| 422 |
+
# ์ด๋ฏธ์ง๋ฅผ ์์ ํ์ผ๋ก ์ ์ฅ
|
| 423 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".png") as temp_file:
|
| 424 |
+
img.save(temp_file, format="PNG")
|
| 425 |
+
temp_file_path = temp_file.name
|
| 426 |
+
|
| 427 |
+
return temp_file_path, None
|
|
|
|
|
|
|
|
|
|
| 428 |
except Exception as e:
|
| 429 |
+
logger.error(f"์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
| 430 |
return None, f"์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 431 |
|
| 432 |
def image_to_video(image, prompt, seed, high_resolution, frame_interpolation):
|
| 433 |
+
logger.info(f"์
๋ ฅ ํ๋กฌํํธ: {prompt}")
|
| 434 |
+
logger.info(f"์ด๋ฏธ์ง ํ์
: {type(image)}")
|
| 435 |
+
logger.info(f"Seed: {seed}, ๊ณ ํด์๋: {high_resolution}, ํ๋ ์ ๋ณด๊ฐ: {frame_interpolation}")
|
| 436 |
+
|
| 437 |
if not prompt:
|
| 438 |
return None, None, None, None, "ํ๋กฌํํธ๋ฅผ ์
๋ ฅํด ์ฃผ์ธ์."
|
| 439 |
|
| 440 |
# ํ๋กฌํํธ๋ฅผ ์์ด๋ก ๋ฒ์ญ
|
| 441 |
prompt = translate_to_english(prompt)
|
| 442 |
+
logger.info(f"๋ฒ์ญ๋ ํ๋กฌํํธ: {prompt}")
|
| 443 |
|
| 444 |
+
image_path, error = process_image(image)
|
| 445 |
if error:
|
| 446 |
+
logger.error(f"์ด๋ฏธ์ง ์ฒ๋ฆฌ ์ค๋ฅ: {error}")
|
| 447 |
return None, None, None, None, error
|
| 448 |
|
| 449 |
client = Client("http://hugpu.ai:7916/", auth=("gini", "pick"))
|
| 450 |
|
| 451 |
try:
|
| 452 |
+
# File ๊ฐ์ฒด ์์ฑ
|
| 453 |
+
image_file = File(image_path)
|
| 454 |
+
|
| 455 |
+
logger.info("API ํธ์ถ ์์")
|
| 456 |
result = client.predict(
|
| 457 |
prompt,
|
| 458 |
+
image_file,
|
| 459 |
seed,
|
| 460 |
high_resolution,
|
| 461 |
frame_interpolation,
|
| 462 |
api_name="/lambda_2"
|
| 463 |
)
|
| 464 |
+
logger.info("API ํธ์ถ ์๋ฃ")
|
| 465 |
+
|
| 466 |
+
# ์์ ํ์ผ ์ญ์
|
| 467 |
+
os.remove(image_path)
|
| 468 |
|
| 469 |
return result[0]['video'], result[1], result[2], result[3], prompt
|
| 470 |
except Exception as e:
|
| 471 |
+
logger.error(f"API ํธ์ถ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}")
|
| 472 |
+
# ์์ ํ์ผ ์ญ์
|
| 473 |
+
os.remove(image_path)
|
| 474 |
+
return None, None, None, None, f"๋น๋์ค ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}
|
| 475 |
|
| 476 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css="""
|
| 477 |
footer {
|
|
|
|
| 747 |
outputs=[prompt_input]
|
| 748 |
)
|
| 749 |
|
| 750 |
+
|
| 751 |
def handle_generation(image, prompt, seed, high_resolution, frame_interpolation, use_enhanced):
|
| 752 |
+
logger.info("handle_generation ํจ์ ์์")
|
| 753 |
if use_enhanced:
|
| 754 |
prompt = enhance_prompt(prompt)
|
| 755 |
|
|
|
|
| 759 |
try:
|
| 760 |
video, video_file, gif_file, used_seed, message = image_to_video(image, prompt, seed, high_resolution, frame_interpolation)
|
| 761 |
if video is None:
|
| 762 |
+
logger.warning(f"๋น๋์ค ์์ฑ ์คํจ: {message}")
|
| 763 |
return [None, None, None, None, None, gr.update(visible=True, value=message)]
|
| 764 |
else:
|
| 765 |
+
logger.info("๋น๋์ค ์์ฑ ์ฑ๊ณต")
|
| 766 |
return [video, video_file, gif_file, used_seed, message, gr.update(visible=False)]
|
| 767 |
except Exception as e:
|
| 768 |
error_message = f"๋น๋์ค ์์ฑ ์ค ์ค๋ฅ ๋ฐ์: {str(e)}"
|
| 769 |
+
logger.error(error_message)
|
| 770 |
return [None, None, None, None, None, gr.update(visible=True, value=error_message)]
|
| 771 |
|
| 772 |
|