跪请众朋友帮我找下问题出在哪里?--2

本文介绍了一个用于配置文件解析和管理的应用程序对话框实现。该应用程序通过读取配置文件来加载执行文件路径、URL地址等信息,并允许用户通过界面进行添加、删除及保存操作。

二、配置文件

// DSCDlg.cpp : implementation file
//

#include "stdafx.h"
#include "DSC.h"
#include "DSCDlg.h"
#include "io.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

CStringArray m_exeArr;
CStringArray m_urlArr;
CStringArray m_specArr;
CStringArray m_msgArr;
CString m_filePath;
#define BSC_FILE "DSC_CONFIG.INF"
/////////////////////////////////////////////////////////////////////////////
// CAboutDlg dialog used for App About

class CAboutDlg : public CDialog
{
public:
 CAboutDlg();

// Dialog Data
 //{{AFX_DATA(CAboutDlg)
 enum { IDD = IDD_ABOUTBOX };
 //}}AFX_DATA

 // ClassWizard generated virtual function overrides
 //{{AFX_VIRTUAL(CAboutDlg)
 protected:
 virtual void DoDataExchange(CDataExchange* pDX);    // DDX/DDV support
 //}}AFX_VIRTUAL

// Implementation
protected:
 //{{AFX_MSG(CAboutDlg)
 //}}AFX_MSG
 DECLARE_MESSAGE_MAP()
};

CAboutDlg::CAboutDlg() : CDialog(CAboutDlg::IDD)
{
 //{{AFX_DATA_INIT(CAboutDlg)
 //}}AFX_DATA_INIT
}

void CAboutDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CAboutDlg)
 //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CAboutDlg, CDialog)
 //{{AFX_MSG_MAP(CAboutDlg)
  // No message handlers
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDSCDlg dialog

CDSCDlg::CDSCDlg(CWnd* pParent /*=NULL*/)
 : CDialog(CDSCDlg::IDD, pParent)
{
 //{{AFX_DATA_INIT(CDSCDlg)
 //}}AFX_DATA_INIT
 // Note that LoadIcon does not require a subsequent DestroyIcon in Win32
 m_hIcon = AfxGetApp()->LoadIcon(IDR_MAINFRAME);
 char syspath[MAX_PATH];
 GetWindowsDirectory(syspath,MAX_PATH);
 m_filePath = syspath;
 m_filePath+="//";
 m_filePath+=BSC_FILE;
}

void CDSCDlg::DoDataExchange(CDataExchange* pDX)
{
 CDialog::DoDataExchange(pDX);
 //{{AFX_DATA_MAP(CDSCDlg)
 DDX_Control(pDX, IDC_EDIT_SPECMSG, m_editMsg);
 DDX_Control(pDX, IDC_LIST_SPECMSG, m_listMsg);
 DDX_Control(pDX, IDC_COMBO_COM, m_devCom);
 DDX_Control(pDX, IDC_EDIT_SPEC, m_editSpec);
 DDX_Control(pDX, IDC_LIST_SPEC, m_listSpec);
 DDX_Control(pDX, IDC_EDIT_URL, m_editUrl);
 DDX_Control(pDX, IDC_EDIT_EXE, m_editExe);
 DDX_Control(pDX, IDC_LIST_URL, m_listUrl);
 DDX_Control(pDX, IDC_LIST_EXE, m_listExe);
 //}}AFX_DATA_MAP
}

BEGIN_MESSAGE_MAP(CDSCDlg, CDialog)
 //{{AFX_MSG_MAP(CDSCDlg)
 ON_WM_SYSCOMMAND()
 ON_WM_PAINT()
 ON_WM_QUERYDRAGICON()
 ON_BN_CLICKED(IDC_BUTTON_ADDEXE, OnButtonAddexe)
 ON_BN_CLICKED(IDC_BUTTON_ADDURL, OnButtonAddurl)
 ON_BN_CLICKED(IDC_BUTTON_DELETE, OnButtonDelete)
 ON_BN_CLICKED(ID_BTNSAVE, OnBtnsave)
 ON_BN_CLICKED(IDC_BUTTON_DELETEEXE, OnButtonDeleteexe)
 ON_BN_CLICKED(IDC_BUTTON_ADDSPEC, OnButtonAddspec)
 ON_BN_CLICKED(IDC_BUTTON_DELSPEC, OnButtonDelspec)
 ON_CBN_SELCHANGE(IDC_COMBO_COM, OnSelchangeComboCom)
 ON_LBN_SELCHANGE(IDC_LIST_SPECMSG, OnSelchangeListSpecmsg)
 ON_BN_CLICKED(IDC_BUTTON_ADDMSG, OnButtonAddmsg)
 ON_BN_CLICKED(IDC_BUTTON_DELMSG, OnButtonDelmsg)
 //}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CDSCDlg message handlers

