seawolf2357 commited on
Commit
743e080
Β·
verified Β·
1 Parent(s): b8bab42

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -14
app.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
  import gradio as gr
3
  from huggingface_hub import HfApi
4
 
@@ -9,22 +10,18 @@ hf_token = os.getenv("HF_TOKEN")
9
  api = HfApi()
10
 
11
  def upload_file_to_hf_space(uploaded_file):
12
- # μ‚¬μš©μž ID와 슀페이슀 이름 μ„€μ •
13
  user_id = "seawolf2357"
14
- space_name = "video" # 슀페이슀 이름을 여기에 μž…λ ₯ν•˜μ„Έμš”.
15
  repo_id = f"{user_id}/{space_name}"
16
 
17
- # 파일λͺ… μ„€μ • 및 μ €μž₯
18
- file_path = uploaded_file.name
19
- with open(file_path, "wb") as f:
20
- f.write(uploaded_file.read())
21
-
22
- # 파일 μœ ν˜• 검사 (MP4 νŒŒμΌμΈμ§€ 확인)
23
- if not file_path.endswith('.mp4'):
24
- return "Please upload an MP4 file."
25
 
26
  # Hugging Face Spaces에 파일 μ—…λ‘œλ“œ
27
- response = api.upload_file(
28
  path_or_fileobj=file_path,
29
  path_in_repo=os.path.basename(file_path),
30
  repo_id=repo_id,
@@ -33,9 +30,10 @@ def upload_file_to_hf_space(uploaded_file):
33
 
34
  # μ—…λ‘œλ“œλœ 파일의 URL λ°˜ν™˜
35
  uploaded_file_url = f"https://huggingface.co/spaces/{repo_id}/blob/main/{os.path.basename(file_path)}"
 
36
  return uploaded_file_url
37
 
38
- # Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
39
  iface = gr.Interface(
40
  fn=upload_file_to_hf_space,
41
  inputs=gr.File(label="Upload your MP4 file"),
@@ -44,5 +42,4 @@ iface = gr.Interface(
44
  description="Upload an MP4 file and get its URL in Hugging Face Spaces. Please ensure the file is an MP4 format."
45
  )
46
 
47
- # μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
48
- iface.launch()
 
1
  import os
2
+ import tempfile
3
  import gradio as gr
4
  from huggingface_hub import HfApi
5
 
 
10
  api = HfApi()
11
 
12
  def upload_file_to_hf_space(uploaded_file):
 
13
  user_id = "seawolf2357"
14
+ space_name = "video"
15
  repo_id = f"{user_id}/{space_name}"
16
 
17
+ # μž„μ‹œ 파일 생성 및 μ—…λ‘œλ“œλœ 파일 데이터 μ“°κΈ°
18
+ with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmp_file:
19
+ # Gradio 2.0 μ΄μƒμ—μ„œλŠ” uploaded_file이 파일의 λ°”μ΄λ„ˆλ¦¬ 데이터λ₯Ό 직접 제곡
20
+ tmp_file.write(uploaded_file)
21
+ file_path = tmp_file.name
 
 
 
22
 
23
  # Hugging Face Spaces에 파일 μ—…λ‘œλ“œ
24
+ api.upload_file(
25
  path_or_fileobj=file_path,
26
  path_in_repo=os.path.basename(file_path),
27
  repo_id=repo_id,
 
30
 
31
  # μ—…λ‘œλ“œλœ 파일의 URL λ°˜ν™˜
32
  uploaded_file_url = f"https://huggingface.co/spaces/{repo_id}/blob/main/{os.path.basename(file_path)}"
33
+ os.unlink(file_path) # μž„μ‹œ 파일 μ‚­μ œ
34
  return uploaded_file_url
35
 
36
+ # Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ • 및 μ‹€ν–‰
37
  iface = gr.Interface(
38
  fn=upload_file_to_hf_space,
39
  inputs=gr.File(label="Upload your MP4 file"),
 
42
  description="Upload an MP4 file and get its URL in Hugging Face Spaces. Please ensure the file is an MP4 format."
43
  )
44
 
45
+ iface.launch()