ginipick commited on
Commit
42b376b
ยท
verified ยท
1 Parent(s): c06a9b5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -13
app.py CHANGED
@@ -12,7 +12,8 @@ import httpx
12
  import time
13
  import base64
14
  from gradio_client import Client, handle_file
15
-
 
16
  # ๋กœ๊น… ์„ค์ •
17
  logging.basicConfig(level=logging.INFO)
18
 
@@ -46,13 +47,19 @@ os.makedirs(GALLERY_DIR, exist_ok=True)
46
  def save_to_gallery(video_path, prompt):
47
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
48
  new_video_path = os.path.join(GALLERY_DIR, f"{timestamp}.mp4")
 
49
 
50
  # ๋น„๋””์˜ค ํŒŒ์ผ ๋ณต์‚ฌ
51
  shutil.copy2(video_path, new_video_path)
52
 
 
 
 
 
53
  # ๊ฐค๋Ÿฌ๋ฆฌ ์ •๋ณด ์ €์žฅ
54
  gallery_info = {
55
  "video": new_video_path,
 
56
  "prompt": prompt,
57
  "timestamp": timestamp
58
  }
@@ -68,14 +75,13 @@ def save_to_gallery(video_path, prompt):
68
  with open(GALLERY_JSON, "w") as f:
69
  json.dump(gallery, f, indent=2)
70
 
71
- return new_video_path
72
-
73
 
74
  def load_gallery():
75
  if os.path.exists(GALLERY_JSON):
76
  with open(GALLERY_JSON, "r") as f:
77
  gallery = json.load(f)
78
- return [(item["video"], item["prompt"]) for item in reversed(gallery)]
79
  return []
80
 
81
 
@@ -128,8 +134,9 @@ examples = [
128
  ["A fantasy map of a fictional world, with detailed terrain and cities.", "q19.webp"]
129
  ]
130
 
131
- def use_prompt(prompt):
132
- return prompt
 
133
 
134
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
135
  with gr.Tab("Generate"):
@@ -145,21 +152,23 @@ with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
145
  fs = gr.Slider(minimum=1, maximum=30, step=1, label="FPS", value=8)
146
  seed = gr.Slider(minimum=0, maximum=1000000, step=1, label="Seed", value=123)
147
  video_length = gr.Slider(minimum=1, maximum=10, step=1, label="Video Length (seconds)", value=2)
148
-
149
  with gr.Row():
150
  for prompt, image_file in examples:
151
  with gr.Column():
152
- gr.Image(image_file, label=prompt[:50] + "...") # ํ”„๋กฌํ”„ํŠธ์˜ ์ฒ˜์Œ 50์ž๋งŒ ํ‘œ์‹œ
153
- gr.Button("Use this prompt").click(
154
- fn=use_prompt,
155
  inputs=[],
156
- outputs=input_text,
157
  api_name=False
158
  ).then(
159
- lambda x=prompt: x,
160
  inputs=[],
161
- outputs=input_text
162
  )
 
 
163
 
164
  with gr.Tab("Gallery"):
165
  gallery = gr.Gallery(
 
12
  import time
13
  import base64
14
  from gradio_client import Client, handle_file
15
+ import cv2
16
+ from moviepy.editor import VideoFileClip
17
  # ๋กœ๊น… ์„ค์ •
18
  logging.basicConfig(level=logging.INFO)
19
 
 
47
  def save_to_gallery(video_path, prompt):
48
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
49
  new_video_path = os.path.join(GALLERY_DIR, f"{timestamp}.mp4")
50
+ thumbnail_path = os.path.join(GALLERY_DIR, f"{timestamp}_thumb.jpg")
51
 
52
  # ๋น„๋””์˜ค ํŒŒ์ผ ๋ณต์‚ฌ
53
  shutil.copy2(video_path, new_video_path)
54
 
55
+ # ์ธ๋„ค์ผ ์ƒ์„ฑ
56
+ video = VideoFileClip(new_video_path)
57
+ video.save_frame(thumbnail_path, t=0) # ์ฒซ ํ”„๋ ˆ์ž„์„ ์ธ๋„ค์ผ๋กœ ์ €์žฅ
58
+
59
  # ๊ฐค๋Ÿฌ๋ฆฌ ์ •๋ณด ์ €์žฅ
60
  gallery_info = {
61
  "video": new_video_path,
62
+ "thumbnail": thumbnail_path,
63
  "prompt": prompt,
64
  "timestamp": timestamp
65
  }
 
75
  with open(GALLERY_JSON, "w") as f:
76
  json.dump(gallery, f, indent=2)
77
 
78
+ return new_video_path, thumbnail_path
 
79
 
80
  def load_gallery():
81
  if os.path.exists(GALLERY_JSON):
82
  with open(GALLERY_JSON, "r") as f:
83
  gallery = json.load(f)
84
+ return [(item["thumbnail"], item["prompt"], item["video"]) for item in reversed(gallery)]
85
  return []
86
 
87
 
 
134
  ["A fantasy map of a fictional world, with detailed terrain and cities.", "q19.webp"]
135
  ]
136
 
137
+ def use_prompt_and_image(prompt, image):
138
+ return prompt, image
139
+
140
 
141
  with gr.Blocks(theme="Nymbo/Nymbo_Theme", css=css) as demo:
142
  with gr.Tab("Generate"):
 
152
  fs = gr.Slider(minimum=1, maximum=30, step=1, label="FPS", value=8)
153
  seed = gr.Slider(minimum=0, maximum=1000000, step=1, label="Seed", value=123)
154
  video_length = gr.Slider(minimum=1, maximum=10, step=1, label="Video Length (seconds)", value=2)
155
+
156
  with gr.Row():
157
  for prompt, image_file in examples:
158
  with gr.Column():
159
+ gr.Image(image_file, label=prompt[:50] + "...")
160
+ gr.Button("Use this example").click(
161
+ fn=use_prompt_and_image,
162
  inputs=[],
163
+ outputs=[input_text, input_image],
164
  api_name=False
165
  ).then(
166
+ lambda p=prompt, i=image_file: (p, i),
167
  inputs=[],
168
+ outputs=[input_text, input_image]
169
  )
170
+
171
+
172
 
173
  with gr.Tab("Gallery"):
174
  gallery = gr.Gallery(