seawolf2357 commited on
Commit
5fd7cca
โ€ข
1 Parent(s): 377906c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -8
app.py CHANGED
@@ -22,15 +22,20 @@ def upload_file_to_hf_space(uploaded_file):
22
  repo_id = f"{user_id}/{space_name}"
23
 
24
  # ์ž„์‹œ ํŒŒ์ผ ์ƒ์„ฑ ๋ฐ ์—…๋กœ๋“œ๋œ ํŒŒ์ผ ๋ฐ์ดํ„ฐ ์“ฐ๊ธฐ
25
- with tempfile.NamedTemporaryFile(delete=True, suffix='.mp4') as tmp_file:
26
- try:
 
27
  tmp_file.write(uploaded_file)
28
- tmp_file.flush()
29
- file_path = tmp_file.name
30
-
31
- logging.info(f"Uploading {file_path} to Hugging Face Spaces")
32
-
33
- # Hugging Face Spaces์— ํŒŒ์ผ ์—…๋กœ๋“œ
 
 
 
 
34
  api.upload_file(
35
  path_or_fileobj=file_path,
36
  path_in_repo=os.path.basename(file_path),
 
22
  repo_id = f"{user_id}/{space_name}"
23
 
24
  # ์ž„์‹œ ํŒŒ์ผ ์ƒ์„ฑ ๋ฐ ์—…๋กœ๋“œ๋œ ํŒŒ์ผ ๋ฐ์ดํ„ฐ ์“ฐ๊ธฐ
25
+ with tempfile.NamedTemporaryFile(delete=True, suffix='.mp4', mode='wb') as tmp_file:
26
+ # ์—…๋กœ๋“œ๋œ ํŒŒ์ผ์˜ ๋ฐ”์ดํŠธ ๋ฐ์ดํ„ฐ๋ฅผ ์ž„์‹œ ํŒŒ์ผ์— ์“ฐ๊ธฐ
27
+ if isinstance(uploaded_file, bytes):
28
  tmp_file.write(uploaded_file)
29
+ else:
30
+ # Gradio๋กœ๋ถ€ํ„ฐ ๋ฐ›์€ ํŒŒ์ผ ๋ฐ์ดํ„ฐ๊ฐ€ bytes๊ฐ€ ์•„๋‹Œ ๊ฒฝ์šฐ ์ฒ˜๋ฆฌ
31
+ data = uploaded_file.read() # ํŒŒ์ผ ๊ฐ์ฒด์—์„œ ๋ฐ”์ดํŠธ ๋ฐ์ดํ„ฐ ์ฝ๊ธฐ
32
+ tmp_file.write(data)
33
+
34
+ tmp_file.flush()
35
+ file_path = tmp_file.name
36
+
37
+ logging.info(f"Uploading {file_path} to Hugging Face Spaces")
38
+ try:
39
  api.upload_file(
40
  path_or_fileobj=file_path,
41
  path_in_repo=os.path.basename(file_path),