Spaces:
Running
Running
import gradio as gr | |
from huggingface_hub import HfApi | |
import os | |
# Initialize the Hugging Face API with the token | |
api = HfApi(token=os.getenv("HF_API_TOKEN")) | |
def upload_video(video): | |
# Save the uploaded video to a temporary file | |
video_path = os.path.join("temp", video.name) | |
# Write the file from the binary content | |
with open(video_path, "wb") as f: | |
f.write(video.read_bytes()) # Use read_bytes() instead of read() | |
# Upload the video to Hugging Face | |
api.upload_file( | |
path_or_fileobj=video_path, | |
path_in_repo=f"/videos/{video.name}", | |
repo_id="vericudebuget/ok4231", | |
repo_type="space", | |
) | |
return f"Uploaded {video.name} successfully!" | |
def progress_bar(video): | |
return f"Uploading {video.name}..." | |
with gr.Blocks() as demo: | |
video_input = gr.File(label="Upload Video") | |
progress = gr.Textbox(label="Progress") | |
output = gr.Textbox(label="Output") | |
video_input.change(progress_bar, inputs=video_input, outputs=progress) | |
video_input.upload(upload_video, inputs=video_input, outputs=output) | |
demo.launch() | |