月度归档:2024年11月

文字列表转图片

from PIL import Image, ImageDraw, ImageFont

# 创建一个新的白色图片
width, height = 2481, 3507
image = Image.new('RGB', (width, height), color = (255, 255, 255))

# 准备画笔
draw = ImageDraw.Draw(image)

# 选择字体和大小
font = ImageFont.truetype("/usr/share/fonts/simsun.ttc", 120)
font2 = ImageFont.truetype("/usr/share/fonts/simsun.ttc", 100)
# 写入文字 20长度
text = "120关于议题《所发生的方式的发生的发送到发送到托付给人生巅峰书房宜》附件"
text_position = (20, 20)  # 文字的位置
draw.text(text_position, text, font=font, fill=(0, 0, 0))

text = "1.这里是第哒哒哒哒哒哒多多多多多顶顶顶顶二行非法"
text_position = (100, 220)  # 文字的位置 23长度
draw.text(text_position, text, font=font2, fill=(0, 0, 0))

text = "2.这里是第三行"
text_position = (100, 420)  # 文字的位置
draw.text(text_position, text, font=font2, fill=(0, 0, 0))

text = "3.这里是第四行"
text_position = (100, 620)  # 文字的位置
draw.text(text_position, text, font=font2, fill=(0, 0, 0))

# 保存图片
image.save('hello.jpg')

print("图片已保存")

120 大小 20个字

100 大小 23个字

JS PDF文件下载,并合并,加动画

CSS代码:

<style>
    /* 加载动画的样式 */
    .loader {
        border: 5px solid #f3f3f3;
        border-radius: 50%;
        border-top: 5px solid #3498db;
        width: 50px;
        height: 50px;
        animation: spin 2s linear infinite;
    }

    @keyframes spin {
        0% {
            transform: rotate(0deg);
        }

        100% {
            transform: rotate(360deg);
        }
    }

</style>

HTML代码

 <button class="btn btn-danger download-files"><span class="glyphicon glyphicon-file"></span></button>

<div id="loadingContainer" style="display:none;margin-top: 10px;" class="row alert alert-info" tag="一键下载附件">
            <div class="col-md-4 col-md-offset-2">
                <h2>下载附件中</h2>
            </div>
            <div class="loader col-md-2"></div>
        </div>



JS代码


        <script src='https://unpkg.com/pdf-lib/dist/pdf-lib.js'></script>
        <script src='https://unpkg.com/pdf-lib/dist/pdf-lib.min.js'></script>

        <script>
            async function mergeAllPDFs(urls) {
                // 显示加载动画
                document.getElementById('loadingContainer').style.display = 'block';

                const pdfDoc = await PDFLib.PDFDocument.create();
                const numDocs = urls.length;

                for (var i = 0; i < numDocs; i++) {
                    const donorPdfBytes = await fetch(urls[i]).then(res => res.arrayBuffer());
                    const donorPdfDoc = await PDFLib.PDFDocument.load(donorPdfBytes);
                    const docLength = donorPdfDoc.getPageCount();
                    for (var k = 0; k < docLength; k++) {
                        const [donorPage] = await pdfDoc.copyPages(donorPdfDoc, [k]);
                        pdfDoc.addPage(donorPage);
                    }
                }

                const pdfBytes = await pdfDoc.save();
                const blob = new Blob([pdfBytes], { type: 'application/pdf' });
                const url = URL.createObjectURL(blob);

                // 隐藏加载动画
                document.getElementById('loadingContainer').style.display = 'none';

                // 创建一个下载链接
                const downloadLink = document.createElement('a');
                downloadLink.href = url;
                downloadLink.download = $("#hy_date").val() + "附件.pdf"; // 指定下载文件名
                document.body.appendChild(downloadLink); // 将链接添加到页面中
                downloadLink.click(); // 模拟点击以下载文件
                document.body.removeChild(downloadLink); // 下载后移除链接
                URL.revokeObjectURL(url); // 释放创建的URL对象
            }
      


            $(".download-files").click(function () {
                $.ajax({
                    url: "{:url('portal/topics/ajax_topics_download_files',['id'=>$info['id']])}",
                    success: function (data) {
                        if (data.status) {
                            let pdfs = [];
                            for (let index = 0; index < data.info.length; index++) {

                            
                                pdfs.push(data.info[index]['pdf']);


                            }
                            console.log(pdfs)
                            mergeAllPDFs(pdfs);
                        }
                    }
                })
            })
        </script>

生成任意字符的单页PDF

中心思想,生成txt文件,再用liberoffice转为PDF

import os

com1="echo "+info_text+":信息 >swap.txt"
com2="libreoffice --convert-to pdf:writer_pdf_Export swap.txt --outdir "+self.download
os.system(com1)
os.system(com2)
  • HTML貌似不可用,目前无法修改字体大小

MAC 似乎游戏 Intel 大模型微调来自AI KIMI TAG

在Intel Mac上进行大模型微调,您可以遵循以下步骤:

  1. 安装Homebrew
  • Homebrew是macOS上的包管理器,用于简化软件包的安装和管理。在终端中输入以下命令安装Homebrew:
    /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
  • 参考链接:Homebrew安装指南
  1. 安装Miniforge
  • Miniforge是为ARM架构设计的Conda发行版,适合在Intel Mac上使用。下载并运行Miniforge安装脚本:
    curl -LO https://github.com/conda-forge/miniforge/releases/latest/download/Miniforge3-MacOSX-x86_64.sh bash Miniforge3-MacOSX-x86_64.sh
  • 按照提示完成安装。
  1. 创建并激活Conda环境
  • 创建一个新的Conda环境,例如名为tensorflow_2
    conda create --name tensorflow_2 python=3.9
  • 激活环境:
    conda activate tensorflow_2
  1. 安装TensorFlow
  • 在Conda环境中,使用pip安装TensorFlow:
    pip install tensorflow-macos
  • 这将安装适用于Intel Mac的TensorFlow版本。
  1. 验证TensorFlow安装
  • 打开Python解释器并运行以下代码以验证TensorFlow是否正确安装:
    import tensorflow as tf print("TensorFlow version:", tf.__version__) print("Num GPUs Available: ", len(tf.config.experimental.list_physical_devices('GPU')))
  • 如果能够看到输出TensorFlow版本和GPU信息,说明TensorFlow已成功安装。
  1. 准备数据集
  • 准备您的数据集,例如JSON格式的数据集,其中包含问题和答案:
    json [ { "instruction": "你好", "input": "", "output": "皇上好,我是甄嬛,家父是大理寺少卿甄远道。" }, { "instruction": "你不愿意见我?", "input": "", "output": "不该相见自然不愿见,还望王爷尊重我的意愿。" } ]
  1. 选择模型并开始微调
  • 选择一个适合您任务的预训练模型,例如LLM-Research/Meta-Llama-3-8B-Instruct,并开始微调。您可以修改train.py文件中的model_id变量来选择不同的模型。
  • 开始微调,执行以下命令:
    python train.py
  1. 测试微调后的模型
  • 微调完成后,您可以使用ChatBot进行对话测试,执行以下命令:
    streamlit run chat.py
  • 这将启动一个Web界面,您可以在其中与微调后的模型进行交互。

以上步骤提供了在Intel Mac上进行大模型微调的详细指南,帮助您充分利用现有的硬件资源和软件工具。

TAG

来自KIMI