Update app.py
Browse files
app.py
CHANGED
@@ -26,8 +26,9 @@ def save_to_gallery(video_path, prompt):
|
|
26 |
new_video_path = os.path.join(GALLERY_DIR, f"{timestamp}.mp4")
|
27 |
|
28 |
# 비디오 파일 복사
|
29 |
-
|
30 |
-
|
|
|
31 |
|
32 |
# 갤러리 정보 저장
|
33 |
gallery_info = {
|
@@ -58,23 +59,24 @@ def load_gallery():
|
|
58 |
|
59 |
|
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}")
|
64 |
|
65 |
try:
|
66 |
-
#
|
67 |
-
|
68 |
-
|
|
|
|
|
69 |
img = Image.fromarray(image.astype('uint8'), 'RGB')
|
70 |
img.save(temp_file.name)
|
71 |
-
|
72 |
-
temp_file.write(image)
|
73 |
-
temp_file_path = temp_file.name
|
74 |
|
75 |
# 비디오 생성 요청
|
76 |
result = api_client.predict(
|
77 |
-
|
78 |
prompt,
|
79 |
steps,
|
80 |
cfg_scale,
|
@@ -86,8 +88,9 @@ def respond(image, prompt, steps, cfg_scale, eta, fs, seed, video_length):
|
|
86 |
)
|
87 |
logging.info("API response received: %s", result)
|
88 |
|
89 |
-
# 임시 파일 삭제
|
90 |
-
|
|
|
91 |
|
92 |
# 결과 확인 및 처리
|
93 |
if isinstance(result, str) and result.endswith('.mp4'):
|
@@ -118,7 +121,7 @@ def use_prompt(prompt):
|
|
118 |
with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
|
119 |
with gr.Tab("Generate"):
|
120 |
with gr.Row():
|
121 |
-
input_image = gr.Image(label="Upload an image", type="
|
122 |
input_text = gr.Textbox(label="Enter your prompt for video generation")
|
123 |
output_video = gr.Video(label="Generated Video")
|
124 |
|
|
|
26 |
new_video_path = os.path.join(GALLERY_DIR, f"{timestamp}.mp4")
|
27 |
|
28 |
# 비디오 파일 복사
|
29 |
+
shutil.copy2(video_path, new_video_path)
|
30 |
+
|
31 |
+
|
32 |
|
33 |
# 갤러리 정보 저장
|
34 |
gallery_info = {
|
|
|
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}")
|
66 |
|
67 |
try:
|
68 |
+
# 이미지 처리
|
69 |
+
if isinstance(image, str): # 파일 경로인 경우
|
70 |
+
image_path = image
|
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 |
+
image_path = temp_file.name
|
|
|
|
|
76 |
|
77 |
# 비디오 생성 요청
|
78 |
result = api_client.predict(
|
79 |
+
image_path,
|
80 |
prompt,
|
81 |
steps,
|
82 |
cfg_scale,
|
|
|
88 |
)
|
89 |
logging.info("API response received: %s", result)
|
90 |
|
91 |
+
# 임시 파일 삭제 (numpy array였을 경우에만)
|
92 |
+
if not isinstance(image, str):
|
93 |
+
os.unlink(image_path)
|
94 |
|
95 |
# 결과 확인 및 처리
|
96 |
if isinstance(result, str) and result.endswith('.mp4'):
|
|
|
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="numpy")
|
125 |
input_text = gr.Textbox(label="Enter your prompt for video generation")
|
126 |
output_video = gr.Video(label="Generated Video")
|
127 |
|