vericudebuget commited on
Commit
019f3a5
·
verified ·
1 Parent(s): 1187796

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -20
app.py CHANGED
@@ -1,38 +1,45 @@
1
- import gradio as gr
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
- def upload_video(video):
10
- # Save the uploaded video to a temporary file
11
- video_path = os.path.join("temp", video.name)
 
12
 
13
- # Write the file from the uploaded content
 
 
 
 
14
  with open(video_path, "wb") as f:
15
- shutil.copyfileobj(video, f) # Use shutil.copyfileobj to write the file
16
 
17
  # Upload the video to Hugging Face
18
  api.upload_file(
19
  path_or_fileobj=video_path,
20
- path_in_repo=f"/videos/{video.name}",
21
  repo_id="vericudebuget/ok4231",
22
  repo_type="space",
23
  )
24
-
25
- return f"Uploaded {video.name} successfully!"
26
 
27
- def progress_bar(video):
28
- return f"Uploading {video.name}..."
29
 
30
- with gr.Blocks() as demo:
31
- video_input = gr.File(label="Upload Video")
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
- demo.launch()
 
 
 
 
 
 
 
 
 
 
 
 
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)