微信扫码
添加专属顾问
我要投稿
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+中大型企业
2025-10-29
KnowFlow 无缝衔接 Dify,分块支持添加父标题、Title 切块支持自定义标题层级切割、图片理解新增支持上下文
2025-10-28
邪修榨干元宝AI录音笔:白天工作,晚上陪聊
2025-10-27
免费又好用的AI录音笔都出来了,这下哪还有理由不学习?
2025-10-24
Aiops探索:我用Dify结合k8s的api做了一个非常简单的Aiops智能体
2025-10-24
阿里夸克AI眼镜开售:叠加补贴后3699元,它能打破AI眼镜的魔咒吗?
2025-10-23
Dify平台集成阿里云AI安全护栏,构建AI Runtime安全防线
2025-10-13
Dify + 飞书组合拳:企业级 AI 安全大脑落地全指南,助力安管效率提升 300%
2025-09-23
专访Plaud中国区CEO:我们只做“必须做”和“不做要死”的事
2025-09-19
2025-09-02
2025-10-13
2025-09-02
2025-10-24
2025-08-25
2025-09-05
2025-09-02
2025-08-22
2025-08-28