Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
1 |
import os
|
|
|
2 |
import gradio as gr
|
3 |
from huggingface_hub import HfApi
|
4 |
|
@@ -9,22 +10,18 @@ hf_token = os.getenv("HF_TOKEN")
|
|
9 |
api = HfApi()
|
10 |
|
11 |
def upload_file_to_hf_space(uploaded_file):
|
12 |
-
# μ¬μ©μ IDμ μ€νμ΄μ€ μ΄λ¦ μ€μ
|
13 |
user_id = "seawolf2357"
|
14 |
-
space_name = "video"
|
15 |
repo_id = f"{user_id}/{space_name}"
|
16 |
|
17 |
-
#
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
# νμΌ μ ν κ²μ¬ (MP4 νμΌμΈμ§ νμΈ)
|
23 |
-
if not file_path.endswith('.mp4'):
|
24 |
-
return "Please upload an MP4 file."
|
25 |
|
26 |
# Hugging Face Spacesμ νμΌ μ
λ‘λ
|
27 |
-
|
28 |
path_or_fileobj=file_path,
|
29 |
path_in_repo=os.path.basename(file_path),
|
30 |
repo_id=repo_id,
|
@@ -33,9 +30,10 @@ def upload_file_to_hf_space(uploaded_file):
|
|
33 |
|
34 |
# μ
λ‘λλ νμΌμ URL λ°ν
|
35 |
uploaded_file_url = f"https://huggingface.co/spaces/{repo_id}/blob/main/{os.path.basename(file_path)}"
|
|
|
36 |
return uploaded_file_url
|
37 |
|
38 |
-
# Gradio μΈν°νμ΄μ€ μ€μ
|
39 |
iface = gr.Interface(
|
40 |
fn=upload_file_to_hf_space,
|
41 |
inputs=gr.File(label="Upload your MP4 file"),
|
@@ -44,5 +42,4 @@ iface = gr.Interface(
|
|
44 |
description="Upload an MP4 file and get its URL in Hugging Face Spaces. Please ensure the file is an MP4 format."
|
45 |
)
|
46 |
|
47 |
-
|
48 |
-
iface.launch()
|
|
|
1 |
import os
|
2 |
+
import tempfile
|
3 |
import gradio as gr
|
4 |
from huggingface_hub import HfApi
|
5 |
|
|
|
10 |
api = HfApi()
|
11 |
|
12 |
def upload_file_to_hf_space(uploaded_file):
|
|
|
13 |
user_id = "seawolf2357"
|
14 |
+
space_name = "video"
|
15 |
repo_id = f"{user_id}/{space_name}"
|
16 |
|
17 |
+
# μμ νμΌ μμ± λ° μ
λ‘λλ νμΌ λ°μ΄ν° μ°κΈ°
|
18 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix='.mp4') as tmp_file:
|
19 |
+
# Gradio 2.0 μ΄μμμλ uploaded_fileμ΄ νμΌμ λ°μ΄λ리 λ°μ΄ν°λ₯Ό μ§μ μ 곡
|
20 |
+
tmp_file.write(uploaded_file)
|
21 |
+
file_path = tmp_file.name
|
|
|
|
|
|
|
22 |
|
23 |
# Hugging Face Spacesμ νμΌ μ
λ‘λ
|
24 |
+
api.upload_file(
|
25 |
path_or_fileobj=file_path,
|
26 |
path_in_repo=os.path.basename(file_path),
|
27 |
repo_id=repo_id,
|
|
|
30 |
|
31 |
# μ
λ‘λλ νμΌμ URL λ°ν
|
32 |
uploaded_file_url = f"https://huggingface.co/spaces/{repo_id}/blob/main/{os.path.basename(file_path)}"
|
33 |
+
os.unlink(file_path) # μμ νμΌ μμ
|
34 |
return uploaded_file_url
|
35 |
|
36 |
+
# Gradio μΈν°νμ΄μ€ μ€μ λ° μ€ν
|
37 |
iface = gr.Interface(
|
38 |
fn=upload_file_to_hf_space,
|
39 |
inputs=gr.File(label="Upload your MP4 file"),
|
|
|
42 |
description="Upload an MP4 file and get its URL in Hugging Face Spaces. Please ensure the file is an MP4 format."
|
43 |
)
|
44 |
|
45 |
+
iface.launch()
|
|