Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,38 +1,45 @@
|
|
1 |
-
import
|
2 |
from huggingface_hub import HfApi
|
3 |
import os
|
4 |
-
import shutil
|
5 |
|
6 |
# Initialize the Hugging Face API with the token
|
7 |
api = HfApi(token=os.getenv("HF_API_TOKEN"))
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
|
|
|
12 |
|
13 |
-
#
|
|
|
|
|
|
|
|
|
14 |
with open(video_path, "wb") as f:
|
15 |
-
|
16 |
|
17 |
# Upload the video to Hugging Face
|
18 |
api.upload_file(
|
19 |
path_or_fileobj=video_path,
|
20 |
-
path_in_repo=f"
|
21 |
repo_id="vericudebuget/ok4231",
|
22 |
repo_type="space",
|
23 |
)
|
24 |
-
|
25 |
-
return f"Uploaded {video.name} successfully!"
|
26 |
|
27 |
-
|
28 |
-
return f"Uploading {video.name}..."
|
29 |
|
30 |
-
|
31 |
-
|
32 |
-
progress = gr.Textbox(label="Progress")
|
33 |
-
output = gr.Textbox(label="Output")
|
34 |
-
|
35 |
-
video_input.change(progress_bar, inputs=video_input, outputs=progress)
|
36 |
-
video_input.upload(upload_video, inputs=video_input, outputs=output)
|
37 |
|
38 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
from huggingface_hub import HfApi
|
3 |
import os
|
|
|
4 |
|
5 |
# Initialize the Hugging Face API with the token
|
6 |
api = HfApi(token=os.getenv("HF_API_TOKEN"))
|
7 |
|
8 |
+
# Function to handle video uploads to Hugging Face
|
9 |
+
def upload_video_to_hf(video_file, video_name):
|
10 |
+
# Save the video temporarily to a file
|
11 |
+
video_path = os.path.join("temp", video_name)
|
12 |
|
13 |
+
# Ensure the temp directory exists
|
14 |
+
if not os.path.exists("temp"):
|
15 |
+
os.makedirs("temp")
|
16 |
+
|
17 |
+
# Write the video content to a file
|
18 |
with open(video_path, "wb") as f:
|
19 |
+
f.write(video_file.read())
|
20 |
|
21 |
# Upload the video to Hugging Face
|
22 |
api.upload_file(
|
23 |
path_or_fileobj=video_path,
|
24 |
+
path_in_repo=f"videos/{video_name}",
|
25 |
repo_id="vericudebuget/ok4231",
|
26 |
repo_type="space",
|
27 |
)
|
|
|
|
|
28 |
|
29 |
+
return f"Uploaded {video_name} successfully to Hugging Face!"
|
|
|
30 |
|
31 |
+
# Streamlit app interface
|
32 |
+
st.title("Video Uploader to Hugging Face")
|
|
|
|
|
|
|
|
|
|
|
33 |
|
34 |
+
# File uploader for video input
|
35 |
+
uploaded_video = st.file_uploader("Upload your video", type=["mp4", "avi", "mov"])
|
36 |
+
|
37 |
+
if uploaded_video:
|
38 |
+
# Show the name of the uploaded video
|
39 |
+
st.write(f"Uploaded video: {uploaded_video.name}")
|
40 |
+
|
41 |
+
# Upload the video when the button is clicked
|
42 |
+
if st.button("Upload to Hugging Face"):
|
43 |
+
with st.spinner("Uploading..."):
|
44 |
+
result = upload_video_to_hf(uploaded_video, uploaded_video.name)
|
45 |
+
st.success(result)
|