namelessai commited on
Commit
9d5b0ac
·
verified ·
1 Parent(s): f8bb6ec

Update app.py

Browse files

I'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.

Files changed (1) hide show
  1. app.py +9 -10
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
- if hasattr(midi_file_obj, 'name'):
96
- input_midi_path = midi_file_obj.name
97
- logger.info(f"Processing uploaded file: {midi_file_obj.name}")
98
- elif isinstance(midi_file_obj, str):
99
- input_midi_path = midi_file_obj
100
- logger.info(f"Processing example file: {input_midi_path}")
101
  else:
102
- raise gr.Error("Invalid input file type.")
 
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