Gradio 智能体 & MCP 黑客马拉松

获奖者
Gradio logo

Gradio 新手?从这里开始:入门

查看发布历史

gradio-rs

介绍

gradio-rs 是由 @JacobLinCool 用 Rust 构建的 Gradio 客户端。您可以在这里找到仓库,在这里找到更详细的 API 文档。

用法

这是一个使用 BS-RoFormer 模型从音频文件中分离人声和背景音乐的示例。

use gradio::{PredictionInput, Client, ClientOptions};

#[tokio::main]
async fn main() {
    if std::env::args().len() < 2 {
        println!("Please provide an audio file path as an argument");
        std::process::exit(1);
    }
    let args: Vec<String> = std::env::args().collect();
    let file_path = &args[1];
    println!("File: {}", file_path);

    let client = Client::new("JacobLinCool/vocal-separation", ClientOptions::default())
        .await
        .unwrap();

    let output = client
        .predict(
            "/separate",
            vec![
                PredictionInput::from_file(file_path),
                PredictionInput::from_value("BS-RoFormer"),
            ],
        )
        .await
        .unwrap();
    println!(
        "Vocals: {}",
        output[0].clone().as_file().unwrap().url.unwrap()
    );
    println!(
        "Background: {}",
        output[1].clone().as_file().unwrap().url.unwrap()
    );
}

您可以在这里找到更多示例。

命令行界面

cargo install gradio
gr --help

stabilityai/stable-diffusion-3-medium HF Space 为例

> gr list stabilityai/stable-diffusion-3-medium
API Spec for stabilityai/stable-diffusion-3-medium:
        /infer
                Parameters:
                        prompt               ( str      ) 
                        negative_prompt      ( str      ) 
                        seed                 ( float    ) numeric value between 0 and 2147483647
                        randomize_seed       ( bool     ) 
                        width                ( float    ) numeric value between 256 and 1344
                        height               ( float    ) numeric value between 256 and 1344
                        guidance_scale       ( float    ) numeric value between 0.0 and 10.0
                        num_inference_steps  ( float    ) numeric value between 1 and 50
                Returns:
                        Result               ( filepath ) 
                        Seed                 ( float    ) numeric value between 0 and 2147483647

> gr run stabilityai/stable-diffusion-3-medium infer 'Rusty text "AI & CLI" on the snow.' '' 0 true 1024 1024 5 28
Result: https://stabilityai-stable-diffusion-3-medium.hf.space/file=/tmp/gradio/5735ca7775e05f8d56d929d8f57b099a675c0a01/image.webp
Seed: 486085626

对于文件输入,只需使用文件路径作为参数

gr run hf-audio/whisper-large-v3 predict 'test-audio.wav' 'transcribe'
output: " Did you know you can try the coolest model on your command line?"