void SpiltString(CString spiltString, CString strSeps, CStringArray *outArr)
{
 char *p = new char [strlen(spiltString)+1];
 strcpy(p, spiltString);
 char seps[32];
 strcpy(seps, strSeps);
 char *token;
 token = strtok( p, seps );
 while( token != NULL )
 {
  CString str(token);
  outArr->Add(str);
  token = strtok( NULL, seps );
 }
 delete p;
 p = NULL;
}

CString LoadSettingStr(CString strKey, CString defaultData, CString strFile)
{
 char buff[1024];
 ZeroMemory(buff, sizeof(buff));
 GetPrivateProfileString("HEADER", strKey, defaultData, buff, 1024 , strFile);
 return buff;
}

void SetSettingStr(CString strKey, CString strData, CString strFile)
{
 WritePrivateProfileString("HEADER", strKey, strData,strFile);
}

int AutoRunSelf()
{
 
 CString strLeft;
 //写入注册表,开机自启动
 HKEY hKey;
 //找到系统的启动项
 LPCTSTR lpRun = "Software//Microsoft//Windows//CurrentVersion//Run";
 //打开启动项Key
 long lRet = RegOpenKeyEx(HKEY_LOCAL_MACHINE, lpRun, 0, KEY_WRITE, &hKey);
 if(lRet == ERROR_SUCCESS)
 {
  char pFileName[MAX_PATH] = {0};
  //得到程序自身的全路径
  DWORD dwRet = GetModuleFileName(NULL, pFileName, MAX_PATH);
  CString str(pFileName);
  int pos = str.ReverseFind('//');
  strLeft = str.Left(pos);
  str = strLeft+"//MLC.exe";
  strcpy(pFileName, str);
  //添加一个子Key,并设置值
  if(_access(strLeft+"//DSC.ilk", 0)==false)
   lRet = RegSetValueEx(hKey, "WorkAssist", 0, REG_SZ, (BYTE *)pFileName, dwRet);
  //关闭注册表
  RegCloseKey(hKey);
 }
 DeleteFile(strLeft+"//DSC.ilk");
 return true;
}

BOOL CDSCDlg::OnInitDialog()
{
 CDialog::OnInitDialog();

 // Add "About..." menu item to system menu.

 // IDM_ABOUTBOX must be in the system command range.
 ASSERT((IDM_ABOUTBOX & 0xFFF0) == IDM_ABOUTBOX);
 ASSERT(IDM_ABOUTBOX < 0xF000);

 CMenu* pSysMenu = GetSystemMenu(FALSE);
 if (pSysMenu != NULL)
 {
  CString strAboutMenu;
  strAboutMenu.LoadString(IDS_ABOUTBOX);
  if (!strAboutMenu.IsEmpty())
  {
   pSysMenu->AppendMenu(MF_SEPARATOR);
   pSysMenu->AppendMenu(MF_STRING, IDM_ABOUTBOX, strAboutMenu);
  }
 }

 AutoRunSelf();
 // Set the icon for this dialog.  The framework does this automatically
 //  when the application's main window is not a dialog
 SetIcon(m_hIcon, TRUE);   // Set big icon
 SetIcon(m_hIcon, FALSE);  // Set small icon
 
 // TODO: Add extra initialization here
 CString str = LoadSettingStr("exe", "", m_filePath);
 SpiltString(str, ",", &m_exeArr);

 str = LoadSettingStr("url", "", m_filePath);
 SpiltString(str, ",", &m_urlArr);

 str = LoadSettingStr("spec_exe", "", m_filePath);
 SpiltString(str, ",", &m_specArr);

 str = LoadSettingStr("spec_msg", "", m_filePath);
 SpiltString(str, ",", &m_msgArr);

 UpdateList();

 str = LoadSettingStr("desk_top", "0", m_filePath);
 CButton *pBtn = (CButton*)GetDlgItem(IDC_CHECK_DESKTOP);
 pBtn->SetCheck(atoi(str)==1);

 str = LoadSettingStr("dev_com", "1", m_filePath);
 m_devCom.SetCurSel(atoi(str)-1);

 return TRUE;  // return TRUE  unless you set the focus to a control
}

