Spaces:
Sleeping
Sleeping
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 | |