seawolf2357 commited on
Commit
9e25e78
โ€ข
1 Parent(s): e2ad603

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -29
app.py CHANGED
@@ -1,36 +1,33 @@
1
- import cv2
2
- import gradio as gr
3
  import os
4
- import tempfile
5
- from pathlib import Path
6
 
7
- def image_to_video(input_file, fps=30):
8
- with tempfile.TemporaryDirectory() as temp_dir:
9
- file_path = os.path.join(temp_dir, "image.jpg")
10
- with open(file_path, 'wb') as file:
11
- file.write(input_file)
12
 
13
- frame = cv2.imread(file_path)
14
- height, width, layers = frame.shape
15
- size = (width, height)
16
-
17
- video_filename = os.path.join('/mnt/data', 'output_video.mp4')
18
-
19
- out = cv2.VideoWriter(video_filename, cv2.VideoWriter_fourcc(*'mp4v'), fps, size)
20
- out.write(frame)
21
- out.release()
22
 
23
- if not os.path.exists(video_filename):
24
- raise FileNotFoundError(f"Failed to create video: {video_filename}")
 
 
 
 
 
25
 
26
- return video_filename
 
 
 
27
 
28
- iface = gr.Interface(
29
- fn=image_to_video,
30
- inputs=gr.File(type="binary", label="Upload Image"),
31
- outputs=gr.Video(label="Output Video"),
32
- title="Image to Video Converter",
33
- description="Upload an image to create a video."
34
- )
35
 
36
- iface.launch()
 
 
 
1
+ from huggingface_hub import HfApi, HfFolder, Repository
 
2
  import os
 
 
3
 
4
+ # Hugging Face ๊ณ„์ •์œผ๋กœ ๋กœ๊ทธ์ธ (์ฒ˜์Œ ์‹คํ–‰ ์‹œ ๋กœ๊ทธ์ธ ์ •๋ณด ์ž…๋ ฅ)
5
+ hf_username = "seawolf2357" # ์—ฌ๊ธฐ์— Hugging Face ์‚ฌ์šฉ์ž ์ด๋ฆ„ ์ž…๋ ฅ
6
+ repo_name = "video" # ์—ฌ๊ธฐ์— ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ์ด๋ฆ„ ์ž…๋ ฅ (์—†์œผ๋ฉด ์ƒ์„ฑ๋จ)
7
+ file_path = "your_file_path.mp4" # ์—…๋กœ๋“œํ•  ํŒŒ์ผ์˜ ๊ฒฝ๋กœ
 
8
 
9
+ # API ์ดˆ๊ธฐํ™”
10
+ api = HfApi()
 
 
 
 
 
 
 
11
 
12
+ # ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ๊ฒฝ๋กœ ์„ค์ •
13
+ repo_url = api.create_repo(
14
+ name=repo_name,
15
+ token=HfFolder.get_token(),
16
+ private=False, # True๋กœ ์„ค์ •ํ•˜๋ฉด ๋น„๊ณต๊ฐœ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ์ƒ์„ฑ
17
+ exist_ok=True # ์ด๋ฏธ ์กด์žฌํ•˜๋Š” ๊ฒฝ์šฐ ์˜ค๋ฅ˜ ๋ฐฉ์ง€
18
+ )
19
 
20
+ # ๋กœ์ปฌ์—์„œ ๋ฆฌํฌ์ง€ํ† ๋ฆฌ ํด๋ก 
21
+ repo_local_path = "./" + repo_name
22
+ repo = Repository(repo_local_path, clone_from=repo_url)
23
+ os.chdir(repo_local_path)
24
 
25
+ # ํŒŒ์ผ ์—…๋กœ๋“œ
26
+ repo.lfs_track("*.mp4") # MP4 ํŒŒ์ผ LFS ์ถ”์ 
27
+ repo.git_add(file_path) # ํŒŒ์ผ ์ถ”๊ฐ€
28
+ repo.git_commit("Upload MP4 file") # ์ปค๋ฐ‹ ๋ฉ”์‹œ์ง€
29
+ repo.git_push() # ๋ณ€๊ฒฝ ์‚ฌํ•ญ ํ‘ธ์‹œ
 
 
30
 
31
+ # ์—…๋กœ๋“œ๋œ ํŒŒ์ผ์˜ URL ๋ฐ˜ํ™˜
32
+ uploaded_file_url = f"https://huggingface.co/{hf_username}/{repo_name}/blob/main/{os.path.basename(file_path)}"
33
+ print("Uploaded file URL:", uploaded_file_url)