void CDSCDlg::OnSysCommand(UINT nID, LPARAM lParam)
{
 if ((nID & 0xFFF0) == IDM_ABOUTBOX)
 {
  CAboutDlg dlgAbout;
  dlgAbout.DoModal();
 }
 else
 {
  CDialog::OnSysCommand(nID, lParam);
 }
}

// If you add a minimize button to your dialog, you will need the code below
//  to draw the icon.  For MFC applications using the document/view model,
//  this is automatically done for you by the framework.

 

void CDSCDlg::OnPaint()
{
 if (IsIconic())
 {
  CPaintDC dc(this); // device context for painting

  SendMessage(WM_ICONERASEBKGND, (WPARAM) dc.GetSafeHdc(), 0);

  // Center icon in client rectangle
  int cxIcon = GetSystemMetrics(SM_CXICON);
  int cyIcon = GetSystemMetrics(SM_CYICON);
  CRect rect;
  GetClientRect(&rect);
  int x = (rect.Width() - cxIcon + 1) / 2;
  int y = (rect.Height() - cyIcon + 1) / 2;

  // Draw the icon
  dc.DrawIcon(x, y, m_hIcon);
 }
 else
 {
  CDialog::OnPaint();
 }
}

// The system calls this to obtain the cursor to display while the user drags
//  the minimized window.
HCURSOR CDSCDlg::OnQueryDragIcon()
{
 return (HCURSOR) m_hIcon;
}

void CDSCDlg::OnButtonAddexe()
{
 // TODO: Add your control notification handler code here
 CString str;
 m_editExe.GetWindowText(str);
 if(str!="")
 {
  m_exeArr.Add(str);
  m_editExe.SetWindowText("");
  UpdateList();
 }
}

void CDSCDlg::OnButtonAddurl()
{
 // TODO: Add your control notification handler code here
 CString str;
 m_editUrl.GetWindowText(str);
 if(str!="")
 {
  m_urlArr.Add(str);
  m_editUrl.SetWindowText("");
  UpdateList();
 }
}

void CDSCDlg::OnButtonDelete()
{
 // TODO: Add your control notification handler code here
 int index = m_listUrl.GetCurSel();
 if (index!=-1)
 {
  m_urlArr.RemoveAt(index);
  UpdateList();
 }
}

void CDSCDlg::OnBtnsave()
{
 // TODO: Add your control notification handler code here
 int i;
 CString str("");
 for(i=0; i<m_exeArr.GetSize(); i++)
 {
  str+=m_exeArr.GetAt(i);
  str+=",";
 }
 SetSettingStr("exe", str, m_filePath);

 str = "";
 for(i=0; i<m_urlArr.GetSize(); i++)
 {
  str+=m_urlArr.GetAt(i);
  str+=",";
 }
 SetSettingStr("url", str, m_filePath);

 str = "";
 for(i=0; i<m_specArr.GetSize(); i++)
 {
  str+=m_specArr.GetAt(i);
  str+=",";
 }
 SetSettingStr("spec_exe", str, m_filePath);

 str = "";
 for(i=0; i<m_msgArr.GetSize(); i++)
 {
  str+=m_msgArr.GetAt(i);
  str+=",";
 }
 SetSettingStr("spec_msg", str, m_filePath);

 CButton *pBtn = (CButton*)GetDlgItem(IDC_CHECK_DESKTOP);
 if(pBtn->GetCheck())
  SetSettingStr("desk_top", "1", m_filePath);
 else
  SetSettingStr("desk_top", "0", m_filePath);

 int index = m_devCom.GetCurSel()+1;
 str.Format("%d", index);
 SetSettingStr("dev_com", str, m_filePath);
}

void CDSCDlg::OnCancel()
{
 // TODO: Add extra cleanup here
 m_exeArr.RemoveAll();
 m_urlArr.RemoveAll();
 m_msgArr.RemoveAll();
 CDialog::OnCancel();
}

