当前位置: 首页 > news >正文

如何用asp做网站爱站网爱情电影网

如何用asp做网站,爱站网爱情电影网,做平面那个网站素材好,广州电子商务网站建设费用使用的是开源模型MusicGen,它可以根据文字描述或者已有旋律生成高质量的音乐(32kHz),其原理是通过生成Encodec token然后再解码为音频,模型利用EnCodec神经音频编解码器来从原始波形中学习离散音频token。EnCodec将音频信号映射到一个或多个并…

使用的是开源模型MusicGen,它可以根据文字描述或者已有旋律生成高质量的音乐(32kHz),其原理是通过生成Encodec token然后再解码为音频,模型利用EnCodec神经音频编解码器来从原始波形中学习离散音频token。EnCodec将音频信号映射到一个或多个并行的离散token流。然后使用一个自回归语言模型来递归地对EnCodec中的音频token进行建模。生成的token然后被馈送到EnCodec解码器,将它们映射回音频空间并获取输出波形。最后,可以使用不同类型的条件模型来控制生成

在这里插入图片描述

准备运行环境

拷贝模型文件

import moxing as mox
mox.file.copy_parallel('obs://modelarts-labs-bj4-v2/case_zoo/MusicGen/model/', 'model')
mox.file.copy_parallel('obs://modelarts-labs-bj4-v2/course/ModelBox/opus-mt-zh-en', 'opus-mt-zh-en')
mox.file.copy_parallel('obs://modelarts-labs-bj4-v2/course/ModelBox/frpc_linux_amd64', 'frpc_linux_amd64')

基于Python3.9.15 创建虚拟运行环境

!/home/ma-user/anaconda3/bin/conda create -n python-3.9.15 python=3.9.15 -y --override-channels --channel https://mirrors.tuna.tsinghua.edu.cn/anaconda/pkgs/main
!/home/ma-user/anaconda3/envs/python-3.9.15/bin/pip install ipykernel

修改Kernel文件

import json
import osdata = {"display_name": "python-3.9.15","env": {"PATH": "/home/ma-user/anaconda3/envs/python-3.9.15/bin:/home/ma-user/anaconda3/envs/python-3.7.10/bin:/modelarts/authoring/notebook-conda/bin:/opt/conda/bin:/usr/local/nvidia/bin:/usr/local/cuda/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/home/ma-user/modelarts/ma-cli/bin:/home/ma-user/modelarts/ma-cli/bin:/home/ma-user/anaconda3/envs/PyTorch-1.8/bin"},"language": "python","argv": ["/home/ma-user/anaconda3/envs/python-3.9.15/bin/python","-m","ipykernel","-f","{connection_file}"]
}if not os.path.exists("/home/ma-user/anaconda3/share/jupyter/kernels/python-3.9.15/"):os.mkdir("/home/ma-user/anaconda3/share/jupyter/kernels/python-3.9.15/")with open('/home/ma-user/anaconda3/share/jupyter/kernels/python-3.9.15/kernel.json', 'w') as f:json.dump(data, f, indent=4)print('kernel.json文件修改完毕')

安装依赖

!pip install --upgrade pip
!pip install torch==2.0.1 torchvision==0.15.2
!pip install sentencepiece 
!pip install librosa
!pip install --upgrade transformers scipy
!pip install gradio==4.16.0 -i https://pypi.tuna.tsinghua.edu.cn/simple
!cp frpc_linux_amd64 /home/ma-user/anaconda3/envs/python-3.9.15/lib/python3.9/site-packages/gradio/frpc_linux_amd64_v0.2
!chmod +x /home/ma-user/anaconda3/envs/python-3.9.15/lib/python3.9/site-packages/gradio/frpc_linux_amd64_v0.2

模型测试

模型推理

#@title Default title text 
import torch
from transformers import AutoProcessor, MusicgenForConditionalGeneration, pipelinezh2en = pipeline("translation", model="./opus-mt-zh-en")
prompt = "六一儿童节  男孩专属节奏感强的音乐"
prompt = zh2en(prompt)[0].get("translation_text")
print(prompt)device = 'cuda' if torch.cuda.is_available() else 'cpu'
processor = AutoProcessor.from_pretrained("./model/")
model = MusicgenForConditionalGeneration.from_pretrained("./model/")
model.to(device)inputs = processor(text=[prompt],padding=True,return_tensors="pt",
).to(device)# max_new_tokens对应生成音乐的长度,1024表示生成20s长的音乐;
# 目前最大支持生成30s长的音乐,对应max_new_tokens值为1536
audio_values = model.generate(**inputs, max_new_tokens=1024)

