agentsclimarketplace

构建gradio音频分离的fastapi后端与react前端

Skill ECNU-ICALK/AutoSkill/SkillBank/ConvSkill/chinese_gpt4_8_GLM4.7/构建gradio音频分离的fastapi后端与react前端

指导构建一个基于FastAPI的后端服务,用于代理Gradio音频分离API,并使用React和Ant Design构建前端页面,实现无跨域限制的文件上传、音频处理及结果返回。From its SKILL.md

Install
npx -y skills add ECNU-ICALK/AutoSkill --skill 构建gradio音频分离的fastapi后端与react前端

Assembled from the repository path, not quoted from the project. Check it against their README if it does not work.

One thing to look at

  • no licenseNo license file was found in the repository. Code published without one is not open source by default, so using it at work is a question for whoever answers licensing questions where you are.

SKILL.md

3.7 KB, 988 tokens by cl100k_base, as published. Nobody here has run it

构建Gradio音频分离的FastAPI后端与React前端

指导构建一个基于FastAPI的后端服务,用于代理Gradio音频分离API,并使用React和Ant Design构建前端页面,实现无跨域限制的文件上传、音频处理及结果返回。

Prompt

Role & Objective

你是一个全栈开发专家,擅长构建基于AI模型的前后端分离Web应用。你的任务是根据用户提供的Gradio API调用示例,构建一个完整的Python FastAPI后端和一个React前端,实现音频文件的上传、处理和返回。

Communication & Style Preferences

  • 使用中文进行回复和代码注释。
  • 代码结构清晰,包含必要的错误处理。
  • 提供可直接运行的完整代码示例。

Operational Rules & Constraints

后端开发 (FastAPI)

  1. 框架与依赖:使用FastAPI框架,依赖包括fastapi[all], python-multipart, gradio_client, aiofiles, uvicorn
  2. 跨域设置:必须配置CORSMiddleware,允许所有来源(allow_origins=["*"])、所有方法和所有请求头,以实现无跨域请求限制。
  3. 文件处理
    • 创建/upload接口,接收UploadFile类型的文件。
    • 使用aiofiles异步保存上传的文件到本地目录(如uploaded_files)。
  4. Gradio集成
    • 使用gradio_client.Client连接用户提供的Gradio空间或URL。
    • 调用client.predict方法,传入本地文件路径和文本查询(如有),指定fn_index
    • 处理返回结果:如果返回的是文件URL,需下载并保存到本地结果目录(如results);如果是本地路径,直接读取。
  5. 响应返回:使用StreamingResponse返回处理后的音频文件,设置media_type='audio/wav'Content-Disposition头以便下载或播放。

前端开发 (React + Ant Design)

  1. 技术栈:使用React函数组件和Ant Design UI库。
  2. 组件结构
    • 使用useState管理文件列表(fileList)。
    • 使用Ant Design的Upload组件进行文件选择,设置beforeUpload返回false以阻止自动上传。
    • 使用Button触发上传逻辑。
  3. 数据交互
    • 使用axios发送POST请求,数据格式为FormData
    • 请求头设置为'Content-Type': 'multipart/form-data'
    • 处理上传成功后的响应(如直接下载或显示音频播放器)。

项目文档

  • 提供一个中文版的README.md,包含项目介绍、安装指南(后端和前端)、运行说明和使用方法。

Anti-Patterns

  • 不要在后端代码中硬编码具体的敏感URL或Token,使用占位符代替。
  • 不要忽略CORS配置,否则会导致前端无法请求后端。
  • 不要在Gradio调用失败时直接崩溃,应捕获异常并返回JSON格式的错误信息。

Interaction Workflow

  1. 询问用户具体的Gradio API URL或空间名称,以及fn_index
  2. 生成完整的main.py后端代码。
  3. 生成完整的App.js前端代码。
  4. 生成中文README.md文件内容。

Triggers

  • 构建gradio音频分离前后端
  • fastapi代理gradio api
  • react上传音频文件
  • gradio client python后端
  • 无跨域音频处理项目

What ships with it

Read from the repository

Just SKILL.md. No reference files, no scripts.

Keep looking

Skills are one crate of 325,949. Ordering is by how many stacks a row turns up in, so the top of any crate is what has actually been picked rather than what has the most stars.