Spaces:
Runtime error
Runtime error
Create utils/huggingface_utils.py
Browse files- utils/huggingface_utils.py +58 -0
utils/huggingface_utils.py
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from huggingface_hub import HfApi, Repository
|
| 2 |
+
import os
|
| 3 |
+
import json
|
| 4 |
+
|
| 5 |
+
class HuggingFaceUploader:
|
| 6 |
+
def __init__(self, config):
|
| 7 |
+
self.config = config.get('huggingface', {})
|
| 8 |
+
self.api = HfApi()
|
| 9 |
+
self.repo_id = self.config.get('repo_id')
|
| 10 |
+
self.token = self.config.get('token')
|
| 11 |
+
|
| 12 |
+
def upload_directory(self, directory_path):
|
| 13 |
+
"""Faz upload de um diretório para o Hugging Face"""
|
| 14 |
+
if not self.repo_id:
|
| 15 |
+
raise ValueError("repo_id não configurado")
|
| 16 |
+
|
| 17 |
+
try:
|
| 18 |
+
# Criar ou clonar repositório
|
| 19 |
+
repo = Repository(
|
| 20 |
+
local_dir=directory_path,
|
| 21 |
+
clone_from=self.repo_id,
|
| 22 |
+
use_auth_token=self.token
|
| 23 |
+
)
|
| 24 |
+
|
| 25 |
+
# Fazer commit e push
|
| 26 |
+
repo.push_to_hub(commit_message="Add processed LIBRAS video data")
|
| 27 |
+
|
| 28 |
+
return f"https://huggingface.co/spaces/{self.repo_id}"
|
| 29 |
+
|
| 30 |
+
except Exception as e:
|
| 31 |
+
print(f"Erro no upload: {e}")
|
| 32 |
+
return None
|
| 33 |
+
|
| 34 |
+
def create_dataset_card(self, directory_path, metadata):
|
| 35 |
+
"""Cria um dataset card para o Hugging Face"""
|
| 36 |
+
card_content = f"""
|
| 37 |
+
---
|
| 38 |
+
language:
|
| 39 |
+
- pt
|
| 40 |
+
- libras
|
| 41 |
+
tags:
|
| 42 |
+
- computer-vision
|
| 43 |
+
- sign-language
|
| 44 |
+
- libras
|
| 45 |
+
- mediapipe
|
| 46 |
+
- keypoints
|
| 47 |
+
datasets:
|
| 48 |
+
- libras-processing
|
| 49 |
+
---
|
| 50 |
+
|
| 51 |
+
# Dataset de Vídeos em LIBRAS Processados
|
| 52 |
+
|
| 53 |
+
## Descrição
|
| 54 |
+
Este dataset contém vídeos em Língua Brasileira de Sinais (LIBRAS) processados com extração de keypoints usando MediaPipe.
|
| 55 |
+
|
| 56 |
+
## Metadados
|
| 57 |
+
```json
|
| 58 |
+
{json.dumps(metadata, indent=2)}
|