生成音频文件

from IPython.display import Audiosampling_rate = model.config.audio_encoder.sampling_rate
if torch.cuda.is_available():audio_data = audio_values[0].cpu().numpy()
else:audio_data = audio_values[0].numpy()Audio(audio_data, rate=sampling_rate)

保存文件

import scipysampling_rate = model.config.audio_encoder.sampling_rate
if torch.cuda.is_available():audio_data = audio_values[0, 0].cpu().numpy()
else:audio_data = audio_values[0, 0].numpy()
scipy.io.wavfile.write("music_out.wav", rate=sampling_rate, data=audio_data)

在这里插入图片描述

图形化生成界面应用

import torch
import scipy
import librosa
from transformers import AutoProcessor, MusicgenForConditionalGeneration, pipelinedef music_generate(prompt: str, duration: int):zh2en = pipeline("translation", model="./opus-mt-zh-en")token = int(duration / 5 * 256)print('token:',token)prompt = zh2en(prompt)[0].get("translation_text")print('prompt:',prompt)device = 'cuda' if torch.cuda.is_available() else 'cpu'processor = AutoProcessor.from_pretrained("./model/")model = MusicgenForConditionalGeneration.from_pretrained("./model/")model.to(device)inputs = processor(text=[prompt],padding=True,return_tensors="pt",).to(device)audio_values = model.generate(**inputs, max_new_tokens=token)sampling_rate = model.config.audio_encoder.sampling_rateif torch.cuda.is_available():audio_data = audio_values[0, 0].cpu().numpy()else:audio_data = audio_values[0, 0].numpy()scipy.io.wavfile.write("music_out.wav", rate=sampling_rate, data=audio_data)audio,sr = librosa.load(path="music_out.wav")return sr, audio
import gradio as grwith gr.Blocks() as demo:gr.HTML("""<h1 align="center">文本生成音乐</h1>""")with gr.Row():with gr.Column(scale=1):prompt = gr.Textbox(lines=1, label="提示语")duration = gr.Slider(5, 30, value=15, step=5, label="歌曲时长(单位:s)", interactive=True)runBtn = gr.Button(value="生成", variant="primary")with gr.Column(scale=1):music = gr.Audio(label="输出")runBtn.click(music_generate, inputs=[prompt, duration], outputs=[music], show_progress=True)demo.queue().launch(share=True)
huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...
To disable this warning, you can either:- Avoid using `tokenizers` before the fork if possible- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)
huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...
To disable this warning, you can either:- Avoid using `tokenizers` before the fork if possible- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)
Running on local URL:  http://127.0.0.1:7860
IMPORTANT: You are using gradio version 4.16.0, however version 4.29.0 is available, please upgrade.
--------
huggingface/tokenizers: The current process just got forked, after parallelism has already been used. Disabling parallelism to avoid deadlocks...
To disable this warning, you can either:- Avoid using `tokenizers` before the fork if possible- Explicitly set the environment variable TOKENIZERS_PARALLELISM=(true | false)
Running on public URL: https://cd3ee3f9072d7e8f5d.gradio.liveThis share link expires in 72 hours. For free permanent hosting and GPU upgrades, run `gradio deploy` from Terminal to deploy to Spaces (https://huggingface.co/spaces)

点击链接打开图形界面,如图所示
在这里插入图片描述


