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()