TEDDyx86 commited on
Commit
063f6de
·
1 Parent(s): 839adf6

Deployment: Synchronized system with new model architecture and streaming notebook v3.0

Browse files
ConfereAI_FastTrain_Colab_v3.ipynb ADDED
@@ -0,0 +1,198 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "nbformat": 4,
3
+ "nbformat_minor": 0,
4
+ "metadata": {
5
+ "colab": {
6
+ "provenance": [],
7
+ "gpuType": "T4"
8
+ },
9
+ "kernelspec": {
10
+ "name": "python3",
11
+ "display_name": "Python 3"
12
+ },
13
+ "language_info": {
14
+ "name": "python"
15
+ }
16
+ },
17
+ "cells": [
18
+ {
19
+ "cell_type": "markdown",
20
+ "metadata": {
21
+ "id": "header"
22
+ },
23
+ "source": [
24
+ "# 🚀 ConfereAI - Fast Training v3.0 (Streaming Edition)\n",
25
+ "Este notebook permite treinar o motor neural do ConfereAI utilizando a GPU do Colab e datasets do Hugging Face sem download.\n",
26
+ "\n",
27
+ "**Novidade:** Suporte a Streaming para datasets gigantes (ex: BRSpeech-DF 243GB).\n",
28
+ "\n",
29
+ "**Instruções:**\n",
30
+ "1. Selecione **T4 GPU** em `Ambiente de Execução`.\n",
31
+ "2. Escolha se quer fazer upload de um ZIP ou usar um dataset remoto.\n",
32
+ "3. Execute as células."
33
+ ]
34
+ },
35
+ {
36
+ "cell_type": "code",
37
+ "execution_count": null,
38
+ "metadata": {
39
+ "id": "setup"
40
+ },
41
+ "outputs": [],
42
+ "source": [
43
+ "# @title 1. Instalar Dependências\n",
44
+ "!pip install -q transformers[torch] datasets librosa soundfile huggingface_hub accelerate"
45
+ ]
46
+ },
47
+ {
48
+ "cell_type": "code",
49
+ "execution_count": null,
50
+ "metadata": {
51
+ "id": "config"
52
+ },
53
+ "outputs": [],
54
+ "source": [
55
+ "# @title 2. Configurações do Hugging Face\n",
56
+ "HF_TOKEN = \"\" # @param {type:\"string\"}\n",
57
+ "REPO_ID = \"TEDDyx86/confereai-wav2vec2\" # @param {type:\"string\"}\n",
58
+ "\n",
59
+ "from huggingface_hub import HfApi, login\n",
60
+ "if HF_TOKEN:\n",
61
+ " login(token=HF_TOKEN)\n",
62
+ "else:\n",
63
+ " print(\"❌ Por favor, insira o seu HF_TOKEN!\")"
64
+ ]
65
+ },
66
+ {
67
+ "cell_type": "code",
68
+ "execution_count": null,
69
+ "metadata": {
70
+ "id": "upload"
71
+ },
72
+ "outputs": [],
73
+ "source": [
74
+ "# @title 3. Carregamento do Dataset\n",
75
+ "DATASET_SOURCE = \"Hugging Face Hub\" # @param [\"Upload ZIP\", \"Hugging Face Hub\"]\n",
76
+ "REMOTE_DATASET = \"AKCIT-Deepfake/BRSpeech-DF\" # @param {type:\"string\"}\n",
77
+ "\n",
78
+ "import os\n",
79
+ "import shutil\n",
80
+ "import zipfile\n",
81
+ "from google.colab import files\n",
82
+ "from datasets import load_dataset\n",
83
+ "\n",
84
+ "DATASET_DIR = \"dataset_training\"\n",
85
+ "RAW_DATASET = None\n",
86
+ "\n",
87
+ "if DATASET_SOURCE == \"Upload ZIP\":\n",
88
+ " uploaded = files.upload()\n",
89
+ " if uploaded:\n",
90
+ " dataset_zip = list(uploaded.keys())[0]\n",
91
+ " if os.path.exists(DATASET_DIR): shutil.rmtree(DATASET_DIR)\n",
92
+ " os.makedirs(DATASET_DIR)\n",
93
+ " with zipfile.ZipFile(dataset_zip, 'r') as zip_ref:\n",
94
+ " zip_ref.extractall(DATASET_DIR)\n",
95
+ " print(f\"✅ Dataset local extraído em: {DATASET_DIR}\")\n",
96
+ "else:\n",
97
+ " print(f\"🌐 Conectando a {REMOTE_DATASET} via Streaming...\")\n",
98
+ " RAW_DATASET = load_dataset(REMOTE_DATASET, streaming=True)\n",
99
+ " print(f\"✅ Pronto para treinar com {REMOTE_DATASET}\")"
100
+ ]
101
+ },
102
+ {
103
+ "cell_type": "code",
104
+ "execution_count": null,
105
+ "metadata": {
106
+ "id": "training"
107
+ },
108
+ "outputs": [],
109
+ "source": [
110
+ "# @title 4. Executar Treinamento (Fine-Tuning)\n",
111
+ "import torch\n",
112
+ "from torch.utils.data import Dataset, IterableDataset\n",
113
+ "from transformers import Wav2Vec2FeatureExtractor, Wav2Vec2ForSequenceClassification, Trainer, TrainingArguments\n",
114
+ "import librosa\n",
115
+ "\n",
116
+ "BASE_MODEL = \"HyperMoon/wav2vec2-base-960h-finetuned-deepfake\"\n",
117
+ "OUTPUT_DIR = \"local_finetuned_model\"\n",
118
+ "processor = Wav2Vec2FeatureExtractor.from_pretrained(BASE_MODEL)\n",
119
+ "\n",
120
+ "class LocalDeepfakeDataset(Dataset):\n",
121
+ " def __init__(self, root_dir, processor):\n",
122
+ " self.files = []\n",
123
+ " self.processor = processor\n",
124
+ " for label, folder in enumerate(['real', 'fake']):\n",
125
+ " path = os.path.join(root_dir, folder)\n",
126
+ " if os.path.exists(path):\n",
127
+ " for f in os.listdir(path):\n",
128
+ " if f.endswith(('.wav', '.mp3', '.flac')):\n",
129
+ " self.files.append({\"path\": os.path.join(path, f), \"label\": label})\n",
130
+ "\n",
131
+ " def __len__(self): return len(self.files)\n",
132
+ " def __getitem__(self, idx):\n",
133
+ " item = self.files[idx]\n",
134
+ " speech, _ = librosa.load(item[\"path\"], sr=16000)\n",
135
+ " inputs = self.processor(speech, sampling_rate=16000, return_tensors=\"pt\", padding=\"max_length\", max_length=160000, truncation=True)\n",
136
+ " return {\"input_values\": inputs.input_values[0], \"labels\": torch.tensor(item[\"label\"], dtype=torch.long)}\n",
137
+ "\n",
138
+ "class StreamingHFDataset(IterableDataset):\n",
139
+ " def __init__(self, hf_dataset, processor):\n",
140
+ " self.hf_dataset = hf_dataset\n",
141
+ " self.processor = processor\n",
142
+ " def __iter__(self):\n",
143
+ " for example in self.hf_dataset['train']:\n",
144
+ " audio = example['audio']\n",
145
+ " label = example['label']\n",
146
+ " inputs = self.processor(audio['array'], sampling_rate=16000, return_tensors=\"pt\", padding=\"max_length\", max_length=160000, truncation=True)\n",
147
+ " yield {\"input_values\": inputs.input_values[0], \"labels\": torch.tensor(label, dtype=torch.long)}\n",
148
+ "\n",
149
+ "if DATASET_SOURCE == \"Upload ZIP\":\n",
150
+ " train_data = LocalDeepfakeDataset(DATASET_DIR, processor)\n",
151
+ "else:\n",
152
+ " train_data = StreamingHFDataset(RAW_DATASET, processor)\n",
153
+ "\n",
154
+ "model = Wav2Vec2ForSequenceClassification.from_pretrained(BASE_MODEL, num_labels=2, ignore_mismatched_sizes=True)\n",
155
+ "if hasattr(model, 'freeze_feature_extractor'): model.freeze_feature_extractor()\n",
156
+ "\n",
157
+ "training_args = TrainingArguments(\n",
158
+ " output_dir=\"./results\",\n",
159
+ " num_train_epochs=3,\n",
160
+ " per_device_train_batch_size=4,\n",
161
+ " gradient_accumulation_steps=4,\n",
162
+ " learning_rate=3e-5,\n",
163
+ " logging_steps=10,\n",
164
+ " max_steps=1000 if DATASET_SOURCE != \"Upload ZIP\" else -1, \n",
165
+ " report_to=\"none\"\n",
166
+ ")\n",
167
+ "\n",
168
+ "trainer = Trainer(model=model, args=training_args, train_dataset=train_data)\n",
169
+ "print(\"🚀 Iniciando treinamento...\")\n",
170
+ "trainer.train()\n",
171
+ "\n",
172
+ "model.save_pretrained(OUTPUT_DIR)\n",
173
+ "processor.save_pretrained(OUTPUT_DIR)\n",
174
+ "print(f\"✅ Modelo salvo em {OUTPUT_DIR}\")"
175
+ ]
176
+ },
177
+ {
178
+ "cell_type": "code",
179
+ "execution_count": null,
180
+ "metadata": {
181
+ "id": "push"
182
+ },
183
+ "outputs": [],
184
+ "source": [
185
+ "# @title 5. Sincronizar com Hugging Face (Model Repo)\n",
186
+ "api = HfApi()\n",
187
+ "api.upload_folder(\n",
188
+ " folder_path=OUTPUT_DIR,\n",
189
+ " repo_id=REPO_ID,\n",
190
+ " repo_type=\"model\",\n",
191
+ " token=HF_TOKEN,\n",
192
+ " commit_message=\"🤖 Auto-Update: Cérebro aprimorado com dataset BR\"\n",
193
+ ")\n",
194
+ "print(f\"✨ Sucesso! O novo cérebro está disponível em: https://huggingface.co/{REPO_ID}\")"
195
+ ]
196
+ }
197
+ ]
198
+ }
dashboard/index.html CHANGED
@@ -277,7 +277,7 @@
277
 