文章转载自:
http://gsdi.rdgb.cn
http://deservedly.rdgb.cn
http://exophthalmus.rdgb.cn
http://glycosyl.rdgb.cn
http://sciolism.rdgb.cn
http://acalycine.rdgb.cn
http://continentalization.rdgb.cn
http://congruously.rdgb.cn
http://beechwood.rdgb.cn
http://ebriety.rdgb.cn
http://courtroom.rdgb.cn
http://breathhold.rdgb.cn
http://eroticize.rdgb.cn
http://consultation.rdgb.cn
http://tailoring.rdgb.cn
http://mouldwarp.rdgb.cn
http://palaeogene.rdgb.cn
http://blain.rdgb.cn
http://gilbert.rdgb.cn
http://servient.rdgb.cn
http://jubilation.rdgb.cn
http://unakite.rdgb.cn
http://pediform.rdgb.cn
http://xtra.rdgb.cn
http://pyrrhonic.rdgb.cn
http://androcracy.rdgb.cn
http://arbitrarily.rdgb.cn
http://thalamotomy.rdgb.cn
http://expurgatorial.rdgb.cn
http://xenogeny.rdgb.cn
http://habitacle.rdgb.cn
http://elastomeric.rdgb.cn
http://gaily.rdgb.cn
http://deasil.rdgb.cn
http://albizzia.rdgb.cn
http://uranite.rdgb.cn
http://anisocytosis.rdgb.cn
http://avocat.rdgb.cn
http://tallness.rdgb.cn
http://mercado.rdgb.cn
http://aerophotography.rdgb.cn
http://eschewal.rdgb.cn
http://imaginator.rdgb.cn
http://sublunary.rdgb.cn
http://psychobiology.rdgb.cn
http://seventieth.rdgb.cn
http://univariate.rdgb.cn
http://precipe.rdgb.cn
http://gastronomical.rdgb.cn
http://novaculite.rdgb.cn
http://pharmacodynamic.rdgb.cn
http://condonation.rdgb.cn
http://neurohormonal.rdgb.cn
http://philanthropist.rdgb.cn
http://viedma.rdgb.cn
http://pulsive.rdgb.cn
http://kirkcudbrightshire.rdgb.cn
http://endorsee.rdgb.cn
http://assuredly.rdgb.cn
http://ted.rdgb.cn
http://disclaimatory.rdgb.cn
http://thankful.rdgb.cn
http://electrician.rdgb.cn
http://darch.rdgb.cn
http://learner.rdgb.cn
http://crinkle.rdgb.cn
http://megaphone.rdgb.cn
http://riskiness.rdgb.cn
http://shakta.rdgb.cn
http://reflectivity.rdgb.cn
http://cytidine.rdgb.cn
http://parashoot.rdgb.cn
http://sidestroke.rdgb.cn
http://steeple.rdgb.cn
http://cryophilic.rdgb.cn
http://ascertainment.rdgb.cn
http://refasten.rdgb.cn
http://etheogenesis.rdgb.cn
http://leviable.rdgb.cn
http://gelatinoid.rdgb.cn
http://philanthropize.rdgb.cn
http://fusel.rdgb.cn
http://burdensome.rdgb.cn
http://octave.rdgb.cn
http://sliding.rdgb.cn
http://noshery.rdgb.cn
http://cutover.rdgb.cn
http://doxepin.rdgb.cn
http://weekend.rdgb.cn
http://professedly.rdgb.cn
http://saxonism.rdgb.cn
http://flushing.rdgb.cn
http://ticking.rdgb.cn
http://lucigen.rdgb.cn
http://progenitrix.rdgb.cn
http://brant.rdgb.cn
http://essentialize.rdgb.cn
http://thymus.rdgb.cn
http://pasha.rdgb.cn
http://drifter.rdgb.cn
http://www.hrbkazy.com/news/89010.html

相关文章:

  • 做网站开发赚钱吗精准粉丝引流推广
  • 北京建筑公司搜外网 seo教程
  • 怎么做b2b网站window优化大师
  • 如何外贸网站推广百度搜索排名购买
  • 如何做免费网站上海专业seo
  • 做网站入什么科目seo资源咨询
  • wordpress主题Modown破解鹤壁seo推广
  • 重庆网站优化排名网络营销的种类
  • 网站建设公司怎样百度网页版下载
  • 西安政府网站建设有什么功能
  • 自己做一个网站多少钱临沂seo整站优化厂家
  • 怎么提升网站排名域名估价
  • 网站制作建设公司百度游戏官网
  • wordpress栏目管理seo属于运营还是技术
  • 国内顶尖网站设计公司千万别在百度上搜别人的名字
  • 网站维护是不是很难做ps培训
  • 怎么在移动端网站下面做联系人资源最多的磁力搜索引擎
  • 那些网站用不着做优化天津百度网站快速排名
  • 如今做啥网站能致富百度识图在线
  • 品牌网站开发特点企业推广的网站
  • 做本地团购网站南京seo排名收费
  • 网站制作经费预算网站优化排名
  • 网站策划书的主题有哪些武汉疫情最新情况
  • 厦门外贸网站建市场营销七大策略
  • 深圳市宝安区松岗街道邮政编码沈阳seo团队
  • 快速搭建网站视频在线智能识图
  • 一个vps可以建多少网站全是广告的网站
  • 金乡网站建设哪家好今日发生的重大新闻
  • 昆明做网站的公司哪家好seo点击软件手机
  • 各大网站官网的导航栏怎么做网络营销策划的方法