Spaces:
Runtime error
Runtime error
Efreak
commited on
try to adapt for uploading files...
Browse files- app.py +22 -18
- packages.txt +1 -0
app.py
CHANGED
|
@@ -1,30 +1,32 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
|
|
|
|
|
|
| 3 |
from huggingface_hub import whoami
|
| 4 |
-
from huggingface_hub
|
| 5 |
-
|
| 6 |
-
ENDPOINT = "https://huggingface.co"
|
| 7 |
-
# ENDPOINT = "http://localhost:5564"
|
| 8 |
|
|
|
|
| 9 |
REPO_TYPES = ["model", "dataset", "space"]
|
| 10 |
|
| 11 |
-
|
| 12 |
-
def duplicate(source_repo, dst_repo, token, repo_type):
|
| 13 |
try:
|
| 14 |
-
if not repo_type in REPO_TYPES:
|
| 15 |
-
raise ValueError("need to select valid repo type")
|
| 16 |
_ = whoami(token)
|
| 17 |
# ^ this will throw if token is invalid
|
| 18 |
|
| 19 |
-
|
| 20 |
-
f"{ENDPOINT}/api/{repo_type}s/{source_repo}/duplicate",
|
| 21 |
-
headers=build_hf_headers(token=token),
|
| 22 |
-
json={"repository": dst_repo},
|
| 23 |
-
)
|
| 24 |
-
hf_raise_for_status(r)
|
| 25 |
|
| 26 |
-
|
|
|
|
|
|
|
| 27 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 28 |
return (
|
| 29 |
f'Find your repo <a href=\'{repo_url}\' target="_blank" style="text-decoration:underline">here</a>',
|
| 30 |
"sp.jpg",
|
|
@@ -44,17 +46,19 @@ def duplicate(source_repo, dst_repo, token, repo_type):
|
|
| 44 |
interface = gr.Interface(
|
| 45 |
fn=duplicate,
|
| 46 |
inputs=[
|
| 47 |
-
gr.Textbox(placeholder="Source
|
| 48 |
gr.Textbox(placeholder="Destination repository (e.g. osanseviero/dst)"),
|
| 49 |
gr.Textbox(placeholder="Write access token", type="password"),
|
|
|
|
|
|
|
| 50 |
gr.Dropdown(choices=REPO_TYPES, value="model"),
|
| 51 |
],
|
| 52 |
outputs=[
|
| 53 |
gr.Markdown(label="output"),
|
| 54 |
gr.Image(show_label=False),
|
| 55 |
],
|
| 56 |
-
title="
|
| 57 |
-
description="
|
| 58 |
article="<p>Find your write token at <a href='https://huggingface.co/settings/tokens' target='_blank'>token settings</a></p>",
|
| 59 |
allow_flagging="never",
|
| 60 |
live=False,
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
import requests
|
| 3 |
+
import subprocess
|
| 4 |
+
import os
|
| 5 |
from huggingface_hub import whoami
|
| 6 |
+
from huggingface_hub import HfApi
|
| 7 |
+
from huggingface_hub import login
|
|
|
|
|
|
|
| 8 |
|
| 9 |
+
api=HfApi()
|
| 10 |
REPO_TYPES = ["model", "dataset", "space"]
|
| 11 |
|
| 12 |
+
def duplicate(source_url, dst_repo, token, file_name, dest,repo_type):
|
|
|
|
| 13 |
try:
|
|
|
|
|
|
|
| 14 |
_ = whoami(token)
|
| 15 |
# ^ this will throw if token is invalid
|
| 16 |
|
| 17 |
+
login(token=token)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
|
| 19 |
+
subprocess.check_call([r"mkdir","-p","downloads"])
|
| 20 |
+
os.chdir('downloads')
|
| 21 |
+
subprocess.check_call([r"aria2c","-x16","--split=16",source_url])
|
| 22 |
|
| 23 |
+
api.upload_file(
|
| 24 |
+
path_or_fileobj=file_name,
|
| 25 |
+
path_in_repo=dest,
|
| 26 |
+
repo_id=dst_repo,
|
| 27 |
+
repo_type=repo_type
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
return (
|
| 31 |
f'Find your repo <a href=\'{repo_url}\' target="_blank" style="text-decoration:underline">here</a>',
|
| 32 |
"sp.jpg",
|
|
|
|
| 46 |
interface = gr.Interface(
|
| 47 |
fn=duplicate,
|
| 48 |
inputs=[
|
| 49 |
+
gr.Textbox(placeholder="Source URL (e.g. civitai.com/api/download/models/4324322534)"),
|
| 50 |
gr.Textbox(placeholder="Destination repository (e.g. osanseviero/dst)"),
|
| 51 |
gr.Textbox(placeholder="Write access token", type="password"),
|
| 52 |
+
gr.Textbox(placeholder="Post-download name of your file, cuz I'm lazy (e.g. stupidmodel.safetensors)"),
|
| 53 |
+
gr.Textbox(placeholder="Destination for your file (e.g. /models/Stable-diffusion/stupidmodel.safetensors)"),
|
| 54 |
gr.Dropdown(choices=REPO_TYPES, value="model"),
|
| 55 |
],
|
| 56 |
outputs=[
|
| 57 |
gr.Markdown(label="output"),
|
| 58 |
gr.Image(show_label=False),
|
| 59 |
],
|
| 60 |
+
title="Download a file to your repo!",
|
| 61 |
+
description="Download a file to your Hugging Face repository! You need to specify a write token obtained in https://hf.co/settings/tokens. This Space is a an experimental demo.",
|
| 62 |
article="<p>Find your write token at <a href='https://huggingface.co/settings/tokens' target='_blank'>token settings</a></p>",
|
| 63 |
allow_flagging="never",
|
| 64 |
live=False,
|
packages.txt
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
aria2
|