1from transformers import AutoModelForCausalLM, AutoTokenizer
2from peft import PeftModel
3import torch
45# 加载基础模型6model_name ="unsloth/llama-3-8b-Instruct-bnb-4bit"7tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)8tokenizer.pad_token = tokenizer.eos_token
910model = AutoModelForCausalLM.from_pretrained(11 model_name,12 torch_dtype=torch.float16,13 device_map="auto",14 trust_remote_code=True,15)1617# 加载 Joe Rogan LoRA18model = PeftModel.from_pretrained(model,"/workspace/joe_rogan_lora_v2/checkpoint-500")19model.eval()2021# 生成对话22prompt ="""System: You are Joe Rogan hosting The Joe Rogan Experience podcast. Speak naturally, casually, and with genuine curiosity.
23User: What do you think about AI?
24Assistant:"""2526inputs = tokenizer(prompt, return_tensors="pt").to("cuda")27outputs = model.generate(**inputs, max_new_tokens=200, temperature=0.8, top_p=0.9, do_sample=True)28print(tokenizer.decode(outputs[0], skip_special_tokens=True))
2. 生成语音 (XTTS v2)
python
1from TTS.api import TTS
23# 加载模型4tts = TTS(model_name='tts_models/multilingual/multi-dataset/xtts_v2')5tts.to('cuda')67# Joe Rogan 声音8tts.tts_to_file(9 text="Welcome to the Joe Rogan Experience.",10 speaker_wav="/workspace/JoeRoganAISample.mp3",# Joe 参考音频11 language='en',12 file_path="joe_output.wav",13)1415# Buffett 声音16tts.tts_to_file(17 text="The best investment you can make is in yourself.",18 speaker_wav="/workspace/buffett_ref_v2.wav",# Buffett 参考音频19 language='en',20 file_path="buffett_output.wav",21)
1{"messages":[2{"role":"system","content":"You are Joe Rogan hosting The Joe Rogan Experience podcast."},3{"role":"user","content":"Continue the conversation:\n\n[上下文]"},4{"role":"assistant","content":"[Joe 的回答]"}5]}