# flask-notebook **Repository Path**: 3162289690/flask-notebook ## Basic Information - **Project Name**: flask-notebook - **Description**: No description available - **Primary Language**: Python - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-11-14 - **Last Updated**: 2024-11-14 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README 以下是对你提供的 Markdown 内容进行优化后的版本: --- # 创建并配置 Jupyter Notebook 环境 ## 1. 创建新的 Conda 环境 ```bash conda create --name Notebook python=3.9 ``` ## 2. 激活环境 ```bash conda activate Notebook ``` ## 3. 安装 Jupyter Notebook ```bash conda install jupyter ``` ## 4. 启动 Jupyter Notebook ```bash jupyter notebook ``` ## 5. 生成并配置 Jupyter Notebook 配置文件 ```bash jupyter notebook --generate-config ``` ## 参考链接 1. [CSDN 博客:Jupyter Notebook 配置](https://blog.csdn.net/cainiao_python/article/details/125567913) 2. [CSDN 博客:Jupyter Notebook 运行界面](https://blog.csdn.net/zxm19980727/article/details/88601249) 3. [CSDN 博客:Jupyter Notebook 运行界面(版本)](https://blog.csdn.net/Cyb19980727/article/details/138735256) 4. [Jupyter Notebook 官方文档:迁移到 Notebook 7](https://jupyter-notebook.readthedocs.io/en/latest/migrate_to_notebook7.html) ## 6. 运行界面 - [Jupyter Notebook 运行界面](http://127.0.0.1:3010/app/webAssembly/runNotebook.html) - [Flask 应用运行界面](http://127.0.0.1:3010/app/webAssembly/runFlask.asp?versionID=798) - [Python 脚本运行界面](http://127.0.0.1:3010/app/webAssembly/runPy.html) ## 示例代码 ```python import sys import os # 获取 Python 版本 version = sys.version print(version) # 获取当前工作目录 current_working_directory = os.getcwd() print('当前工作目录:', current_working_directory) # 获取目录下的所有文件 files = [f for f in os.listdir(current_working_directory) if os.path.isfile(os.path.join(current_working_directory, f))] for file in files: print(file) # 读取文件内容 def read_file_content(file_path): # 检查文件是否存在 if not os.path.exists(file_path): return f"文件 {file_path} 不存在" # 检查文件是否为普通文件 if not os.path.isfile(file_path): return f"{file_path} 不是一个有效的文件" try: # 打开文件并读取内容 with open(file_path, 'r', encoding='utf-8') as file: content = file.read() return content except Exception as e: return f"读取文件时出错: {e}" # 示例文件路径 file_path = 'app.py' content = read_file_content(file_path) print(content) ``` # 使用 Docker 部署 Flask 应用 ## 1. 手动拉取 Docker 镜像 ```bash docker pull python:3.9-slim ``` ## 2. 构建 Docker 镜像 ```bash docker build -t flask-notebook . ``` ## 3. 运行 Docker 容器并指定端口 ```bash docker run -d -p 5000:5000 flask-notebook ``` --- # 导出已安装的包 ```bash pip freeze > requirements.txt ``` ```bash flask~=3.0.3 flask-cors~= 5.0.0 ``` ```bash git rm -r --cached .idea git commit -m "Remove .idea directory from repository" git push ``` # Ollama本地私有化部署 ## 参考资料 https://blog.csdn.net/Langchain/article/details/143402899 https://github.com/ollama/ollama?tab=readme-ov-file https://hub.docker.com/r/ollama/ollama https://github.com/ollama/ollama-python https://github.com/ollama/ollama/blob/main/docs/api.md https://blog.csdn.net/willian113/article/details/142746017 https://blog.csdn.net/u014297502/article/details/136308061 ## CPU only ```bash docker run -d -v ollama:/root/.ollama -p 11434:11434 --name ollama ollama/ollama # 拉取模型 ollama pull llama2 ollama pull llama3.2 # 运行模型 ollama run llama2 # 运行模型 本地没有,先下载模型 ollama run llama3.2 ollama run llama3.2 ollama run qwen2.5 # 输入/help查看对话可用指令 # 输入/bye退出对话模式 ollama serve # 启动ollama ollama create # 从模型文件创建模型 ollama show # 显示模型信息 ollama run # 运行模型 ollama pull # 从注册仓库中拉取模型 ollama push # 将模型推送到注册仓库 ollama list # 列出已下载模型 ollama cp # 复制模型 ollama rm # 删除模型 ollama help # 获取有关任何命令的帮助信息 ``` ## REST API ```bash # 流式返回 curl -X POST http://localhost:11434/api/generate -d '{"model":"llama3.2","prompt":"Why is the sky blue?"}' # 非流式返回。通过设置 "stream": false 参数可以设置一次性返回。 curl http://localhost:11434/api/generate -d '{ "model": "gemma:2b", "prompt":"介绍一下React,20字以内", "stream": false }' curl --location 'http://localhost:11434/api/generate' --header 'Content-Type: application/json' --data '{"model":"llama3.2","prompt":"Ollama本地私有化部署具体的方案"}' ```