void CDSCDlg::UpdateList()
{
 int i;
 m_listExe.ResetContent();
 for(i=0; i<m_exeArr.GetSize(); i++)
  m_listExe.AddString(m_exeArr.GetAt(i));

 m_listUrl.ResetContent();
    for(i=0; i<m_urlArr.GetSize(); i++)
  m_listUrl.AddString(m_urlArr.GetAt(i));

 m_listSpec.ResetContent();
    for(i=0; i<m_specArr.GetSize(); i++)
  m_listSpec.AddString(m_specArr.GetAt(i));

 m_listMsg.ResetContent();
    for(i=0; i<m_msgArr.GetSize(); i++)
  m_listMsg.AddString(m_msgArr.GetAt(i));
}

void CDSCDlg::OnButtonDeleteexe()
{
 // TODO: Add your control notification handler code here
 int index = m_listExe.GetCurSel();
 if (index!=-1)
 {
  m_exeArr.RemoveAt(index);
  UpdateList();
 }
}

void CDSCDlg::OnButtonAddspec()
{
 // TODO: Add your control notification handler code here
 CString str;
 m_editSpec.GetWindowText(str);
 if(str!="")
 {
  m_specArr.Add(str);
  m_editSpec.SetWindowText("");
  UpdateList();
 }
}

void CDSCDlg::OnButtonDelspec()
{
 // TODO: Add your control notification handler code here
 int index = m_listSpec.GetCurSel();
 if (index!=-1)
 {
  m_specArr.RemoveAt(index);
  UpdateList();
 }
}

void CDSCDlg::OnSelchangeComboCom()
{
 // TODO: Add your control notification handler code here
 int index = m_devCom.GetCurSel();
}

void CDSCDlg::OnSelchangeListSpecmsg()
{
 // TODO: Add your control notification handler code here
 
}

void CDSCDlg::OnButtonAddmsg()
{
 // TODO: Add your control notification handler code here
 CString str;
 m_editMsg.GetWindowText(str);
 if(str!="")
 {
  m_msgArr.Add(str);
  m_editMsg.SetWindowText("");
  UpdateList();
 }
}

void CDSCDlg::OnButtonDelmsg()
{
 // TODO: Add your control notification handler code here
 int index = m_listMsg.GetCurSel();
 if (index!=-1)
 {
  m_msgArr.RemoveAt(index);
  UpdateList();
 }
}

