微信扫码
添加专属顾问
我要投稿
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-01-31
AI硬件的宿命:要么“在场”,要么“进抽屉”
2026-01-31
我们测了十几款AI硬件,发现它们死于同一个问题
2026-01-29
LiteRT | 释放极致潜能,构建下一代高性能端侧 AI
2026-01-29
在树莓派CM0上部署 Clawdbot 真的有那么神奇吗?
2026-01-22
英伟达让机器人闪念决策:Fast-ThinkAct如何让AI思考速度快9倍还更聪明?
2026-01-20
AI手机的终极猜想:超级Agent入口|产业深度
2026-01-19
吃灰 AI 眼镜爆改“交警 Copilot”,函数计算AgentRun 实操记录
2026-01-19
OpenAI放大招: 新AI硬件Sweetpea要革屏幕的命, 有人早就布局4年
2025-12-05
2025-12-09
2025-11-09
2025-12-01
2025-12-08
2025-11-17
2025-12-15
2025-12-01
2025-12-03
2025-11-08
2026-01-29
2026-01-22
2026-01-06
2026-01-04
2026-01-02
2025-11-08
2025-10-27
2025-10-24