举荐:应用NSDT场景编辑器
助你疾速搭建可二次编辑的3D利用场景
1. 创立新空间
- 转到 hf.co 并创立一个收费帐户。之后,单击右上角的显示图像,而后抉择“新空间”选项。
- 在表单中填写应用程序名称、许可证、空间硬件和可见性。
3.按“创立空间”以初始化应用程序。
4.您能够克隆存储库并从本地零碎推送文件,或者应用浏览器在拥抱脸上创立和编辑文件。
2.创立聊天机器人应用程序文件
- 咱们将单击“文件”选项卡>+增加文件>创立新文件。
2.创立 Gradio 接口。你能够复制我的代码。
3.我曾经加载了“microsoft/dialopGPT-large”标记器和模型,并创立了一个“预测”函数来获取响应和创立历史记录。
from transformers import AutoModelForCausalLM, AutoTokenizerimport gradio as grimport torchtitle = "AI ChatBot"description = "A State-of-the-Art Large-scale Pretrained Response generation model (DialoGPT)"examples = [["How are you?"]]tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-large")model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-large")def predict(input, history=[]): # tokenize the new input sentence new_user_input_ids = tokenizer.encode( input + tokenizer.eos_token, return_tensors="pt" ) # append the new user input tokens to the chat history bot_input_ids = torch.cat([torch.LongTensor(history), new_user_input_ids], dim=-1) # generate a response history = model.generate( bot_input_ids, max_length=4000, pad_token_id=tokenizer.eos_token_id ).tolist() # convert the tokens to text, and then split the responses into lines response = tokenizer.decode(history[0]).split("<|endoftext|>") # print('decoded_response-->>'+str(response)) response = [ (response[i], response[i + 1]) for i in range(0, len(response) - 1, 2) ] # convert to tuples of list # print('response-->>'+str(response)) return response, historygr.Interface( fn=predict, title=title, description=description, examples=examples, inputs=["text", "state"], outputs=["chatbot", "state"], theme="finlaymacklon/boxy_violet",).launch()
此外,我还为我的应用程序提供了一个自定义主题:boxy_violet。您能够浏览Gradio主题库,依据您的口味抉择主题。
3. 创立需要文件
1.当初,咱们须要创立一个“需要.txt”文件并增加所需的 Python 包。
`transformers
torch`
之后,您的应用程序将开始构建,并在几分钟内下载模型并加载模型推理。
4. Gradio
演示Gradio应用程序看起来很棒。咱们只须要为每个不同的模型架构师创立一个“预测”函数,以取得响应并保护历史记录。
您当初能够在kingabzpro / AI-ChatBot上与应用程序聊天和互动,或应用 https://kingabzpro-ai-chatbot.hf.space 将您的应用程序嵌入您的网站。
你还在困惑吗?在 Spaces 上查找数百个聊天机器人应用程序,以取得灵感并理解模型推理。
例如,如果您有一个在“LLaMA-7B”上微调的模式。搜寻模型并向下滚动以查看模型的各种实现。
论断
总之,本博客提供了一个疾速简便的教程,介绍如何在短短 5 分钟内应用 Hugging Face 和 Gradio 创立 AI 聊天机器人。
通过分步阐明和可自定义的选项,任何人都能够轻松创立他们的聊天机器人。这很乏味,我心愿你学到了一些货色。请在评论局部分享您的Gradio演示。如果您正在寻找更简略的解决方案,请查看OpenChat:在几分钟内构建自定义聊天机器人的收费和简略平台。
教你5分钟内应用Hugging Face和 Gradio 构建 AI 聊天机器人