Spaces:
Runtime error
Runtime error
Commit ·
e5007d2
1
Parent(s): b538a96
Ça marche sur le CPU
Browse filesFiles changed (3)
- README.md+2
- app.py+67-5
- environment.ymlAdded+40
9 unmodified lines1011129 unmodified lines---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference9 unmodified lines10111213149 unmodified lines---Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
123456789101112131429 unmodified lines444546474849505152535455565758596061626364656667import syssys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'amt/src')))import osimport shutilimport mimetypesimport gradio as grfrom model_helper import load_model_checkpoint, transcribefrom prepare_media import prepare_mediaMODEL_NAME = 'YPTF.MoE+Multi (noPS)' # @param ["YMT3+", "YPTF+Single (noPS)", "YPTF+Multi (PS)", "YPTF.MoE+Multi (noPS)", "YPTF.MoE+Multi (PS)"]PRECISION = '16'# if torch.cuda.is_available() else '32'# @param ["32", "bf16-mixed", "16"]PROJECT = '2024'29 unmodified lines}}model = load_model_checkpoint(args=MODELS[MODEL_NAME]["args"], device="cpu")#model.to("cuda")def handle_audio(file_path):# Guess extension from MIMEmime_type, _ = mimetypes.guess_type(file_path)ext = mimetypes.guess_extension(mime_type) or os.path.splitext(file_path)[1] or ".bin"output_path = f"received_audio{ext}"shutil.copy(file_path, output_path)return output_pathdemo = gr.Interface(fn=handle_audio,inputs=gr.Audio(type="filepath"),outputs=gr.File())if __name__ == "__main__":demo.launch()12345678910111213141516171829 unmodified lines48495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129import osimport syssys.path.append(os.path.abspath(os.path.join(os.path.dirname(__file__), 'amt/src')))import shutilimport mimetypesimport subprocessimport gradio as grimport torchaudiofrom model_helper import load_model_checkpoint, transcribefrom prepare_media import prepare_mediafrom typing import Tuple, Dict, LiteralMODEL_NAME = 'YPTF.MoE+Multi (noPS)' # @param ["YMT3+", "YPTF+Single (noPS)", "YPTF+Multi (PS)", "YPTF.MoE+Multi (noPS)", "YPTF.MoE+Multi (PS)"]PRECISION = '16'# if torch.cuda.is_available() else '32'# @param ["32", "bf16-mixed", "16"]PROJECT = '2024'29 unmodified lines}}log_file = 'amt/log.txt'model = load_model_checkpoint(args=MODELS[MODEL_NAME]["args"], device="cpu")#model.to("cuda")def prepare_media(source_path_or_url: os.PathLike,source_type: Literal['audio_filepath', 'youtube_url'],delete_video: bool = True,simulate = False) -> Dict:"""prepare media from source path or youtube, and return audio info"""# Get audio_fileif source_type == 'audio_filepath':audio_file = source_path_or_urlelif source_type == 'youtube_url':if os.path.exists('/download/yt_audio.mp3'):os.remove('/download/yt_audio.mp3')# Download from youtubewith open(log_file, 'w') as lf:audio_file = './downloaded/yt_audio'command = ['yt-dlp', '-x', source_path_or_url, '-f', 'bestaudio','-o', audio_file, '--audio-format', 'mp3', '--restrict-filenames','--extractor-retries', '10','--force-overwrites', '--username', 'oauth2', '--password', '', '-v']if simulate:command = command + ['-s']process = subprocess.Popen(command,stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)for line in iter(process.stdout.readline, ''):# Filter out unnecessary messagesprint(line)if "www.google.com/device" in line:hl_text = line.replace("https://www.google.com/device", "\033[93mhttps://www.google.com/device\x1b[0m").split()hl_text[-1] = "\x1b[31;1m" + hl_text[-1] + "\x1b[0m"lf.write(' '.join(hl_text)); lf.flush()elif "Authorization successful" in line or "Video unavailable" in line:lf.write(line); lf.flush()process.stdout.close()process.wait()audio_file += '.mp3'else:raise ValueError(source_type)# Create infoinfo = torchaudio.info(audio_file)return {"filepath": audio_file,"track_name": os.path.basename(audio_file).split('.')[0],"sample_rate": int(info.sample_rate),"bits_per_sample": int(info.bits_per_sample),"num_channels": int(info.num_channels),"num_frames": int(info.num_frames),"duration": int(info.num_frames / info.sample_rate),"encoding": str.lower(info.encoding),}def handle_audio(file_path):# Guess extension from MIMEmime_type, _ = mimetypes.guess_type(file_path)ext = mimetypes.guess_extension(mime_type) or os.path.splitext(file_path)[1] or ".bin"output_path = f"received_audio{ext}"shutil.copy(file_path, output_path)audio_info = prepare_media(output_path, source_type='audio_filepath')midifile_path = transcribe(model, audio_info)return midifile_pathdemo = gr.Interface(fn=handle_audio,inputs=gr.Audio(type="filepath"),outputs=gr.File(),)if __name__ == "__main__":demo.launch(server_port=7860)
12345678910111213141516171819202122232425262728293031323334353637383940name: gradiochannels: - conda-forgedependencies: - python=3.12 - lightning>=2.2.1 - deprecated - librosa - einops - transformers==4.45.1 - numpy==1.26.4 - wandb - annotated-types==0.7.0 - anyio==4.9.0 - blinker==1.9.0 - ertifi==2025.4.26 - click==8.1.8 - fastapi==0.115.12 - Flask==3.1.0 - h11==0.16.0 - idna==3.10 - importlib_metadata==8.6.1 - itsdangerous==2.2.0 - Jinja2==3.1.6 - MarkupSafe==2.1.5 - pip==25.1.1 - pydantic==2.11.4 - pydantic_core==2.33.2 - python-multipart==0.0.20 - setuptools==80.1.0 - sniffio==1.3.1 - starlette==0.46.2 - typing_extensions==4.13.2 - typing-inspection==0.4.0 - uvicorn==0.34.2 - Werkzeug==3.1.3 - wheel==0.45.1 - zipp==3.21.0pip: - --extra-index-url https://download.pytorch.org/whl/cu113README.md+2
app.py+67-5
environment.ymlAdded+40