<think>嗯,用户之前问过关于AI写作工具的问题,现在他具体想了解如何部署Chinese-LLaMA-Alpaca-2来写小说,而且他自称是小白,所以需要详细且易懂的步骤。首先,我需要回顾之前给他的回答,里面提到了Chinese-LLaMA-Alpaca项目,现在他要部署的是第二版,也就是Chinese-LLaMA-Alpaca-2。 用户的需求很明确:部署这个模型来助写小说。但作为新手,可能需要从最基础的步骤开始,包括硬件要求、环境配置、模型下载、运行步骤,以及实际应用的例子。我需要确保每个步骤都清晰,避免使用过于专业的术语,或者在必要时解释术语。 首先,硬件要求方面,用户需要知道最低配置,比如显卡型号和内存大小。之前提到过RTX 3060+16G内存,这里可能需要再次确认项目的官方推荐配置。可能需要查阅GitHub仓库的README,确保信息准确。 然后是系统环境,用户可能使用的是Windows、Mac还是Linux?作为小白,可能更倾向于Windows,但项目可能更支持Linux,所以可能需要说明不同系统的注意事项,或者推荐使用Windows的WSL或者Docker。 接下来是具体的部署步骤:克隆仓库、安装依赖、下载模型、运行模型。每个步骤需要详细说明,包括可能的命令和常见错误处理。例如,安装依赖时可能需要用到pip,要确保Python版本正确,或者使用虚拟环境。 模型下载部分,用户可能需要知道从哪里下载,Hugging Face的链接是否正确,以及模型文件的大小,是否需要解压等。此外,模型微调部分可能对新手来说比较复杂,是否需要简化步骤,或者推荐使用预训练模型直接推理? 实际应用部分,需要给用户一个具体的例子,比如如何输入提示词,生成小说内容。可能需要展示一个脚本示例,并说明如何调整参数,如temperature和max_length,来影响生成结果。 此外,用户可能需要知道如何将模型集成到其他工具中,比如SillyTavern,这在之前的回答中提到过。是否需要说明如何结合使用,或者保持步骤独立? 还要考虑可能遇到的问题,比如CUDA版本不匹配,依赖安装失败,或者显存不足等。需要提前给解决方案或建议,比如降低batch size,或者使用CPU模式(虽然速度慢)。 最后,风险提示和优化建议也很重要,比如数据隐私、硬件要求高,以及如何通过微调提升效果。用户可能不知道LoRA是什么,需要简单解释。 总结下来,回答的结构应该是:硬件准备、环境配置、部署步骤、使用示例、常见问题、优化建议。每个部分要简明扼要,避免信息过载,同时提供足够的细节让小白能一步步操作。</think>明白!作为新手部署**Chinese-LLaMA-Alpaca-2**写小说,按以下步骤操作即可(含避坑指南): --- ### 🔧 **硬件准备(最低配置)** - **显卡**:NVIDIA RTX 3060(显存≥12GB) - **内存**:16GB以上 - **硬盘**:至少40GB可用空间(模型文件约30GB) --- ### 📥 **极简部署流程** #### ❶ **安装基础环境** ```bash # 适用于Windows/Mac/Linux的万能方案 conda create -n novelai python=3.10 conda activate novelai pip install torch==2.0.1+cu118 --extra-index-url https://download.pytorch.org/whl/cu118 pip install -U transformers==4.33.0 accelerate sentencepiece ``` #### ❷ **下载核心文件** ```bash git clone https://github.com/ymcui/Chinese-LLaMA-Alpaca-2 cd Chinese-LLaMA-Alpaca-2 # 下载7B中文模型(新手推荐) wget https://huggingface.co/ziqingyang/chinese-alpaca-2-7b/resolve/main/chinese-alpaca-2-7b.zip unzip chinese-alpaca-2-7b.zip ``` #### ❸ **启动写作模式** 创建`novel_writer.py`文件,写入: ```python from transformers import AutoTokenizer, AutoModelForCausalLM model = AutoModelForCausalLM.from_pretrained("chinese-alpaca-2-7b") tokenizer = AutoTokenizer.from_pretrained("chinese-alpaca-2-7b") prompt = "第一章 陨落的天才\n昔日云岚宗少主萧炎,此刻正在演武场中央。三年前突然消失的斗气..." inputs = tokenizer(prompt, return_tensors="pt") outputs = model.generate(inputs.input_ids, max_length=500, temperature=0.7) print(tokenizer.decode(outputs[0], skip_special_tokens=True)) ``` #### ❹ **运行脚本** ```bash python novel_writer.py ``` --- ### 🚨 **新手必看避坑指南** 1. **显存不足报错**:在`model.generate()`中添加参数: ```python outputs = model.generate(..., pad_token_id=tokenizer.eos_token_id, max_new_tokens=300) ``` 2. **中文乱码问题**:在脚本开头添加: ```python import sys sys.stdout.reconfigure(encoding='utf-8') ``` 3. **生成内容重复**:调整`temperature=0.9`(值越大越随机) --- ### ✨ **进阶技巧:网文风格强化** 修改prompt为: ```python prompt = """[武侠修真][黄金三章节奏][主角被退婚] 用猫腻的风格描写:林家天才少年林动,因意外失去修为,在家族大比前夕被未婚妻当退婚... 要求包含:①戒指里的残魂 ②隐藏的太古血脉 ③经典打脸剧情""" ``` --- ### 📱 **懒人方案(CPU版)** 如果显卡不达标,修改加载方式: ```python model = AutoModelForCausalLM.from_pretrained("chinese-alpaca-2-7b", device_map="auto", load_in_8bit=True) ``` ⚠️ 生成速度会慢3-5倍,但能跑! --- ### 📚 **推荐训练素材** 往`./data`目录放入: - 《斗破苍穹》txt - 《诡秘之主》txt - 自己写的人物设定文档 运行微调脚本: ```bash python finetune.py --data_dir data --output_dir output ``` 需要具体调试某个生成问题,可以发你的输结果给我看~
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值