ginipick commited on
Commit
c13831b
1 Parent(s): 432a7d3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -10
app.py CHANGED
@@ -12,23 +12,29 @@ logging.basicConfig(level=logging.INFO)
12
  api_client = Client("http://211.233.58.202:7960/")
13
 
14
  # 갤러리 저장 디렉토리 설정
15
- GALLERY_DIR = "gallery"
16
- GALLERY_JSON = "gallery.json"
17
 
18
  # 갤러리 디렉토리 생성
19
  os.makedirs(GALLERY_DIR, exist_ok=True)
20
 
21
- def save_to_gallery(image_path, prompt):
22
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
23
- new_image_path = os.path.join(GALLERY_DIR, f"{timestamp}.png")
 
24
 
25
- # 이미지 파일 복사
26
- with open(image_path, "rb") as src, open(new_image_path, "wb") as dst:
27
- dst.write(src.read())
 
 
 
 
28
 
29
  # 갤러리 정보 저장
30
  gallery_info = {
31
- "image": new_image_path,
 
32
  "prompt": prompt,
33
  "timestamp": timestamp
34
  }
@@ -44,13 +50,13 @@ def save_to_gallery(image_path, prompt):
44
  with open(GALLERY_JSON, "w") as f:
45
  json.dump(gallery, f, indent=2)
46
 
47
- return new_image_path
48
 
49
  def load_gallery():
50
  if os.path.exists(GALLERY_JSON):
51
  with open(GALLERY_JSON, "r") as f:
52
  gallery = json.load(f)
53
- return [(item["image"], item["prompt"]) for item in reversed(gallery)]
54
  return []
55
 
56
  def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):
 
12
  api_client = Client("http://211.233.58.202:7960/")
13
 
14
  # 갤러리 저장 디렉토리 설정
15
+ GALLERY_DIR = "/home/user/app/gallery"
16
+ GALLERY_JSON = "/home/user/app/gallery.json"
17
 
18
  # 갤러리 디렉토리 생성
19
  os.makedirs(GALLERY_DIR, exist_ok=True)
20
 
21
+ def save_to_gallery(video_path, prompt):
22
  timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
23
+ new_video_path = os.path.join(GALLERY_DIR, f"{timestamp}.mp4")
24
+ thumbnail_path = os.path.join(GALLERY_DIR, f"{timestamp}_thumb.jpg")
25
 
26
+ # 비디오 파일 복사
27
+ shutil.copy2(video_path, new_video_path)
28
+
29
+ # 썸네일 생성
30
+ video = VideoFileClip(new_video_path)
31
+ video.save_frame(thumbnail_path, t=0) # 첫 프레임을 썸네일로 저장
32
+ video.close()
33
 
34
  # 갤러리 정보 저장
35
  gallery_info = {
36
+ "video": new_video_path,
37
+ "thumbnail": thumbnail_path,
38
  "prompt": prompt,
39
  "timestamp": timestamp
40
  }
 
50
  with open(GALLERY_JSON, "w") as f:
51
  json.dump(gallery, f, indent=2)
52
 
53
+ return new_video_path, thumbnail_path
54
 
55
  def load_gallery():
56
  if os.path.exists(GALLERY_JSON):
57
  with open(GALLERY_JSON, "r") as f:
58
  gallery = json.load(f)
59
+ return [(item["thumbnail"], item["prompt"], item["video"]) for item in reversed(gallery)]
60
  return []
61
 
62
  def respond(message, seed, randomize_seed, width, height, guidance_scale, num_inference_steps):