test_api.js 1.0 KB

1234567891011121314151617181920212223242526272829303132333435
  1. const { Client } = require("@gradio/client/dist/client.cjs");
  2. const fs = require("fs");
  3. const readVideoFile = (filePath) => {
  4. return new Promise((resolve, reject) => {
  5. fs.readFile(filePath, (err, data) => {
  6. if (err) {
  7. return reject(err);
  8. }
  9. const blob = new Blob([data], { type: "video/mp4" });
  10. resolve(blob);
  11. });
  12. });
  13. };
  14. const processVideo = async (videoPath) => {
  15. try {
  16. const videoBlob = await readVideoFile(videoPath);
  17. const client = await Client.connect("http://0.0.0.0:7860/");
  18. const result = await client.predict("/gradio_process", {
  19. video: videoBlob,
  20. threshold: 27,
  21. });
  22. console.log(result.data);
  23. } catch (error) {
  24. console.error("Error processing video:", error);
  25. }
  26. };
  27. processVideo("/path/to/your/video/file.mp4");
  28. // 调用方法并传入要处理的视频文件路径
  29. processVideo("/Users/hxc/translate_web/translate_web/plugins/video_scene/video/46c04229-4d04-480a-aa27-ee1cc23e3978.mp4");