File size: 10,275 Bytes
80b326d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
{
  "cells": [
    {
      "cell_type": "markdown",
      "source": [
        "# ViralCutter\n",
        "Uma alternativa gratuita ao `opus.pro` e ao `vidyo.ai`"
      ],
      "metadata": {
        "id": "pa36OeArowme"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# Suporte em:\n",
        "[![](https://dcbadge.limes.pink/api/server/tAdPHFAbud)](https://discord.gg/tAdPHFAbud)"
      ],
      "metadata": {
        "id": "6Q-ljfsw1unE"
      }
    },
    {
      "cell_type": "markdown",
      "source": [
        "# TODO📝\n",
        "- [x] Release code\n",
        "- [ ] Huggingface SpaceDemo\n",
        "- [x] Two face in the cut\n",
        "- [x] Custom caption and burn\n",
        "- [x] Make the code faster\n",
        "- [ ] More types of framing beyond 9:16"
      ],
      "metadata": {
        "id": "0o3KcBT5wzws"
      }
    },
    {
      "cell_type": "code",
      "execution_count": 1,
      "metadata": {
        "id": "e76jiRnjONmj",
        "cellView": "form",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "6e8baa39-5e40-45d7-e247-a70eddbc1a79"
      },
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "✅ Instalação V7 Finalizada!\n",
            "- Transformers 4.46.3 (Compatível com Alinhamento): INSTALADO\n",
            "- Torch 2.3.1: ATIVO\n"
          ]
        }
      ],
      "source": [
        "#@title 🛠️ Instalação\n",
        "import os\n",
        "import subprocess\n",
        "import shutil\n",
        "from IPython.display import clear_output\n",
        "\n",
        "# 1. Limpeza TOTAL\n",
        "print(\"🧹 Limpando instalação anterior...\")\n",
        "%cd /content\n",
        "if os.path.exists(\"ViralCutter\"):\n",
        "    shutil.rmtree(\"ViralCutter\")\n",
        "\n",
        "!git clone -b dev https://github.com/RafaelGodoyEbert/ViralCutter.git\n",
        "%cd /content/ViralCutter\n",
        "\n",
        "print(\"⏳ Instalando gerenciador UV e drivers do sistema...\")\n",
        "\n",
        "# 2. Instalar UV e Drivers Linux\n",
        "subprocess.run(['pip', 'install', 'uv'], check=True)\n",
        "subprocess.run('sudo apt update -y && sudo apt install -y libcudnn8 ffmpeg xvfb', shell=True, check=True)\n",
        "\n",
        "# 3. Criar Ambiente Virtual\n",
        "print(\"⏳ Criando ambiente virtual...\")\n",
        "subprocess.run(['uv', 'venv', '.venv'], check=True)\n",
        "\n",
        "# 4. INSTALAÇÃO DAS DEPENDÊNCIAS\n",
        "print(\"⏳ Instalando Bibliotecas...\")\n",
        "\n",
        "# Passo A: WhisperX e Requisitos Básicos (Deixe instalar o que quiserem)\n",
        "cmds_fase_1 = [\n",
        "    \"uv pip install --python .venv git+https://github.com/m-bain/whisperx.git\",\n",
        "    \"uv pip install --python .venv -r requirements.txt\",\n",
        "    \"uv pip install --python .venv yt-dlp pytubefix\",\n",
        "    \"uv pip install yt_dlp\"\n",
        "]\n",
        "\n",
        "for cmd in cmds_fase_1:\n",
        "    subprocess.run(cmd, shell=True, check=True)\n",
        "\n",
        "# Passo B: CORREÇÃO DE ALINHAMENTO E GEMINI\n",
        "# - google-generativeai: Para o Gemini funcionar\n",
        "# - pandas: Para separar palavras\n",
        "# - transformers==4.46.3: VERSÃO CRÍTICA. Versões mais novas exigem Torch 2.6 e quebram o alinhamento.\n",
        "# - accelerate: Ajuda no carregamento do modelo\n",
        "print(\"🔨 Aplicando downgrade estratégico no Transformers...\")\n",
        "extra_libs = [\n",
        "    \"uv pip install --python .venv google-generativeai\",\n",
        "    \"uv pip install --python .venv pandas\",\n",
        "    \"uv pip install --python .venv onnxruntime-gpu\",\n",
        "    \"uv pip install --python .venv transformers==4.46.3 accelerate>=0.26.0\"\n",
        "]\n",
        "\n",
        "for cmd in extra_libs:\n",
        "    subprocess.run(cmd, shell=True, check=True)\n",
        "\n",
        "# Passo C: O MARTELO FINAL (Torch 2.3.1 Estável)\n",
        "# Reinstalamos por último para garantir que nada atualizou ele sem querer\n",
        "print(\"🔨 Forçando versão estável do Torch (2.3.1)...\")\n",
        "cmd_fix_torch = (\n",
        "    \"uv pip install --python .venv \"\n",
        "    \"torch==2.3.1+cu121 torchvision==0.18.1+cu121 torchaudio==2.3.1+cu121 \"\n",
        "    \"--index-url https://download.pytorch.org/whl/cu121\"\n",
        ")\n",
        "subprocess.run(cmd_fix_torch, shell=True, check=True)\n",
        "\n",
        "# Passo D: Trava do Numpy\n",
        "print(\"🔨 Travando Numpy...\")\n",
        "subprocess.run(\"uv pip install --python .venv 'numpy<2.0' setuptools==69.5.1\", shell=True, check=True)\n",
        "\n",
        "# Passo E: Correção de Visão Computacional (CRÍTICO)\n",
        "print(\"🔨 Corrigindo InsightFace e MediaPipe...\")\n",
        "\n",
        "# 1. Garante que o InsightFace tenha o motor necessário (evita que ele falhe)\n",
        "subprocess.run(\"uv pip install --python .venv insightface onnxruntime-gpu\", shell=True, check=True)\n",
        "\n",
        "# 2. Limpeza Radical e Reinstalação do MediaPipe\n",
        "# Remove versões quebradas\n",
        "subprocess.run(\"uv pip uninstall --python .venv mediapipe protobuf flatbuffers\", shell=True)\n",
        "\n",
        "# 3. Instala versão FLEXÍVEL respeitando limites críticos\n",
        "# mediapipe>=0.10.0: Pega a versão mais recente compatível com Py3.12\n",
        "# protobuf>=3.20,<5.0: Garante compatibilidade sem quebrar o sistema antigo\n",
        "subprocess.run(\"uv pip install --python .venv 'mediapipe>=0.10.0' 'protobuf>=3.20,<5.0' 'flatbuffers>=2.0'\", shell=True, check=True)\n",
        "\n",
        "# 5. Configurar Monitor\n",
        "os.system('Xvfb :1 -screen 0 2560x1440x8 &')\n",
        "os.environ['DISPLAY'] = ':1.0'\n",
        "\n",
        "clear_output()\n",
        "print(\"✅ Instalação V7 Finalizada!\")\n",
        "print(\"- Transformers 4.46.3 (Compatível com Alinhamento): INSTALADO\")\n",
        "print(\"- Torch 2.3.1: ATIVO\")"
      ]
    },
    {
      "cell_type": "code",
      "source": [
        "#@title 🚀 Configuração e Execução\n",
        "import os\n",
        "\n",
        "%cd /content/ViralCutter\n",
        "\n",
        "# 1. Configura o \"Display\" falso (para evitar erros de interface gráfica)\n",
        "os.system('Xvfb :1 -screen 0 2560x1440x8 &')\n",
        "os.environ['DISPLAY'] = ':1.0'\n",
        "\n",
        "# 2. CORREÇÃO DO ERRO ATUAL:\n",
        "# Forçamos o Matplotlib a usar o backend 'Agg' (modo sem cabeça/headless)\n",
        "# Isso ignora o 'module://matplotlib_inline.backend_inline' que o Colab força e quebra o script.\n",
        "os.environ['MPLBACKEND'] = 'Agg'\n",
        "\n",
        "print(\"🚀 Iniciando ViralCutter usando o ambiente virtual...\")\n",
        "print(\"⚠️ Ignore os avisos de 'UserWarning', aguarde o link public URL.\")\n",
        "\n",
        "# Executa usando o Python do ambiente virtual\n",
        "!/content/ViralCutter/.venv/bin/python webui/app.py --colab"
      ],
      "metadata": {
        "id": "DNn8ZKJdD5XG",
        "colab": {
          "base_uri": "https://localhost:8080/"
        },
        "outputId": "fd4689bd-f036-42de-fc7e-67854af40d81"
      },
      "execution_count": null,
      "outputs": [
        {
          "output_type": "stream",
          "name": "stdout",
          "text": [
            "/content/ViralCutter\n",
            "🚀 Iniciando ViralCutter usando o ambiente virtual...\n",
            "⚠️ Ignore os avisos de 'UserWarning', aguarde o link public URL.\n",
            "/content/ViralCutter/webui/app.py:204: UserWarning: The parameters have been moved from the Blocks constructor to the launch() method in Gradio 6.0: theme, css. Please pass these parameters to launch() instead.\n",
            "  with gr.Blocks(title=i18n(\"ViralCutter WebUI\"), theme=gr.themes.Default(primary_hue=\"blue\", neutral_hue=\"slate\"), css=css) as demo:\n",
            "Running in Colab mode. Generating public link...\n",
            "* Running on local URL:  http://127.0.0.1:7860\n",
            "* Running on public URL: https://7f3b04ec670707105b.gradio.live\n",
            "\n",
            "This share link expires in 1 week. For free permanent hosting and GPU upgrades, run `gradio deploy` from the terminal in the working directory to deploy to Hugging Face Spaces (https://huggingface.co/spaces)\n"
          ]
        }
      ]
    },
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "nEIsMZLwJ5kD"
      },
      "source": [
        "#Créditos\n",
        "\n",
        "Inspirado no [reels clips automator](https://github.com/eddieoz/reels-clips-automator) e no [YoutubeVideoToAIPoweredShorts](https://github.com/Fitsbit/YoutubeVideoToAIPoweredShorts)<br>\n",
        "\n",
        "---\n",
        "![Rafa.png](https://i.imgur.com/cGknQpU.png;base64)\n",
        "\n",
        "Desenvolvido por **Rafa.Godoy**<br>\n",
        "[ ![GitHub](https://img.shields.io/badge/github-%23121011.svg?style=for-the-badge&logo=github&logoColor=white) ](https://github.com/rafaelGodoyEbert)<br>\n",
        "[ ![X](https://img.shields.io/twitter/url?url=https%3A%2F%2Ftwitter.com%2FGodoyEbert) ](https://twitter.com/GodoyEbert)<br>\n",
        "[Instagram](https://www.instagram.com/rafael.godoy.ebert/)<br>\n",
        "[ ![](https://dcbadge.vercel.app/api/server/aihubbrasil) ](https://discord.gg/aihubbrasil)"
      ]
    },
    {
      "cell_type": "markdown",
      "source": [
        "`0.1v Alpha`<br>\n",
        "\n",
        "Apenas uma alternativa gratuita ao `opus.pro` e ao `vidyo.ai`<br>\n"
      ],
      "metadata": {
        "id": "tpLJmPqGT5_u"
      }
    }
  ],
  "metadata": {
    "accelerator": "GPU",
    "colab": {
      "gpuType": "T4",
      "provenance": []
    },
    "kernelspec": {
      "display_name": "Python 3",
      "name": "python3"
    },
    "language_info": {
      "name": "python"
    }
  },
  "nbformat": 4,
  "nbformat_minor": 0
}