微信扫码
添加专属顾问
我要投稿
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-06-14
32K Star狂欢!这个可视化AI助手平台让人人都能搭建专属智能体!
2025-06-04
Dify结合Echarts实现数据可视化-数据库篇
2025-06-03
刚刚,全球第一CRM收购AI Agent平台Moonhub
2025-06-02
Albus:重新定义文件管理,AI 驱动的智能网盘
2025-05-29
Dify工作流:用爬虫批量把公众号文章存到AI知识库 | 保姆级教程
2025-05-27
企业当前适合引入大模型驱动的智能运维吗?
2025-05-26
AI 硬件产品怎么做?——儿童智能硬件
2025-05-24
微软CEO:不卷大模型,微软要造AI时代的通用工具箱
2025-03-25
2025-03-25
2025-03-20
2025-03-18
2025-03-23
2025-03-17
2025-03-19
2025-03-19
2025-03-22
2025-03-28
2025-05-27
2025-05-24
2025-05-17
2025-05-14
2025-05-12
2025-05-09
2025-04-30
2025-04-26