278
  <div class="footer-links">
279
 
280
- <a href="https://huggingface.co/HyperMoon/wav2vec2-base-960h-finetuned-deepfake" target="_blank">Modelo IA</a>
281
 
282
  </div>
283
 
 
277
 
278
  <div class="footer-links">
279
 
280
+ <a href="https://huggingface.co/TEDDyx86/confereai-wav2vec2" target="_blank">Cérebro Pessoal v1.0</a>
281
 
282
  </div>
283
 
execution/inference_wav2vec.py CHANGED
@@ -10,7 +10,8 @@ import os
10
  LOCAL_MODEL_DIR = "./local_finetuned_model"
11
  # Prioridade: 1. Pasta Local (Upload direto) | 2. Repo Customizado (Variável de Ambiente) | 3. Modelo Base
12
  CUSTOM_MODEL_REPO = os.environ.get("CUSTOM_MODEL_REPO", "TEDDyx86/confereai-wav2vec2")
13
- BASE_MODEL = "HyperMoon/wav2vec2-base-960h-finetuned-deepfake"
 
14
 
15
  # Singleton para carregar o modelo e processador apenas uma vez
16
  _feature_extractor = None
 
10
  LOCAL_MODEL_DIR = "./local_finetuned_model"
11
  # Prioridade: 1. Pasta Local (Upload direto) | 2. Repo Customizado (Variável de Ambiente) | 3. Modelo Base
12
  CUSTOM_MODEL_REPO = os.environ.get("CUSTOM_MODEL_REPO", "TEDDyx86/confereai-wav2vec2")
13
+ # Modelo especializado treinado pelo usuário (Cérebro Pessoal)
14
+ BASE_MODEL = "TEDDyx86/confereai-wav2vec2"
15
 
16
  # Singleton para carregar o modelo e processador apenas uma vez
17
  _feature_extractor = None