LLaVA: Large Language and Vision Assistant 图片解析 图生文

效果

ec7026ec6af668ff91b70ad4d039c465.png

项目

e5b3646d0c201f2ce1213214430d6ebf.png

测试代码

using LLavaSharp;
using System;
using System.Diagnostics;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace WinformTest
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        IntPtr llamaDllPtr = Lib.LoadLibrary(@".\dll\cuda12\llama.dll");
        IntPtr llavaSharedDllPtr = Lib.LoadLibrary(@".\dll\cuda12\llava_shared.dll");

        string model = @"C:\MyStudy\llava\llava-v1.5-7b-Q4_K.gguf";
        string mmproj = @"C:\MyStudy\llava\llava-v1.5-7b-mmproj-Q4_0.gguf";

        Helper helper;

        private void Form1_Load(object sender, EventArgs e)
        {
            helper = new Helper(model, mmproj);
        }

        string fileFilter = "*.*|*.bmp;*.jpg;*.jpeg;*.tiff;*.tiff;*.png";
        string image_path = "";
        Bitmap bitmap;
        private void button1_Click(object sender, EventArgs e)
        {
            OpenFileDialog ofd = new OpenFileDialog();
            ofd.Filter = fileFilter;
            if (ofd.ShowDialog() != DialogResult.OK) return;
            pictureBox1.Image = null;
            image_path = ofd.FileName;
            bitmap = new Bitmap(image_path);
            pictureBox1.Image = bitmap;
            txtInfo.Text = "";
        }

        StringBuilder sb = new StringBuilder();
        private void button2_Click(object sender, EventArgs e)
        {
            if (image_path == "")
            {
                return;
            }

            if (String.IsNullOrEmpty(txtPrompt.Text))
            {
                return;
            }

            txtInfo.Text = "";
            button2.Enabled = false;
            sb.Clear();
            System.Windows.Forms.Application.DoEvents();
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            string result = helper.ProcessImage(bitmap, txtPrompt.Text);
            double totalTime = stopwatch.Elapsed.TotalSeconds;
            stopwatch.Stop();
            sb.AppendLine($"totalTime: {totalTime:F2}s");
            sb.AppendLine("- - - - - - - - - - - - - - - - ");
            sb.AppendLine(result);
            txtInfo.Text = sb.ToString();
            button2.Enabled = true;
        }
    }
}

参考

项目地址

https://github.com/IntptrMax/LLavaSharp

测试模型下载地址

https://hf-mirror.com/jartine/llava-v1.5-7B-GGUF/tree/main

b38bc59feeaa8a97a8b28bca1974628d.gif

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值