Update app.py
Browse files
app.py
CHANGED
@@ -7,6 +7,8 @@ from datetime import datetime
|
|
7 |
import tempfile
|
8 |
import numpy as np
|
9 |
from PIL import Image
|
|
|
|
|
10 |
# 로깅 설정
|
11 |
logging.basicConfig(level=logging.INFO)
|
12 |
|
@@ -28,8 +30,6 @@ def save_to_gallery(video_path, prompt):
|
|
28 |
# 비디오 파일 복사
|
29 |
shutil.copy2(video_path, new_video_path)
|
30 |
|
31 |
-
|
32 |
-
|
33 |
# 갤러리 정보 저장
|
34 |
gallery_info = {
|
35 |
"video": new_video_path,
|
@@ -50,6 +50,7 @@ def save_to_gallery(video_path, prompt):
|
|
50 |
|
51 |
return new_video_path
|
52 |
|
|
|
53 |
def load_gallery():
|
54 |
if os.path.exists(GALLERY_JSON):
|
55 |
with open(GALLERY_JSON, "r") as f:
|
@@ -57,9 +58,6 @@ def load_gallery():
|
|
57 |
return [(item["video"], item["prompt"]) for item in reversed(gallery)]
|
58 |
return []
|
59 |
|
60 |
-
|
61 |
-
|
62 |
-
|
63 |
def respond(image, prompt, steps, cfg_scale, eta, fs, seed, video_length):
|
64 |
logging.info(f"Received prompt: {prompt}, steps: {steps}, cfg_scale: {cfg_scale}, "
|
65 |
f"eta: {eta}, fs: {fs}, seed: {seed}, video_length: {video_length}")
|
@@ -67,16 +65,16 @@ def respond(image, prompt, steps, cfg_scale, eta, fs, seed, video_length):
|
|
67 |
try:
|
68 |
# 이미지 처리
|
69 |
if isinstance(image, str): # 파일 경로인 경우
|
70 |
-
|
71 |
else: # numpy array인 경우
|
72 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_file:
|
73 |
img = Image.fromarray(image.astype('uint8'), 'RGB')
|
74 |
img.save(temp_file.name)
|
75 |
-
|
76 |
|
77 |
# 비디오 생성 요청
|
78 |
result = api_client.predict(
|
79 |
-
|
80 |
prompt,
|
81 |
steps,
|
82 |
cfg_scale,
|
@@ -90,7 +88,7 @@ def respond(image, prompt, steps, cfg_scale, eta, fs, seed, video_length):
|
|
90 |
|
91 |
# 임시 파일 삭제 (numpy array였을 경우에만)
|
92 |
if not isinstance(image, str):
|
93 |
-
os.unlink(
|
94 |
|
95 |
# 결과 확인 및 처리
|
96 |
if isinstance(result, str) and result.endswith('.mp4'):
|
@@ -121,7 +119,7 @@ def use_prompt(prompt):
|
|
121 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
122 |
with gr.Tab("Generate"):
|
123 |
with gr.Row():
|
124 |
-
input_image = gr.Image(label="Upload an image", type="
|
125 |
input_text = gr.Textbox(label="Enter your prompt for video generation")
|
126 |
output_video = gr.Video(label="Generated Video")
|
127 |
|
|
|
7 |
import tempfile
|
8 |
import numpy as np
|
9 |
from PIL import Image
|
10 |
+
import shutil
|
11 |
+
from gradio_client import Client, File
|
12 |
# 로깅 설정
|
13 |
logging.basicConfig(level=logging.INFO)
|
14 |
|
|
|
30 |
# 비디오 파일 복사
|
31 |
shutil.copy2(video_path, new_video_path)
|
32 |
|
|
|
|
|
33 |
# 갤러리 정보 저장
|
34 |
gallery_info = {
|
35 |
"video": new_video_path,
|
|
|
50 |
|
51 |
return new_video_path
|
52 |
|
53 |
+
|
54 |
def load_gallery():
|
55 |
if os.path.exists(GALLERY_JSON):
|
56 |
with open(GALLERY_JSON, "r") as f:
|
|
|
58 |
return [(item["video"], item["prompt"]) for item in reversed(gallery)]
|
59 |
return []
|
60 |
|
|
|
|
|
|
|
61 |
def respond(image, prompt, steps, cfg_scale, eta, fs, seed, video_length):
|
62 |
logging.info(f"Received prompt: {prompt}, steps: {steps}, cfg_scale: {cfg_scale}, "
|
63 |
f"eta: {eta}, fs: {fs}, seed: {seed}, video_length: {video_length}")
|
|
|
65 |
try:
|
66 |
# 이미지 처리
|
67 |
if isinstance(image, str): # 파일 경로인 경우
|
68 |
+
image_file = File(image)
|
69 |
else: # numpy array인 경우
|
70 |
with tempfile.NamedTemporaryFile(suffix=".png", delete=False) as temp_file:
|
71 |
img = Image.fromarray(image.astype('uint8'), 'RGB')
|
72 |
img.save(temp_file.name)
|
73 |
+
image_file = File(temp_file.name)
|
74 |
|
75 |
# 비디오 생성 요청
|
76 |
result = api_client.predict(
|
77 |
+
image_file,
|
78 |
prompt,
|
79 |
steps,
|
80 |
cfg_scale,
|
|
|
88 |
|
89 |
# 임시 파일 삭제 (numpy array였을 경우에만)
|
90 |
if not isinstance(image, str):
|
91 |
+
os.unlink(image_file.name)
|
92 |
|
93 |
# 결과 확인 및 처리
|
94 |
if isinstance(result, str) and result.endswith('.mp4'):
|
|
|
119 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
120 |
with gr.Tab("Generate"):
|
121 |
with gr.Row():
|
122 |
+
input_image = gr.Image(label="Upload an image", type="filepath")
|
123 |
input_text = gr.Textbox(label="Enter your prompt for video generation")
|
124 |
output_video = gr.Video(label="Generated Video")
|
125 |
|