File size: 1,193 Bytes
3d9e285 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
import gradio as gr
import os
import zipfile
from huggingface_hub import HfApi, Repository
# Initialize Hugging Face API
api = HfApi()
# Function to upload and push to Hugging Face
def push_to_huggingface(repo_name, zip_file, hf_token):
# Step 1: Unzip the directory
with zipfile.ZipFile(zip_file.name, 'r') as zip_ref:
unzip_dir = f"./{repo_name}"
zip_ref.extractall(unzip_dir)
# Step 2: Create repository on Hugging Face
api.create_repo(repo_name, token=hf_token)
# Step 3: Push the unzipped directory to Hugging Face
repo = Repository(local_dir=unzip_dir, clone_from=f"{hf_token}/{repo_name}")
repo.push_to_hub()
return f"Repository '{repo_name}' has been pushed to Hugging Face Hub successfully."
# Gradio Interface
interface = gr.Interface(
fn=push_to_huggingface,
inputs=[
"text", # Repository name
"file", # Zipped directory
"text" # Hugging Face Token
],
outputs="text",
title="Push Directory to Hugging Face",
description="Upload a zipped directory and push it to the Hugging Face Hub."
)
# Launch the interface
if __name__ == "__main__":
interface.launch()
|