人脸识别与大模型问答

This commit is contained in:
jiang 2024-10-17 17:06:13 +08:00
parent 90443b8887
commit 45ac05fc06
2 changed files with 34 additions and 18 deletions

View File

@ -17,13 +17,14 @@ import javax.annotation.Resource;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.ArrayList; import java.util.*;
import java.util.Comparator;
import java.util.List;
import java.util.Map;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
import java.util.zip.ZipInputStream; import java.util.zip.ZipInputStream;
/** /**
@ -514,25 +515,33 @@ public class DataSetController extends BaseController {
List<MultipartFile> multipartFiles = new ArrayList<>(); List<MultipartFile> multipartFiles = new ArrayList<>();
int batchSize = 100; // 每批处理的文件数量 int batchSize = 100; // 每批处理的文件数量
try (ZipInputStream zis = new ZipInputStream(file.getInputStream())) { try (ZipFile zipFile = new ZipFile(convertMultipartFileToFile(file), Charset.forName("GBK"))) {
ZipEntry entry; Enumeration<? extends ZipEntry> entries = zipFile.entries();
// 逐个读取压缩文件中的条目 zipFile.stream().forEach(entry -> {
while ((entry = zis.getNextEntry()) != null) { String name = entry.getName();
System.out.println(name);
});
while (entries.hasMoreElements()) {
ZipEntry entry = entries.nextElement();
String fileName = entry.getName();
// 如果条目不是目录且是图片文件 // 如果条目不是目录且是图片文件
if (!entry.isDirectory() && isImageFile(entry.getName())) { if (!entry.isDirectory() && isImageFile(fileName)) {
// 创建解压后的图片文 // 创建解压后的图片文
File imgFile = new File(tempDir.toFile(), entry.getName()); File imgFile = new File(tempDir.toFile(), fileName);
imgFile.getParentFile().mkdirs(); // 确保目录存在 imgFile.getParentFile().mkdirs(); // 确保目录存在
// 将条目内容写入到文件 // 将条目内容写入到文件
try (FileOutputStream fos = new FileOutputStream(imgFile)) { try (InputStream entryInputStream = zipFile.getInputStream(entry);
FileOutputStream fos = new FileOutputStream(imgFile)) {
byte[] buffer = new byte[1024]; byte[] buffer = new byte[1024];
int length; int length;
while ((length = zis.read(buffer)) >= 0) { while ((length = entryInputStream.read(buffer)) >= 0) {
fos.write(buffer, 0, length); fos.write(buffer, 0, length);
} }
} }
// 创建 MultipartFile 对象并添加到列表中 // 创建 MultipartFile 对象并添加到列表中
MultipartFile multipartFile = new CustomMultipartFile(imgFile); MultipartFile multipartFile = new CustomMultipartFile(imgFile);
multipartFiles.add(multipartFile); multipartFiles.add(multipartFile);
@ -620,4 +629,11 @@ public class DataSetController extends BaseController {
} }
} }
// 辅助方法 MultipartFile 转换为 File
private File convertMultipartFileToFile(MultipartFile file) throws IOException {
File tempFile = File.createTempFile("temp", null);
file.transferTo(tempFile);
return tempFile;
}
} }

View File

@ -468,7 +468,7 @@ public class DataSetServiceImpl implements DataSetService {
if (ajaxResult.isSuccess()) { if (ajaxResult.isSuccess()) {
List<Map<String, String>> data = (List<Map<String, String>>) ajaxResult.get("data"); List<Map<String, String>> data = (List<Map<String, String>>) ajaxResult.get("data");
for (Map<String, String> map : data) { for (Map<String, String> map : data) {
entity.setModelAddress(map.get("url")); entity.setModelAddress(entity.getModelFile()[0].getOriginalFilename()+":"+map.get("url"));
} }
} else { } else {
return AjaxResult.error("上传文件失败"); return AjaxResult.error("上传文件失败");
@ -479,7 +479,7 @@ public class DataSetServiceImpl implements DataSetService {
if (userGuide.isSuccess()) { if (userGuide.isSuccess()) {
List<Map<String, String>> data = (List<Map<String, String>>) userGuide.get("data"); List<Map<String, String>> data = (List<Map<String, String>>) userGuide.get("data");
for (Map<String, String> map : data) { for (Map<String, String> map : data) {
entity.setUserGuide(map.get("url")); entity.setUserGuide(entity.getUserGuideFile()[0].getOriginalFilename()+":"+map.get("url"));
} }
} else { } else {
@ -507,18 +507,18 @@ public class DataSetServiceImpl implements DataSetService {
if (ajaxResult.isSuccess()) { if (ajaxResult.isSuccess()) {
List<Map<String, String>> data = (List<Map<String, String>>) ajaxResult.get("data"); List<Map<String, String>> data = (List<Map<String, String>>) ajaxResult.get("data");
for (Map<String, String> map : data) { for (Map<String, String> map : data) {
entity.setModelAddress(map.get("url")); entity.setModelAddress(entity.getModelFile()[0].getOriginalFilename()+":"+map.get("url"));
} }
} else { } else {
return AjaxResult.error("上传文件失败"); return AjaxResult.error("上传文件失败");
} }
} }
if (ObjectUtils.isNotEmpty(entity.getModelFile())) { if (ObjectUtils.isNotEmpty(entity.getUserGuideFile())) {
AjaxResult userGuide = remoteFileService.uploadFile(entity.getUserGuideFile()); AjaxResult userGuide = remoteFileService.uploadFile(entity.getUserGuideFile());
if (userGuide.isSuccess()) { if (userGuide.isSuccess()) {
List<Map<String, String>> data = (List<Map<String, String>>) userGuide.get("data"); List<Map<String, String>> data = (List<Map<String, String>>) userGuide.get("data");
for (Map<String, String> map : data) { for (Map<String, String> map : data) {
entity.setUserGuide(map.get("url")); entity.setUserGuide(entity.getUserGuideFile()[0].getOriginalFilename()+":"+map.get("url"));
} }
} else { } else {