Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,6 +4,7 @@ import glob
|
|
| 4 |
import re
|
| 5 |
import pandas as pd
|
| 6 |
import gradio as gr
|
|
|
|
| 7 |
from pypdf import PdfReader
|
| 8 |
import docx2txt
|
| 9 |
import speech_recognition as sr
|
|
@@ -21,6 +22,7 @@ os.makedirs(PROCESSED_DIR, exist_ok=True)
|
|
| 21 |
# -------------------------------------------------------------
|
| 22 |
# CORE PIPELINE LOGIC (TRANSCRIBER, PARSER, CHUNKER)
|
| 23 |
# -------------------------------------------------------------
|
|
|
|
| 24 |
def transcribe_video_audio(file_path):
|
| 25 |
try:
|
| 26 |
gr.Info(f"🎬 Extracting track layers from {os.path.basename(file_path)}...")
|
|
@@ -102,6 +104,7 @@ def structure_unsloth_rows(chunks, archetype):
|
|
| 102 |
rows.append({"text": chunk})
|
| 103 |
return rows
|
| 104 |
|
|
|
|
| 105 |
def execute_dataset_builder_pipeline(files, archetype, enable_chunking, chunk_size, chunk_overlap):
|
| 106 |
if not files:
|
| 107 |
return "⚠️ Target file loading queue is empty. Please upload files."
|
|
@@ -141,12 +144,10 @@ def execute_dataset_builder_pipeline(files, archetype, enable_chunking, chunk_si
|
|
| 141 |
# THEME TOGGLE SWITCH LOGIC ☀️/🌙
|
| 142 |
# -------------------------------------------------------------
|
| 143 |
def toggle_theme(current_theme):
|
| 144 |
-
# This toggles the utility class directly via Gradio's internal state mapping
|
| 145 |
if current_theme == "dark":
|
| 146 |
return gr.update(variant="light"), "light"
|
| 147 |
return gr.update(variant="dark"), "dark"
|
| 148 |
|
| 149 |
-
# CUSTOM JAVASCRIPT FOR THE THEME SWITCHING IN GRADIO RUNTIME
|
| 150 |
js_theme_switcher = """
|
| 151 |
function(theme) {
|
| 152 |
const documentElement = document.documentElement;
|
|
@@ -168,15 +169,14 @@ archetype_choices = [
|
|
| 168 |
"📖 Raw Knowledge Base (Continued Pre-Training)"
|
| 169 |
]
|
| 170 |
|
| 171 |
-
# Base Theme Configurations
|
| 172 |
custom_theme = gr.themes.Default(
|
| 173 |
primary_hue="green",
|
| 174 |
secondary_hue="zinc",
|
| 175 |
neutral_hue="zinc"
|
| 176 |
)
|
| 177 |
|
| 178 |
-
|
| 179 |
-
|
| 180 |
ui_theme_state = gr.State("dark")
|
| 181 |
|
| 182 |
with gr.Row():
|
|
@@ -200,14 +200,12 @@ with gr.Blocks(theme=custom_theme, title="Unsloth Studio Platform") as demo:
|
|
| 200 |
with gr.Column(scale=1):
|
| 201 |
log_monitor = gr.Textbox(label="🖥️ Core Engine Pipeline Logs", lines=15)
|
| 202 |
|
| 203 |
-
# Trigger execution conversion functionality
|
| 204 |
run_btn.click(
|
| 205 |
fn=execute_dataset_builder_pipeline,
|
| 206 |
inputs=[file_uploader, archetype_dropdown, chunk_toggle, size_input, overlap_input],
|
| 207 |
outputs=log_monitor
|
| 208 |
)
|
| 209 |
|
| 210 |
-
# Theme Switcher Trigger Interactions
|
| 211 |
theme_toggle_btn.click(
|
| 212 |
fn=toggle_theme,
|
| 213 |
inputs=[ui_theme_state],
|
|
@@ -218,9 +216,9 @@ with gr.Blocks(theme=custom_theme, title="Unsloth Studio Platform") as demo:
|
|
| 218 |
js=js_theme_switcher
|
| 219 |
)
|
| 220 |
|
| 221 |
-
# Initialize into dark layout out-of-the-box
|
| 222 |
demo.load(fn=lambda: "dark", outputs=ui_theme_state).then(fn=None, inputs=[ui_theme_state], js=js_theme_switcher)
|
| 223 |
|
| 224 |
if __name__ == "__main__":
|
| 225 |
-
|
|
|
|
| 226 |
|
|
|
|
| 4 |
import re
|
| 5 |
import pandas as pd
|
| 6 |
import gradio as gr
|
| 7 |
+
import spaces # <--- REQUIRED FOR HUGGING FACE ZEROGPU TIERS
|
| 8 |
from pypdf import PdfReader
|
| 9 |
import docx2txt
|
| 10 |
import speech_recognition as sr
|
|
|
|
| 22 |
# -------------------------------------------------------------
|
| 23 |
# CORE PIPELINE LOGIC (TRANSCRIBER, PARSER, CHUNKER)
|
| 24 |
# -------------------------------------------------------------
|
| 25 |
+
@spaces.GPU # <--- TELLS HUGGING FACE TO ALLOCATE GPU POWER FOR TRANSCRIBING
|
| 26 |
def transcribe_video_audio(file_path):
|
| 27 |
try:
|
| 28 |
gr.Info(f"🎬 Extracting track layers from {os.path.basename(file_path)}...")
|
|
|
|
| 104 |
rows.append({"text": chunk})
|
| 105 |
return rows
|
| 106 |
|
| 107 |
+
@spaces.GPU # <--- DECORATES THE TOP LEVEL CONVERSION Pipeline FOR ZEROGPU STABILITY
|
| 108 |
def execute_dataset_builder_pipeline(files, archetype, enable_chunking, chunk_size, chunk_overlap):
|
| 109 |
if not files:
|
| 110 |
return "⚠️ Target file loading queue is empty. Please upload files."
|
|
|
|
| 144 |
# THEME TOGGLE SWITCH LOGIC ☀️/🌙
|
| 145 |
# -------------------------------------------------------------
|
| 146 |
def toggle_theme(current_theme):
|
|
|
|
| 147 |
if current_theme == "dark":
|
| 148 |
return gr.update(variant="light"), "light"
|
| 149 |
return gr.update(variant="dark"), "dark"
|
| 150 |
|
|
|
|
| 151 |
js_theme_switcher = """
|
| 152 |
function(theme) {
|
| 153 |
const documentElement = document.documentElement;
|
|
|
|
| 169 |
"📖 Raw Knowledge Base (Continued Pre-Training)"
|
| 170 |
]
|
| 171 |
|
|
|
|
| 172 |
custom_theme = gr.themes.Default(
|
| 173 |
primary_hue="green",
|
| 174 |
secondary_hue="zinc",
|
| 175 |
neutral_hue="zinc"
|
| 176 |
)
|
| 177 |
|
| 178 |
+
# Removed theme and title parameters from constructor to prevent Gradio 6 layout deprecation warnings
|
| 179 |
+
with gr.Blocks() as demo:
|
| 180 |
ui_theme_state = gr.State("dark")
|
| 181 |
|
| 182 |
with gr.Row():
|
|
|
|
| 200 |
with gr.Column(scale=1):
|
| 201 |
log_monitor = gr.Textbox(label="🖥️ Core Engine Pipeline Logs", lines=15)
|
| 202 |
|
|
|
|
| 203 |
run_btn.click(
|
| 204 |
fn=execute_dataset_builder_pipeline,
|
| 205 |
inputs=[file_uploader, archetype_dropdown, chunk_toggle, size_input, overlap_input],
|
| 206 |
outputs=log_monitor
|
| 207 |
)
|
| 208 |
|
|
|
|
| 209 |
theme_toggle_btn.click(
|
| 210 |
fn=toggle_theme,
|
| 211 |
inputs=[ui_theme_state],
|
|
|
|
| 216 |
js=js_theme_switcher
|
| 217 |
)
|
| 218 |
|
|
|
|
| 219 |
demo.load(fn=lambda: "dark", outputs=ui_theme_state).then(fn=None, inputs=[ui_theme_state], js=js_theme_switcher)
|
| 220 |
|
| 221 |
if __name__ == "__main__":
|
| 222 |
+
# Theme configuration parameters passed to launch method matching Gradio 6 guidelines
|
| 223 |
+
demo.launch(theme=custom_theme)
|
| 224 |
|