File size: 1,478 Bytes
612cb39
0660b1b
2348476
c892817
0660b1b
 
 
 
9e25e78
e2ad603
0660b1b
 
 
 
 
e2ad603
1cd16bc
17bf8a6
 
0660b1b
17bf8a6
1cd16bc
 
 
 
0660b1b
 
17bf8a6
 
0660b1b
 
 
2348476
0660b1b
17bf8a6
0660b1b
c892817
0660b1b
 
 
1cd16bc
0660b1b
 
b8bab42
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import os
import gradio as gr
from huggingface_hub import HfApi

# ν™˜κ²½ λ³€μˆ˜μ—μ„œ Hugging Face 토큰 읽기
hf_token = os.getenv("HF_TOKEN")

# Hugging Face API μ΄ˆκΈ°ν™”
api = HfApi()

def upload_file_to_hf_space(uploaded_file):
    # μ‚¬μš©μž ID와 슀페이슀 이름 μ„€μ •
    user_id = "seawolf2357"
    space_name = "video"  # 슀페이슀 이름을 여기에 μž…λ ₯ν•˜μ„Έμš”.
    repo_id = f"{user_id}/{space_name}"

    # 파일λͺ… μ„€μ • 및 μ €μž₯
    file_path = uploaded_file.name
    with open(file_path, "wb") as f:
        f.write(uploaded_file.read())

    # 파일 μœ ν˜• 검사 (MP4 νŒŒμΌμΈμ§€ 확인)
    if not file_path.endswith('.mp4'):
        return "Please upload an MP4 file."

    # Hugging Face Spaces에 파일 μ—…λ‘œλ“œ
    response = api.upload_file(
        path_or_fileobj=file_path,
        path_in_repo=os.path.basename(file_path),
        repo_id=repo_id,
        token=hf_token,
    )

    # μ—…λ‘œλ“œλœ 파일의 URL λ°˜ν™˜
    uploaded_file_url = f"https://huggingface.co/spaces/{repo_id}/blob/main/{os.path.basename(file_path)}"
    return uploaded_file_url

# Gradio μΈν„°νŽ˜μ΄μŠ€ μ„€μ •
iface = gr.Interface(
    fn=upload_file_to_hf_space,
    inputs=gr.File(label="Upload your MP4 file"),
    outputs="text",
    title="MP4 File Upload to Hugging Face Spaces",
    description="Upload an MP4 file and get its URL in Hugging Face Spaces. Please ensure the file is an MP4 format."
)

# μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
iface.launch()