Gradio github:https://github.com/gradio-app/gradio
1.curl-fsSLhttps://ollama.com/install.sh|sh2.ollamapullllama3.1:8b
如果想了解详细的安装过程,请看此篇:
【干货】手把手教你搭建Ollama+OpenWebUI
source~/miniconda3/bin/activatecondacreate-ncharbot_1python=3.12
完成后继续以下指令,在虚拟环境中安装Gradio 。
condaactivatecharbot_1pipinstallgradio
import requestsimport jsonimport gradio as grurl = "http://localhost:11434/api/generate"headers = {'Content-Type': 'application/json'}conversation_history = []def generate_response(prompt):conversation_history.append(prompt)full_prompt = "\n".join(conversation_history)data = {"model": "llama3.1:8b","stream": False,"prompt": full_prompt}response =requests.post(url, headers=headers, data=json.dumps(data))if response.status_code == 200:response_txt = response.textdata = json.loads(response_txt)actual_response = data["response"]conversation_history.append(actual_response)return actual_responseelse:print("Error:", response.status_code, response.text)iface = gr.Interface(fn=generate_response,inputs=["text"],outputs=["text"])if __name__ == "__main__":iface.launch()
1. 先运行 ollama 把模型启动,在终端中运行
ollamarunllama3.1:8B
2. 另开一个终端,进入python虚拟环境运行 charbot_1
python3charbot_1
3. 在浏览器中打开
--THE END--
| 欢迎光临 链载Ai (https://www.lianzai.com/) | Powered by Discuz! X3.5 |