微信扫码
添加专属顾问
我要投稿
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 requests
import json
import gradio as gr
url = "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.text
data = json.loads(response_txt)
actual_response = data["response"]
conversation_history.append(actual_response)
return actual_response
else:
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. 在浏览器中打开
53AI,企业落地大模型首选服务商
产品:场景落地咨询+大模型应用平台+行业解决方案
承诺:免费场景POC验证,效果验证后签署服务协议。零风险落地应用大模型,已交付160+中大型企业
2025-05-27
企业当前适合引入大模型驱动的智能运维吗?
2025-05-26
AI 硬件产品怎么做?——儿童智能硬件
2025-05-24
微软CEO:不卷大模型,微软要造AI时代的通用工具箱
2025-05-24
我们是否应该用 Lite-GPU 构建 AI 集群?
2025-05-24
Kubernetes为Mastercard的AI工作台提供安全创新能力
2025-05-22
Genspark:AI Agent 赛道的差异化突围者 | AI 智能体
2025-05-22
微软发布多智能体 Web 操作系统!让 AI 成为真正“可控、协同、透明”的网页执行助手!
2025-05-21
Spring AI Alibaba 发布企业级 MCP 分布式部署方案
2024-03-30
2024-05-09
2024-07-23
2024-07-07
2025-02-12
2024-07-01
2024-06-24
2024-10-20
2024-06-23
2024-12-29
2025-05-27
2025-05-24
2025-05-17
2025-05-14
2025-05-12
2025-05-09
2025-04-30
2025-04-26