效果
项目
测试代码
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