Spaces:
Sleeping
Sleeping
Update app.py
Browse filesI've made two changes:
1. **Line 167:** Changed `type="file"` to `type="filepath"` to satisfy the version of Gradio we have.
2. **Lines 100-111:** Updated the `render_midi` function to reflect that the input will now *always* be a filepath string, which simplifies the logic.
app.py
CHANGED
|
@@ -75,10 +75,10 @@ def extract_examples():
|
|
| 75 |
logger.error(f"Error extracting examples: {e}", exc_info=True)
|
| 76 |
return [], f"⛔ **Error:** Could not extract examples. See console logs."
|
| 77 |
|
| 78 |
-
|
| 79 |
-
def render_midi(midi_file_obj, progress=gr.Progress(track_tqdm=True)):
|
| 80 |
"""
|
| 81 |
Renders a MIDI/KAR file to audio, now with progress updates and feedback.
|
|
|
|
| 82 |
"""
|
| 83 |
try:
|
| 84 |
# --- 1. Validation and Setup (Progress: 0% -> 20%) ---
|
|
@@ -92,14 +92,13 @@ def render_midi(midi_file_obj, progress=gr.Progress(track_tqdm=True)):
|
|
| 92 |
)
|
| 93 |
progress(0.1, desc="SoundFont found. Checking input...")
|
| 94 |
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
input_midi_path = midi_file_obj
|
| 100 |
-
logger.info(f"Processing example file: {input_midi_path}")
|
| 101 |
else:
|
| 102 |
-
|
|
|
|
| 103 |
progress(0.2, desc="Input file OK. Preparing output...")
|
| 104 |
|
| 105 |
# --- 2. Create Temp File (Progress: 20% -> 30%) ---
|
|
@@ -164,7 +163,7 @@ with gr.Blocks() as app: # <-- I've removed theme=gr.themes.Soft()
|
|
| 164 |
file_input = gr.File(
|
| 165 |
label="Upload .midi, .kar, or .mid file", # <-- Updated this line
|
| 166 |
file_types=[".midi", ".kar", ".mid"], # <-- Updated this line
|
| 167 |
-
type="file"
|
| 168 |
)
|
| 169 |
submit_btn = gr.Button("Render Audio", variant="primary")
|
| 170 |
|
|
|
|
| 75 |
logger.error(f"Error extracting examples: {e}", exc_info=True)
|
| 76 |
return [], f"⛔ **Error:** Could not extract examples. See console logs."
|
| 77 |
|
| 78 |
+
def render_midi(midi_file_path, progress=gr.Progress(track_tqdm=True)):
|
|
|
|
| 79 |
"""
|
| 80 |
Renders a MIDI/KAR file to audio, now with progress updates and feedback.
|
| 81 |
+
The input `midi_file_path` is always a string filepath.
|
| 82 |
"""
|
| 83 |
try:
|
| 84 |
# --- 1. Validation and Setup (Progress: 0% -> 20%) ---
|
|
|
|
| 92 |
)
|
| 93 |
progress(0.1, desc="SoundFont found. Checking input...")
|
| 94 |
|
| 95 |
+
# Simplified logic: Input is always a filepath string
|
| 96 |
+
if isinstance(midi_file_path, str):
|
| 97 |
+
input_midi_path = midi_file_path
|
| 98 |
+
logger.info(f"Processing input file: {input_midi_path}")
|
|
|
|
|
|
|
| 99 |
else:
|
| 100 |
+
logger.error(f"Invalid input file type: {type(midi_file_path)}")
|
| 101 |
+
raise gr.Error(f"Invalid input file type: {type(midi_file_path)}")
|
| 102 |
progress(0.2, desc="Input file OK. Preparing output...")
|
| 103 |
|
| 104 |
# --- 2. Create Temp File (Progress: 20% -> 30%) ---
|
|
|
|
| 163 |
file_input = gr.File(
|
| 164 |
label="Upload .midi, .kar, or .mid file", # <-- Updated this line
|
| 165 |
file_types=[".midi", ".kar", ".mid"], # <-- Updated this line
|
| 166 |
+
type="filepath" # <-- Changed from "file" to "filepath"
|
| 167 |
)
|
| 168 |
submit_btn = gr.Button("Render Audio", variant="primary")
|
| 169 |
|