Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

USE API #652

Open
4 of 5 tasks
Jumao-OC opened this issue Dec 19, 2024 · 1 comment
Open
4 of 5 tasks

USE API #652

Jumao-OC opened this issue Dec 19, 2024 · 1 comment
Labels
enhancement New feature or request

Comments

@Jumao-OC
Copy link

Checks

  • This template is only for feature request.
  • I have thoroughly reviewed the project documentation but couldn't find any relevant information that meets my needs.
  • I have searched for existing issues, including closed ones, and found not discussion yet.
  • I confirm that I am using English to submit this report in order to facilitate communication.

1. Is this request related to a challenge you're experiencing? Tell us your story.

to the gradio cache dir because it was not uploaded by a user.<= An error message is reported in the console. im use this api=>curl -X POST http://192.168.254.10:7860/gradio_api/call/basic_tts -s -H "Content-Type: application/json" -d '{
到渐变缓存目录,因为它不是由用户上传的。<= 控制台中报告错误消息。我使用这个api=>curl -X POST http://192.168.254.10:7860/gradio_api/call/basic_tts -s -H "Content-Type: application/json" -d '{

"data": [
“数据”: [

{"path":"https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav"},
{“路径”:“https://github.com/gradio-app/gradio/raw/main/test/test_files/audio_sample.wav”},

"Hello!!",
“你好!!”,

"Hello!!",
“你好!!”,

true,
真的,

0,
0,

4,
4、

0.3
0.3

]}'
]}'

| awk -F'"' '{ print $4}'
| awk -F'"' '{ 打印 $4}'

| read EVENT_ID; curl -N http://192.168.254.10:7860/gradio_api/call/basic_tts/$EVENT_ID*************************=> this my // 构建请求数据
|读取EVENT_ID;卷曲 -N http://192.168.254.10:7860/gradio_api/call/basic_tts/$EVENT_ID************************=> 这是我的// 构建请求数据

Map<String, Object> requestData = new HashMap<>();
Map requestData = new HashMap<>();

Map<String, Object> fileData = new HashMap<>();
Map fileData = new HashMap<>();

// 使用 HashMap 创建 meta 数据
// 使用HashMap创建元数据

Map<String, String> metaData = new HashMap<>();
Map metaData = new HashMap<>();

metaData.put("_type", "gradio.FileData");

fileData.put("path", fileToSave.getAbsolutePath());//这里需要将文件存到本地 然后拿到这个路径
System.out.println(fileToSave.getAbsolutePath() + "=======");
fileData.put("orig_name", originalFilename);
fileData.put("size", size);
fileData.put("mime_type", mimeType);
fileData.put("meta", metaData);

// 将 fileData 和 additionalData 添加到 requestData
// 将 fileData 和 additionalData 添加到 requestData

requestData.put("data", new Object[]{
requestData.put("data", new Object[]{

fileData,
fileData,

samplesText,
samplesText,

genTextInput,
genTextInput,

true,
true,

0.15,
0.15,

32,
32,

1});
1});

// 设置请求头
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);

// 创建请求实体
HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestData, headers);

// 发送 POST 请求并获取 eventId
ResponseEntity<Map> response = restTemplate.exchange(
        "http://192.168.254.10:7860/gradio_api/call/basic_tts",
        HttpMethod.POST,
        requestEntity,
        Map.class
); im want know why

2. What is your suggested solution?

SORRY, NOT SOLUTON

3. Additional context or comments

I'm using java to call the api, @PostMapping("/convertToSpeechFile")
public AjaxResult convertToSpeechFile(@RequestParam("AudioSamples") MultipartFile audioSamples, @RequestParam("SamplesText") String samplesText) {

    //接收到用户输入的文件,音频文件对应的文字内容
    //获取到文件的信息 orig_name,size,mime_type,meta:{"_type"}
    //向http://192.168.254.10:7860/gradio_api/call/basic_tts这个路径发送请求 拿到返回的eventId(POST)
    //向http://127.0.0.1:7860/gradio_api/call/basic_tts/00c8ef5983c94b058ba88cc22402f5fb发送请求,返回二进制文件流 (另外写一个方法)Get


    // 获取样本文本
    samplesText = "腾讯客服朋友圈不能发送或刷新您可尝试按照以下方式操作以检查您的账号功能是否正常如果账号.";

// 固定文本
String genTextInput = "命令的作用是阻止服务器从缓存中获取数据。具体来说,-N选项告诉curl不要使用缓存的数据,而是直接从服务器获取最新的数据。这对于确保获取最新的网页内容非常有用,尤其是在调试或测试时。";

    // 获取文件的原始名称
    String originalFilename = audioSamples.getOriginalFilename();

    // 获取文件的大小(单位:字节)
    long size = audioSamples.getSize();

    // 获取文件的MIME类型
    String mimeType = audioSamples.getContentType();


    // 定义存储路径
    String storagePath = "C:\\Users\\Administrator.DESKTOP-9VRVEFV\\AppData\\Local\\Temp\\"; // 根据需要修改路径
    File fileToSave = new File(storagePath + originalFilename);

    // 将文件保存到本地
    try (FileOutputStream fos = new FileOutputStream(fileToSave)) {
        fos.write(audioSamples.getBytes());
    } catch (IOException e) {
        return AjaxResult.error("文件保存失败:" + e.getMessage());
    }

    // 构建请求数据
    Map<String, Object> requestData = new HashMap<>();
    Map<String, Object> fileData = new HashMap<>();
    // 使用 HashMap 创建 meta 数据
    Map<String, String> metaData = new HashMap<>();

    metaData.put("_type", "gradio.FileData");

    fileData.put("path", fileToSave.getAbsolutePath());//这里需要将文件存到本地 然后拿到这个路径
    System.out.println(fileToSave.getAbsolutePath() + "=======");
    fileData.put("orig_name", originalFilename);
    fileData.put("size", size);
    fileData.put("mime_type", mimeType);
    fileData.put("meta", metaData);

// 将 fileData 和 additionalData 添加到 requestData
requestData.put("data", new Object[]{
fileData,
samplesText,
genTextInput,
true,
0.15,
32,
1});

    // 设置请求头
    HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.APPLICATION_JSON);

    // 创建请求实体
    HttpEntity<Map<String, Object>> requestEntity = new HttpEntity<>(requestData, headers);

    // 发送 POST 请求并获取 eventId
    ResponseEntity<Map> response = restTemplate.exchange(
            "http://192.168.254.10:7860/gradio_api/call/basic_tts",
            HttpMethod.POST,
            requestEntity,
            Map.class
    );

    if (response.getStatusCode().is2xxSuccessful() && response.getBody() != null) {
        String eventId = (String) response.getBody().get("event_id"); // 假设返回的 JSON 中有 eventId
        System.out.println(response + "=====================================================================");

           /*  return httpGetBinaryFile(eventId);*/
        return success(response.toString());
    } else {
        return AjaxResult.error("请求失败,状态码:" + response.getStatusCode());
    }


}This is my request

4. Can you help us with this feature?

  • I am interested in contributing to this feature.
@Jumao-OC Jumao-OC added the enhancement New feature or request label Dec 19, 2024
@SWivid
Copy link
Owner

SWivid commented Dec 25, 2024

not quite get your issue, maybe you could help explain a little bit?

@SWivid SWivid mentioned this issue Dec 25, 2024
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants