Spaces:
Running
Running
File size: 1,115 Bytes
2e0eb40 436734f 5c4b237 4478b28 5ff2b1d 5c4b237 436734f 4478b28 436734f 4478b28 04b984b 436734f fe472d7 436734f fe472d7 436734f 2e0eb40 436734f 2e0eb40 436734f 2e0eb40 436734f |
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 |
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()
|