text2videoService.ts 2.66 KB
Newer Older
Administrator's avatar
Administrator committed
1 2 3 4 5 6
/**
 * 相关接口
 */
import request from '@/api/request'

export default {
7
  submitGpt(prompt: string, llm: string = "gpt"): Promise<string> {
周成波's avatar
周成波 committed
8 9 10
    if (!prompt) {
      return Promise.reject("输入不能为空");
    }
11
    const post_data = { source_text: prompt, llm: llm }
周成波's avatar
周成波 committed
12 13 14 15 16 17 18 19 20 21 22 23
    return request.post('/text2video/text2gpt', post_data)
      .then((res: any) => {
        // console.log(res);
        if (res && res.code === 0) {
          return res.data.result.answer;
        } else {
          const errorMessage = res ? res.message : "未知错误";
          return Promise.reject(errorMessage);
        }
      })
      .catch((err: any) => {
        console.log(err);
24
        return Promise.reject("与LLM通讯失败");
周成波's avatar
周成波 committed
25 26 27 28 29 30 31 32
      });
  },

  submitSD(
    task_id: string = "",
    img_idx: string = "",
    prompt: string = "",
    negative_prompt: string = "",
周成波's avatar
周成波 committed
33 34
    width: string = "960",
    height: string = "512",
周成波's avatar
周成波 committed
35
    sampler_index: string = "DPM++ 2M Karras",
周成波's avatar
周成波 committed
36
    seed: string = "-1",
周成波's avatar
周成波 committed
37
    steps: string = "25",
周成波's avatar
周成波 committed
38
    cfg_scale: string = "9",
39
  ): Promise<{"domain_image_path": string, "local_image_path": string}> {
周成波's avatar
周成波 committed
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58
    if (!prompt) {
      return Promise.reject("SD提示词不能为空");
    }
    const post_data = {
      task_id: task_id,
      img_idx: img_idx,
      prompt: prompt,
      negative_prompt: negative_prompt,
      sampler_index: sampler_index,
      seed: seed,
      steps: steps,
      width: width,
      height: height,
      cfg_scale: cfg_scale,
    }
    return request.post('/text2video/text2img', post_data)
      .then((res: any) => {
        // console.log(res);
        if (res && res.code === 0) {
59
          return {"domain_image_path": res.data.result.domain_image_path, "local_image_path": res.data.result.local_image_path};
周成波's avatar
周成波 committed
60 61 62 63 64 65 66
        } else {
          const errorMessage = res ? res.message : "未知错误";
          return Promise.reject(errorMessage);
        }
      })
      .catch((err: any) => {
        console.log(err);
周成波's avatar
周成波 committed
67
        return Promise.reject("与 stable-diffusion-webui Api 通讯失败");
周成波's avatar
周成波 committed
68
      });
周成波's avatar
周成波 committed
69 70
  },

周成波's avatar
周成波 committed
71
  submitGenVideo(gen_video_param: any): Promise<string> {
周成波's avatar
周成波 committed
72 73 74
    if (!gen_video_param) {
      return Promise.reject("输入不能为空");
    }
周成波's avatar
周成波 committed
75
    const post_data = gen_video_param
周成波's avatar
周成波 committed
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
    return request.post('/text2video/gen_video', post_data)
      .then((res: any) => {
        // console.log(res);
        if (res && res.code === 0) {
          return res.data.result;
        } else {
          const errorMessage = res ? res.message : "未知错误";
          return Promise.reject(errorMessage);
        }
      })
      .catch((err: any) => {
        console.log(err);
        return Promise.reject("gen_video接口通讯失败");
      });
  },
Administrator's avatar
Administrator committed
91
}