Spaces:
Sleeping
Sleeping
seawolf2357
commited on
Commit
โข
0660b1b
1
Parent(s):
0127bb3
Update app.py
Browse files
app.py
CHANGED
@@ -1,32 +1,43 @@
|
|
1 |
-
from huggingface_hub import HfApi, HfFolder, Repository
|
2 |
import os
|
|
|
3 |
from huggingface_hub import HfApi
|
4 |
|
|
|
|
|
|
|
|
|
5 |
api = HfApi()
|
6 |
-
repo_name = "seawolf2357"
|
7 |
-
hf_username = "video"
|
8 |
-
token = os.getenv("TOKEN")
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
|
14 |
-
|
15 |
-
exist_ok=True # ์ด๋ฏธ ์กด์ฌํ๋ ๊ฒฝ์ฐ ์ค๋ฅ ๋ฐฉ์ง
|
16 |
-
)
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
|
19 |
-
#
|
20 |
-
|
21 |
-
|
22 |
-
os.chdir(repo_local_path)
|
23 |
|
24 |
-
#
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
|
|
|
|
|
|
29 |
|
30 |
-
#
|
31 |
-
|
32 |
-
print("Uploaded file URL:", uploaded_file_url)
|
|
|
|
|
1 |
import os
|
2 |
+
import gradio as gr
|
3 |
from huggingface_hub import HfApi
|
4 |
|
5 |
+
# ํ๊ฒฝ ๋ณ์์์ Hugging Face ํ ํฐ ์ฝ๊ธฐ
|
6 |
+
hf_token = os.getenv("HF_TOKEN")
|
7 |
+
|
8 |
+
# Hugging Face API ์ด๊ธฐํ
|
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 |
+
with open(uploaded_file.name, "wb") as f:
|
19 |
+
f.write(uploaded_file.read())
|
20 |
+
|
21 |
+
# Hugging Face Spaces์ ํ์ผ ์
๋ก๋
|
22 |
+
response = api.upload_file(
|
23 |
+
path_or_fileobj=uploaded_file.name,
|
24 |
+
path_in_repo=uploaded_file.name,
|
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/{uploaded_file.name}"
|
31 |
+
return uploaded_file_url
|
|
|
32 |
|
33 |
+
# Gradio ์ธํฐํ์ด์ค ์ค์
|
34 |
+
iface = gr.Interface(
|
35 |
+
fn=upload_file_to_hf_space,
|
36 |
+
inputs=gr.inputs.File(filetypes=["mp4"], label="Upload your MP4 file"),
|
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."
|
40 |
+
)
|
41 |
|
42 |
+
# ์ธํฐํ์ด์ค ์คํ
|
43 |
+
iface.launch()
|
|