微信扫码
添加专属顾问
我要投稿
Gradio github:https://github.com/gradio-app/gradio
1. curl -fsSL https://ollama.com/install.sh | sh2. ollama pull llama3.1:8b
如果想了解详细的安装过程,请看此篇:
【干货】手把手教你搭建Ollama+OpenWebUI
source ~/miniconda3/bin/activateconda create -n charbot_1 python=3.12
完成后继续以下指令,在虚拟环境中安装Gradio 。
conda activate charbot_1pip install gradio
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 把模型启动,在终端中运行
ollama run llama3.1:8B
2. 另开一个终端,进入python虚拟环境运行 charbot_1
python3 charbot_1
3. 在浏览器中打开
--THE END-- 
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费POC验证,效果达标后再合作。零风险落地应用大模型,已交付160+中大型企业
2026-05-18
Android 迎来 Gemini-Intelligence,手机要开始替你干活了
2026-05-18
OpenAI秘密矩阵曝光!你的所有设备,被Codex连成一台超级电脑
2026-05-15
苹果不卷AI了:iOS 27要让第三方模型"竞标"进系统
2026-05-13
安卓彻底变了!Gemini接管所有屏幕,苹果连影子都没追上
2026-05-09
探索树莓派和本地 AI 智能体、机器人技术与 2026 年自动化未来!
2026-05-07
龙虾退烧后,荣耀给它造了一个宇宙
2026-04-27
刚刚,OpenAI 手机曝光!2028 年量产
2026-04-21
乐鑫龙虾 ESP-Claw 来了!聊天就能开发智能设备
2026-03-10
2026-04-07
2026-02-22
2026-02-22
2026-04-02
2026-03-25
2026-03-19
2026-02-22
2026-03-17
2026-03-16