Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
β’
17bf8a6
1
Parent(s):
0660b1b
Update app.py
Browse files
app.py
CHANGED
@@ -14,26 +14,29 @@ def upload_file_to_hf_space(uploaded_file):
|
|
14 |
space_name = "video" # μ€νμ΄μ€ μ΄λ¦μ μ¬κΈ°μ μ
λ ₯νμΈμ.
|
15 |
repo_id = f"{user_id}/{space_name}"
|
16 |
|
17 |
-
#
|
18 |
-
|
|
|
|
|
|
|
19 |
f.write(uploaded_file.read())
|
20 |
-
|
21 |
# Hugging Face Spacesμ νμΌ μ
λ‘λ
|
22 |
response = api.upload_file(
|
23 |
-
path_or_fileobj=
|
24 |
-
path_in_repo=
|
25 |
repo_id=repo_id,
|
26 |
token=hf_token,
|
27 |
)
|
28 |
|
29 |
# μ
λ‘λλ νμΌμ URL λ°ν
|
30 |
-
uploaded_file_url = f"https://huggingface.co/spaces/{repo_id}/blob/main/{
|
31 |
return uploaded_file_url
|
32 |
|
33 |
# Gradio μΈν°νμ΄μ€ μ€μ
|
34 |
iface = gr.Interface(
|
35 |
fn=upload_file_to_hf_space,
|
36 |
-
inputs=gr.
|
37 |
outputs="text",
|
38 |
title="MP4 File Upload to Hugging Face Spaces",
|
39 |
description="Upload an MP4 file and get its URL in Hugging Face Spaces."
|
|
|
14 |
space_name = "video" # μ€νμ΄μ€ μ΄λ¦μ μ¬κΈ°μ μ
λ ₯νμΈμ.
|
15 |
repo_id = f"{user_id}/{space_name}"
|
16 |
|
17 |
+
# νμΌλͺ
μ€μ
|
18 |
+
file_path = uploaded_file.name
|
19 |
+
|
20 |
+
# νμΌ μ μ₯
|
21 |
+
with open(file_path, "wb") as f:
|
22 |
f.write(uploaded_file.read())
|
23 |
+
|
24 |
# Hugging Face Spacesμ νμΌ μ
λ‘λ
|
25 |
response = api.upload_file(
|
26 |
+
path_or_fileobj=file_path,
|
27 |
+
path_in_repo=os.path.basename(file_path),
|
28 |
repo_id=repo_id,
|
29 |
token=hf_token,
|
30 |
)
|
31 |
|
32 |
# μ
λ‘λλ νμΌμ URL λ°ν
|
33 |
+
uploaded_file_url = f"https://huggingface.co/spaces/{repo_id}/blob/main/{os.path.basename(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(filetypes=["mp4"], label="Upload your MP4 file"),
|
40 |
outputs="text",
|
41 |
title="MP4 File Upload to Hugging Face Spaces",
|
42 |
description="Upload an MP4 file and get its URL in Hugging Face Spaces."
|