Spaces:
Running
Running
File size: 108,712 Bytes
3a9fd79 85f62fa 3a9fd79 9deac74 3a9fd79 9deac74 43c2a6c 4051916 43c2a6c 4051916 43c2a6c 9deac74 43c2a6c 9deac74 43c2a6c 9deac74 43c2a6c 9deac74 43c2a6c 9deac74 43c2a6c 817e2bd 43c2a6c 817e2bd 9deac74 3a9fd79 7ae2c28 3a9fd79 299aa65 7ae2c28 299aa65 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 9deac74 43c2a6c 9deac74 0b18e76 6b9974f 9deac74 0b18e76 43c2a6c 9deac74 43c2a6c 9deac74 43c2a6c 0b18e76 9deac74 43c2a6c 9deac74 0b18e76 9deac74 43c2a6c 9deac74 0fa6349 9deac74 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 7ae2c28 3a9fd79 62781b7 3a9fd79 795b054 3a9fd79 7ae2c28 bd8aa67 7ae2c28 795b054 7ae2c28 bd8aa67 795b054 3a9fd79 9deac74 3a9fd79 9deac74 3a9fd79 85f62fa 3a9fd79 85f62fa 3a9fd79 85f62fa 3a9fd79 85f62fa 3a9fd79 85f62fa 3a9fd79 85f62fa 3a9fd79 85f62fa 3a9fd79 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276 2277 2278 2279 2280 2281 2282 2283 2284 2285 2286 2287 2288 2289 2290 2291 2292 2293 2294 2295 2296 2297 2298 2299 2300 2301 2302 2303 2304 2305 2306 2307 2308 2309 2310 2311 2312 2313 2314 2315 2316 2317 2318 2319 2320 2321 2322 2323 2324 2325 2326 2327 2328 2329 2330 2331 2332 2333 2334 2335 2336 2337 2338 2339 2340 2341 2342 2343 2344 2345 2346 2347 2348 2349 2350 2351 2352 2353 2354 2355 2356 2357 2358 2359 2360 2361 2362 2363 2364 2365 2366 2367 2368 2369 2370 2371 2372 2373 2374 2375 2376 2377 2378 2379 2380 2381 2382 2383 2384 2385 2386 2387 2388 2389 2390 2391 2392 2393 2394 2395 2396 2397 2398 2399 2400 2401 2402 2403 2404 2405 2406 2407 2408 2409 2410 2411 2412 2413 2414 2415 2416 2417 2418 2419 2420 2421 2422 2423 2424 2425 2426 2427 2428 2429 2430 2431 2432 2433 2434 2435 2436 2437 2438 2439 2440 2441 2442 2443 2444 2445 2446 2447 2448 2449 2450 2451 2452 2453 2454 2455 2456 2457 2458 2459 2460 2461 2462 2463 2464 2465 2466 2467 2468 2469 2470 2471 2472 2473 2474 2475 2476 2477 2478 2479 2480 2481 2482 2483 2484 2485 2486 2487 2488 2489 2490 2491 2492 2493 2494 2495 2496 2497 2498 2499 2500 2501 2502 2503 2504 2505 2506 2507 2508 2509 2510 2511 2512 2513 2514 2515 2516 2517 2518 2519 2520 2521 2522 2523 2524 2525 2526 2527 2528 2529 2530 2531 2532 2533 2534 2535 2536 2537 2538 2539 2540 2541 2542 2543 2544 2545 2546 2547 2548 2549 2550 2551 2552 2553 2554 2555 2556 2557 2558 2559 2560 2561 2562 2563 2564 2565 2566 2567 2568 2569 2570 2571 2572 2573 2574 2575 2576 2577 2578 2579 2580 2581 2582 2583 2584 2585 2586 2587 2588 2589 2590 2591 2592 2593 2594 2595 2596 2597 2598 2599 2600 2601 2602 2603 2604 2605 2606 2607 2608 2609 2610 2611 2612 2613 2614 2615 2616 2617 2618 2619 2620 2621 2622 2623 2624 2625 2626 2627 2628 2629 2630 2631 2632 2633 2634 2635 2636 2637 2638 2639 2640 2641 2642 2643 2644 2645 2646 2647 2648 2649 2650 2651 2652 2653 2654 2655 2656 2657 2658 2659 2660 2661 2662 2663 2664 2665 2666 2667 2668 2669 2670 2671 2672 2673 2674 2675 2676 2677 2678 2679 2680 2681 2682 2683 2684 2685 2686 2687 2688 2689 2690 2691 2692 2693 2694 2695 2696 2697 2698 2699 2700 2701 2702 2703 2704 2705 2706 2707 2708 2709 2710 2711 2712 2713 2714 2715 2716 2717 2718 2719 2720 2721 2722 2723 2724 2725 2726 2727 2728 2729 2730 2731 2732 2733 2734 2735 2736 2737 2738 2739 2740 2741 2742 2743 2744 2745 2746 2747 2748 2749 2750 2751 2752 2753 2754 2755 2756 2757 2758 2759 2760 2761 2762 2763 2764 2765 2766 2767 2768 2769 2770 2771 2772 2773 2774 2775 2776 2777 2778 2779 2780 2781 2782 2783 2784 2785 2786 2787 2788 2789 2790 2791 2792 2793 2794 2795 2796 2797 2798 2799 2800 2801 2802 2803 2804 2805 2806 2807 2808 2809 2810 2811 2812 2813 2814 2815 2816 2817 2818 2819 2820 2821 2822 2823 2824 2825 2826 2827 2828 2829 2830 2831 2832 2833 2834 2835 2836 2837 2838 2839 |
"""
VoiceKit - MCP Server for Voice Analysis
6 MCP tools for voice processing (all accept base64 audio):
- Embedding extraction, voice comparison, acoustic analysis
- Speech-to-text, voice isolation, similarity analysis
MCP Endpoint: https://mcp-1st-birthday-voicekit.hf.space/gradio_api/mcp/sse
"""
import gradio as gr
import base64
import os
import json
import tempfile
import math
import re
# Set Gradio temp directory to current directory
GRADIO_TEMP_DIR = os.path.join(os.getcwd(), "gradio_temp")
os.makedirs(GRADIO_TEMP_DIR, exist_ok=True)
os.environ['GRADIO_TEMP_DIR'] = GRADIO_TEMP_DIR
tempfile.tempdir = GRADIO_TEMP_DIR
# Modal connection (requires MODAL_TOKEN_ID and MODAL_TOKEN_SECRET in HF Secrets)
try:
import modal
AudioAnalyzer = modal.Cls.from_name("voice-semantle", "AudioAnalyzer")
analyzer = AudioAnalyzer()
modal_available = True
print("Modal connected!")
except Exception as e:
modal_available = False
analyzer = None
print(f"Modal not available: {e}")
# Load README.md and convert to HTML
def load_readme_as_html():
"""Load README.md and convert markdown to HTML"""
try:
with open("README.md", "r", encoding="utf-8") as f:
content = f.read()
# Remove YAML front matter
content = re.sub(r'^---\n.*?\n---\n', '', content, flags=re.DOTALL)
html = content
# Headers
html = re.sub(r'^### (.+)$', r'<h3>\1</h3>', html, flags=re.MULTILINE)
html = re.sub(r'^## (.+)$', r'<h2>\1</h2>', html, flags=re.MULTILINE)
html = re.sub(r'^# (.+)$', r'<h1>\1</h1>', html, flags=re.MULTILINE)
# Code blocks - preserve content without adding extra newlines
def format_code_block(match):
code = match.group(2).strip()
# Replace internal newlines with a placeholder, then restore after processing
# This prevents the paragraph logic from adding extra breaks
code_escaped = code.replace('\n', '<!-- NEWLINE -->')
return f'<pre><code>{code_escaped}</code></pre>'
html = re.sub(r'```(\w*)\n(.*?)```', format_code_block, html, flags=re.DOTALL)
# Images - convert relative paths to HuggingFace raw file URLs
# Handle both <img> tags and markdown image syntax
HF_BASE_URL = "https://huggingface.co/spaces/MCP-1st-Birthday/voicekit/resolve/main"
def convert_image_path(match):
src = match.group(1)
# If it's a relative path (not starting with http), convert to HF URL
if not src.startswith('http'):
src = f"{HF_BASE_URL}/{src}"
return f'<img src="{src}" style="max-width:100%; height:auto; border-radius:8px; margin:12px 0;">'
html = re.sub(r'<img src="([^"]+)"[^>]*>', convert_image_path, html)
# Inline code (but not inside <pre><code> blocks)
html = re.sub(r'`([^`]+)`', r'<code>\1</code>', html)
# Bold
html = re.sub(r'\*\*(.+?)\*\*', r'<strong>\1</strong>', html)
# Links
html = re.sub(r'\[([^\]]+)\]\(([^)]+)\)', r'<a href="\2" target="_blank">\1</a>', html)
# Tables
lines = html.split('\n')
in_table = False
table_html = []
new_lines = []
for line in lines:
if '|' in line and line.strip().startswith('|'):
if not in_table:
in_table = True
table_html = ['<table>']
if re.match(r'^\|[\s\-:|]+\|$', line.strip()):
continue
cells = [c.strip() for c in line.strip().split('|')[1:-1]]
if len(table_html) == 1:
table_html.append('<thead><tr>')
for cell in cells:
table_html.append(f'<th>{cell}</th>')
table_html.append('</tr></thead><tbody>')
else:
table_html.append('<tr>')
for cell in cells:
table_html.append(f'<td>{cell}</td>')
table_html.append('</tr>')
else:
if in_table:
table_html.append('</tbody></table>')
new_lines.append(''.join(table_html))
table_html = []
in_table = False
new_lines.append(line)
if in_table:
table_html.append('</tbody></table>')
new_lines.append(''.join(table_html))
html = '\n'.join(new_lines)
# Lists
html = re.sub(r'^- (.+)$', r'<li>\1</li>', html, flags=re.MULTILINE)
html = re.sub(r'(<li>.*</li>\n?)+', r'<ul>\g<0></ul>', html)
# Paragraphs - skip lines that are inside pre/code blocks
lines = html.split('\n')
result = []
for line in lines:
stripped = line.strip()
if stripped and not stripped.startswith('<') and not stripped.startswith('```'):
result.append(f'<p>{stripped}</p>')
else:
result.append(line)
# Join and restore newlines in code blocks
final_html = '\n'.join(result)
final_html = final_html.replace('<!-- NEWLINE -->', '\n')
# Escape curly braces for f-string compatibility
final_html = final_html.replace('{', '{{').replace('}', '}}')
return final_html
except Exception as e:
return f"<p>Error loading README: {e}</p>"
readme_html = load_readme_as_html()
def file_to_base64(file_path: str) -> str:
"""Convert file path to base64 string"""
if not file_path:
return ""
with open(file_path, "rb") as f:
return base64.b64encode(f.read()).decode()
# ============================================================================
# MCP Tools (all accept base64 directly)
# ============================================================================
def extract_embedding(audio_base64: str) -> str:
"""
Extract voice embedding using Wav2Vec2.
Returns a 768-dimensional vector representing voice characteristics.
Useful for voice comparison, speaker identification, etc.
Args:
audio_base64: Audio file as base64 encoded string
Returns:
embedding (768-dim list), model, dim
"""
if not modal_available:
return json.dumps({"error": "Modal not available. Please set MODAL_TOKEN_ID and MODAL_TOKEN_SECRET in HF Secrets."})
if not audio_base64:
return json.dumps({"error": "No audio provided"})
try:
result = analyzer.extract_embedding.remote(audio_base64)
if "embedding" in result:
result["embedding_preview"] = result["embedding"][:5] + ["..."]
result["embedding_length"] = len(result["embedding"])
del result["embedding"]
return json.dumps(result, ensure_ascii=False, indent=2)
except Exception as e:
return json.dumps({"error": str(e)})
def match_voice(audio1_base64: str, audio2_base64: str) -> str:
"""
Compare similarity between two voices.
Extracts Wav2Vec2 embeddings and calculates cosine similarity.
Useful for checking if the same person spoke with similar tone.
Args:
audio1_base64: First audio as base64 encoded string
audio2_base64: Second audio as base64 encoded string
Returns:
similarity (0-1), tone_score (0-100)
"""
if not modal_available:
return json.dumps({"error": "Modal not available. Please set MODAL_TOKEN_ID and MODAL_TOKEN_SECRET in HF Secrets."})
if not audio1_base64 or not audio2_base64:
return json.dumps({"error": "Both audio files required"})
try:
result = analyzer.compare_voices.remote(audio1_base64, audio2_base64)
return json.dumps(result, ensure_ascii=False, indent=2)
except Exception as e:
return json.dumps({"error": str(e)})
def analyze_acoustics(audio_base64: str) -> str:
"""
Analyze acoustic features of audio.
Extracts pitch, energy, rhythm, tempo, and spectral characteristics.
Useful for understanding voice expressiveness and characteristics.
Args:
audio_base64: Audio file as base64 encoded string
Returns:
pitch, energy, rhythm, tempo, spectral information
"""
if not modal_available:
return json.dumps({"error": "Modal not available. Please set MODAL_TOKEN_ID and MODAL_TOKEN_SECRET in HF Secrets."})
if not audio_base64:
return json.dumps({"error": "No audio provided"})
try:
result = analyzer.analyze_acoustic_features.remote(audio_base64)
return json.dumps(result, ensure_ascii=False, indent=2)
except Exception as e:
return json.dumps({"error": str(e)})
def transcribe_audio(audio_base64: str, language: str = "en") -> str:
"""
Convert audio to text (Speech-to-Text).
Uses ElevenLabs Scribe v1 model for high-quality speech recognition.
Supports various languages.
Args:
audio_base64: Audio file as base64 encoded string
language: Language code (e.g., "en", "ko", "ja"). Default is "en"
Returns:
text, language, model
"""
if not modal_available:
return json.dumps({"error": "Modal not available. Please set MODAL_TOKEN_ID and MODAL_TOKEN_SECRET in HF Secrets."})
if not audio_base64:
return json.dumps({"error": "No audio provided"})
try:
result = analyzer.transcribe_audio.remote(audio_base64, language)
return json.dumps(result, ensure_ascii=False, indent=2)
except Exception as e:
return json.dumps({"error": str(e)})
def isolate_voice(audio_base64: str) -> str:
"""
Remove background music (BGM) and extract voice only.
Uses ElevenLabs Voice Isolator to remove music, noise, etc.
Useful for memes, songs, and other audio with background sounds.
Args:
audio_base64: Audio file as base64 encoded string
Returns:
isolated_audio_base64, metadata (bgm_detected, sizes, duration)
"""
if not modal_available:
return json.dumps({"error": "Modal not available. Please set MODAL_TOKEN_ID and MODAL_TOKEN_SECRET in HF Secrets."})
if not audio_base64:
return json.dumps({"error": "No audio provided"})
try:
result = analyzer.isolate_voice.remote(audio_base64)
return json.dumps(result, ensure_ascii=False, indent=2)
except Exception as e:
return json.dumps({"error": str(e)})
def grade_voice(
user_audio_base64: str,
reference_audio_base64: str,
reference_text: str = "",
category: str = "meme"
) -> str:
"""
Comprehensively compare and analyze user voice with reference voice.
Evaluates with 5 metrics:
- pronunciation: Pronunciation accuracy (STT-based)
- tone: Voice timbre similarity (Wav2Vec2 embedding)
- pitch: Pitch matching
- rhythm: Rhythm sense
- energy: Energy expressiveness
Args:
user_audio_base64: User audio as base64 encoded string
reference_audio_base64: Reference audio as base64 encoded string
reference_text: Reference text (optional, enables pronunciation scoring)
category: Category (meme, song, movie) - determines weights
Returns:
overall_score, metrics, weak_points, strong_points, feedback
"""
if not modal_available:
return json.dumps({"error": "Modal not available. Please set MODAL_TOKEN_ID and MODAL_TOKEN_SECRET in HF Secrets."})
if not user_audio_base64 or not reference_audio_base64:
return json.dumps({"error": "Both user and reference audio required"})
try:
result = analyzer.analyze_audio.remote(
user_audio_base64=user_audio_base64,
reference_audio_base64=reference_audio_base64,
reference_text=reference_text if reference_text else None,
challenge_id="mcp_analysis",
category=category,
)
# Simplify output for backend/API use
metrics = result.get("metrics", {})
simple_result = {
"pitch": metrics.get("pitch", 0),
"rhythm": metrics.get("rhythm", 0),
"energy": metrics.get("energy", 0),
"pronunciation": metrics.get("pronunciation", 0),
"transcript": metrics.get("transcript", 0),
"overall": result.get("overall_score", 0),
"user_text": result.get("user_text", "")
}
return json.dumps(simple_result, ensure_ascii=False, indent=2)
except Exception as e:
return json.dumps({"error": str(e)})
# ============================================================================
# Demo Functions for UI
# ============================================================================
def demo_acoustic_analysis(audio_file):
"""Acoustic Analysis - Analyze pitch, energy, rhythm, tempo"""
if not audio_file:
return create_acoustic_empty()
audio_b64 = file_to_base64(audio_file)
result_json = analyze_acoustics(audio_b64)
try:
result = json.loads(result_json)
if "error" in result:
return f'''<div style="color: #ef4444; padding: 20px; background: #fee; border-radius: 12px; border: 1px solid #fca5a5;">
<strong>Error in result:</strong><br>{result.get("error", "Unknown error")}
</div>'''
return create_acoustic_visualization(result)
except Exception as e:
return f'''<div style="color: #ef4444; padding: 20px; background: #fee; border-radius: 12px; border: 1px solid #fca5a5;">
<strong>Parsing Error:</strong> {str(e)}<br><br>
<strong>Raw Result (first 500 chars):</strong><br>
<code style="display: block; padding: 10px; background: white; border-radius: 4px; overflow-x: auto; font-size: 12px;">{result_json[:500]}</code>
</div>'''
def demo_transcribe_audio(audio_file, language):
"""Audio Transcription"""
if not audio_file:
return create_transcription_empty()
audio_b64 = file_to_base64(audio_file)
result_json = transcribe_audio(audio_b64, language)
try:
result = json.loads(result_json)
if "error" in result:
return create_transcription_empty()
text = result.get("text", "")
return create_transcription_visualization(text)
except:
return create_transcription_empty()
def demo_clean_extraction(audio_file):
"""Clean Audio Extraction - returns audio file only"""
if not audio_file:
return None
audio_b64 = file_to_base64(audio_file)
result_json = isolate_voice(audio_b64)
try:
result = json.loads(result_json)
if "error" in result:
return None
# Convert isolated audio base64 back to file
import tempfile
isolated_audio_bytes = base64.b64decode(result["isolated_audio_base64"])
with tempfile.NamedTemporaryFile(suffix=".wav", delete=False) as tmp:
tmp.write(isolated_audio_bytes)
isolated_audio_path = tmp.name
return isolated_audio_path
except:
return None
def demo_extract_embedding(audio_file):
"""Extract Embedding - extract voice fingerprint"""
if not audio_file:
return create_embedding_empty()
audio_b64 = file_to_base64(audio_file)
result_json = extract_embedding(audio_b64)
try:
result = json.loads(result_json)
if "error" in result:
return f'''<div style="color: #ef4444; padding: 20px; background: #fee; border-radius: 12px; border: 1px solid #fca5a5;">
<strong>Error in result:</strong><br>{result.get("error", "Unknown error")}
</div>'''
return create_embedding_visualization(result)
except Exception as e:
return f'''<div style="color: #ef4444; padding: 20px; background: #fee; border-radius: 12px; border: 1px solid #fca5a5;">
<strong>Parsing Error:</strong> {str(e)}<br><br>
<strong>Raw Result (first 500 chars):</strong><br>
<code style="display: block; padding: 10px; background: white; border-radius: 4px; overflow-x: auto; font-size: 12px;">{result_json[:500]}</code>
</div>'''
def demo_match_voice(audio1, audio2):
"""Compare Voices - compare two voice similarities"""
if not audio1 or not audio2:
return create_compare_empty()
audio1_b64 = file_to_base64(audio1)
audio2_b64 = file_to_base64(audio2)
result_json = match_voice(audio1_b64, audio2_b64)
try:
result = json.loads(result_json)
if "error" in result:
return create_compare_empty()
return create_compare_visualization(result)
except:
return create_compare_empty()
def demo_voice_similarity(user_audio, ref_audio):
"""Voice Similarity - comprehensive 5-metric analysis"""
if not user_audio or not ref_audio:
return create_similarity_empty()
user_b64 = file_to_base64(user_audio)
ref_b64 = file_to_base64(ref_audio)
result_json = grade_voice(user_b64, ref_b64, "", "meme")
try:
result = json.loads(result_json)
if "error" in result:
return create_similarity_empty()
return create_similarity_visualization(result)
except:
return create_similarity_empty()
# ============================================================================
# Visualization Functions
# ============================================================================
def create_acoustic_empty():
"""Empty state for acoustic analysis"""
return """
<div style="
background: rgba(10, 10, 26, 0.4);
border: 1px solid rgba(124, 58, 237, 0.2);
border-radius: 16px;
padding: 30px 20px;
text-align: center;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
">
<div style="margin-bottom: 12px; opacity: 0.5;">
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" style="margin: 0 auto; display: block;">
<path d="M22 10C22 10 20 4 17 4C14 4 12 16 9 16C6 16 4 10 2 10" stroke="#7c3aed" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<g transform="translate(13, 11)">
<circle cx="5" cy="5" r="4" stroke="#7c3aed" stroke-width="1.5"/>
<path d="M8 8L11 11" stroke="#7c3aed" stroke-width="1.5" stroke-linecap="round"/>
</g>
</svg>
</div>
<div style="color: #a5b4fc; font-size: 12px; line-height: 1.5;">
Upload audio to analyze acoustic features
</div>
</div>
"""
def create_acoustic_visualization(result):
"""Acoustic analysis visualization with radar chart"""
pitch = result.get("pitch", {})
energy = result.get("energy", {})
rhythm = result.get("rhythm", {})
tempo = result.get("tempo", 0)
spectral = result.get("spectral", {})
# Use pre-calculated scores from Modal backend (already 0-100)
pitch_norm = pitch.get("score", 0)
energy_norm = energy.get("score", 0)
rhythm_norm = rhythm.get("score", 0)
spectral_norm = spectral.get("score", 0)
# Tempo: normalize BPM to 0-100 (60-180 BPM range)
tempo_bpm = tempo
tempo_norm = min(100, max(0, (tempo_bpm - 60) / 120 * 100)) if tempo_bpm > 0 else 0
# Radar chart calculation
center_x, center_y = 150, 150
radius = 110
# 5 metrics in order: Pitch(top), Energy(top-right), Rhythm(bottom-right), Tempo(bottom-left), Spectral(top-left)
metrics = [
("Pitch", pitch_norm, -90), # 0° - 90° = -90° (top)
("Energy", energy_norm, -18), # 72° - 90° = -18° (top-right)
("Rhythm", rhythm_norm, 54), # 144° - 90° = 54° (bottom-right)
("Tempo", tempo_norm, 126), # 216° - 90° = 126° (bottom-left)
("Spectral", spectral_norm, 198) # 288° - 90° = 198° (top-left)
]
# Calculate polygon points for data
data_points = []
for _, value, angle_deg in metrics:
angle_rad = math.radians(angle_deg)
point_radius = (value / 100) * radius
x = center_x + point_radius * math.cos(angle_rad)
y = center_y + point_radius * math.sin(angle_rad)
data_points.append(f"{x:.2f},{y:.2f}")
# Background concentric pentagons (20, 40, 60, 80, 100)
def create_pentagon_points(scale):
points = []
for _, _, angle_deg in metrics:
angle_rad = math.radians(angle_deg)
r = radius * scale
x = center_x + r * math.cos(angle_rad)
y = center_y + r * math.sin(angle_rad)
points.append(f"{x:.2f},{y:.2f}")
return " ".join(points)
background_pentagons = ""
for scale in [0.2, 0.4, 0.6, 0.8, 1.0]:
background_pentagons += f'<polygon points="{create_pentagon_points(scale)}" fill="none" stroke="rgba(124, 58, 237, 0.15)" stroke-width="1"/>'
# Axis lines from center to vertices
axis_lines = ""
for _, _, angle_deg in metrics:
angle_rad = math.radians(angle_deg)
x = center_x + radius * math.cos(angle_rad)
y = center_y + radius * math.sin(angle_rad)
axis_lines += f'<line x1="{center_x}" y1="{center_y}" x2="{x:.2f}" y2="{y:.2f}" stroke="rgba(124, 58, 237, 0.3)" stroke-width="1"/>'
# Labels at vertices
labels = ""
for label, value, angle_deg in metrics:
angle_rad = math.radians(angle_deg)
# Position label outside the pentagon
label_radius = radius + 25
x = center_x + label_radius * math.cos(angle_rad)
y = center_y + label_radius * math.sin(angle_rad)
labels += f'''<text x="{x:.2f}" y="{y:.2f}" text-anchor="middle" dominant-baseline="middle" fill="#a5b4fc" font-size="11" font-weight="600">
{label}
<tspan x="{x:.2f}" dy="12" fill="#a855f7" font-size="13" font-weight="700">{int(value)}</tspan>
</text>'''
return f"""
<div style="
background: rgba(10, 10, 26, 0.6);
border: 1px solid rgba(124, 58, 237, 0.3);
border-radius: 16px;
padding: 20px;
display: flex;
align-items: center;
justify-content: center;
">
<svg width="300" height="300" viewBox="0 0 300 300">
<!-- Background pentagons -->
{background_pentagons}
<!-- Axis lines -->
{axis_lines}
<!-- Data polygon -->
<polygon points="{' '.join(data_points)}"
fill="rgba(124, 58, 237, 0.3)"
stroke="#a855f7"
stroke-width="2"/>
<!-- Data points -->
{''.join([f'<circle cx="{pt.split(",")[0]}" cy="{pt.split(",")[1]}" r="4" fill="#a855f7"/>' for pt in data_points])}
<!-- Labels -->
{labels}
</svg>
</div>
"""
def create_mimicry_empty():
"""Empty state for voice mimicry game"""
return """
<div style="
background: rgba(10, 10, 26, 0.4);
border: 1px solid rgba(124, 58, 237, 0.2);
border-radius: 16px;
padding: 30px 20px;
text-align: center;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
">
<div style="margin-bottom: 12px; opacity: 0.5;">
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" style="margin: 0 auto; display: block;">
<defs>
<linearGradient id="micGradEmpty" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#8b5cf6"/>
<stop offset="100%" style="stop-color:#6366f1"/>
</linearGradient>
</defs>
<path d="M12 14c1.66 0 3-1.34 3-3V5c0-1.66-1.34-3-3-3S9 3.34 9 5v6c0 1.66 1.34 3 3 3z" fill="url(#micGradEmpty)"/>
<path d="M17 11c0 2.76-2.24 5-5 5s-5-2.24-5-5H5c0 3.53 2.61 6.43 6 6.92V21h2v-3.08c3.39-.49 6-3.39 6-6.92h-2z" fill="url(#micGradEmpty)"/>
</svg>
</div>
<div style="color: #a5b4fc; font-size: 12px; line-height: 1.5;">
Upload reference and your voice to see similarity scores
</div>
</div>
"""
def create_mimicry_visualization(result):
"""Voice mimicry score visualization with progress bars"""
pronunciation = result.get("pronunciation", 0)
tone = result.get("transcript", 0) # Tone score
pitch = result.get("pitch", 0)
rhythm = result.get("rhythm", 0)
energy = result.get("energy", 0)
def create_progress_bar(label, value):
return f"""
<div style="display: flex; align-items: center; gap: 12px; margin-bottom: 10px;">
<div style="flex: 1;">
<div style="font-size: 11px; color: #cbd5e1; margin-bottom: 4px;">{label}</div>
<div style="
height: 6px;
background: rgba(124, 58, 237, 0.2);
border-radius: 3px;
overflow: hidden;
">
<div style="
height: 100%;
width: {value}%;
background: linear-gradient(90deg, #6366f1, #22d3ee);
border-radius: 3px;
"></div>
</div>
</div>
<div style="
font-size: 14px;
font-weight: 700;
color: #22d3ee;
min-width: 32px;
text-align: right;
">{value}</div>
</div>
"""
return f"""
<div style="
background: rgba(10, 10, 26, 0.6);
border: 1px solid rgba(124, 58, 237, 0.3);
border-radius: 16px;
padding: 20px;
height: 100%;
display: flex;
flex-direction: column;
">
<div style="
display: flex;
align-items: center;
gap: 10px;
margin-bottom: 16px;
padding-bottom: 14px;
border-bottom: 1px solid rgba(124, 58, 237, 0.2);
">
<div style="
width: 40px;
height: 40px;
border-radius: 10px;
background: linear-gradient(135deg, #7c3aed, #6366f1);
display: flex;
align-items: center;
justify-content: center;
flex-shrink: 0;
">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
<circle cx="12" cy="12" r="10" fill="rgba(255, 255, 255, 0.2)" stroke="white" stroke-width="1.5"/>
<text x="12" y="16" text-anchor="middle" font-size="10" fill="white" font-weight="bold">AI</text>
</svg>
</div>
<div style="flex: 1; min-width: 0;">
<div style="font-size: 10px; color: #a5b4fc; text-transform: uppercase; letter-spacing: 1px;">CLAUDE</div>
<div style="font-size: 11px; color: #cbd5e1; line-height: 1.4;">
Wow, that voice input, takes analytical skills of course but I'll handle it
</div>
</div>
</div>
<div style="flex: 1;">
{create_progress_bar("Pronunciation", pronunciation)}
{create_progress_bar("Tone", tone)}
{create_progress_bar("Pitch", pitch)}
{create_progress_bar("Rhythm", rhythm)}
{create_progress_bar("Energy", energy)}
</div>
</div>
"""
def create_transcription_empty():
"""Empty state for transcription"""
return """
<div style="
background: rgba(10, 10, 26, 0.4);
border: 1px solid rgba(124, 58, 237, 0.2);
border-radius: 12px;
padding: 20px;
text-align: center;
color: #a5b4fc;
font-size: 13px;
">
Upload audio to transcribe
</div>
"""
def create_transcription_visualization(text):
"""Simple text display for transcription result"""
return f"""
<div style="
background: rgba(10, 10, 26, 0.6);
border: 1px solid rgba(124, 58, 237, 0.3);
border-radius: 12px;
padding: 20px;
color: #e2e8f0;
font-size: 20px;
line-height: 1.6;
white-space: pre-wrap;
word-wrap: break-word;
">
{text if text else "Transcription completed"}
</div>
"""
def create_embedding_empty():
"""Empty state for embedding extraction"""
return """
<div style="
background: rgba(10, 10, 26, 0.4);
border: 1px solid rgba(124, 58, 237, 0.2);
border-radius: 16px;
padding: 30px 20px;
text-align: center;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
">
<div style="margin-bottom: 12px; opacity: 0.5;">
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" style="margin: 0 auto; display: block;">
<path d="M21 16V8L12 4L3 8V16L12 20L21 16Z" stroke="#A855F7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 4V12M12 12V20M12 12L21 8M12 12L3 8" stroke="#A855F7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="12" cy="12" r="2" fill="#A855F7"/>
</svg>
</div>
<div style="color: #a5b4fc; font-size: 12px; line-height: 1.5;">
Upload audio to extract voice embedding
</div>
</div>
"""
def create_embedding_visualization(result):
"""Embedding extraction visualization"""
model = result.get("model", "Wav2Vec2")
dim = result.get("embedding_length", result.get("dim", 768))
preview = result.get("embedding_preview", [])
# Filter only numeric values to avoid format errors with strings like "..."
if preview:
numeric_preview = [v for v in preview if isinstance(v, (int, float))]
preview_str = ", ".join([f"{v:.4f}" for v in numeric_preview]) if numeric_preview else "..."
else:
preview_str = "..."
return f"""
<div style="
background: rgba(10, 10, 26, 0.6);
border: 1px solid rgba(124, 58, 237, 0.3);
border-radius: 16px;
padding: 20px;
height: 100%;
display: flex;
flex-direction: column;
">
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding: 10px; background: rgba(124, 58, 237, 0.1); border-radius: 8px;">
<div style="font-size: 16px; color: #cbd5e1; font-weight: 600;">Model</div>
<div style="font-size: 18px; font-weight: 700; color: #22d3ee;">{model}</div>
</div>
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; padding: 10px; background: rgba(124, 58, 237, 0.1); border-radius: 8px;">
<div style="font-size: 16px; color: #cbd5e1; font-weight: 600;">Dimensions</div>
<div style="font-size: 18px; font-weight: 700; color: #22d3ee;">{dim}</div>
</div>
<div style="padding: 10px; background: rgba(124, 58, 237, 0.1); border-radius: 8px;">
<div style="font-size: 16px; color: #cbd5e1; font-weight: 600; margin-bottom: 8px;">Preview</div>
<div style="font-size: 14px; font-family: monospace; color: #22d3ee; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;">
[{preview_str}]
</div>
</div>
</div>
"""
def create_compare_empty():
"""Empty state for voice comparison"""
return """
<div style="
background: rgba(10, 10, 26, 0.4);
border: 1px solid rgba(124, 58, 237, 0.2);
border-radius: 16px;
padding: 30px 20px;
text-align: center;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
">
<div style="margin-bottom: 12px; opacity: 0.5;">
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" style="margin: 0 auto; display: block;">
<path d="M2 10V14" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M5 8V16" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M8 11V13" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M22 10V14" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M19 7V17" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M16 11V13" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M10 12H14" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
</svg>
</div>
<div style="color: #a5b4fc; font-size: 12px; line-height: 1.5;">
Upload two audio files to compare voices
</div>
</div>
"""
def create_compare_visualization(result):
"""Voice comparison visualization with similarity score"""
similarity = result.get("similarity", 0)
tone_score = result.get("tone_score", 0)
# Convert similarity to percentage
similarity_pct = int(similarity * 100)
# Color based on similarity - Purple theme matching VOICE SIMILARITY
if similarity_pct >= 80:
color = "#c084fc" # Light purple (high score)
elif similarity_pct >= 60:
color = "#a855f7" # Medium purple (medium score)
else:
color = "#7c3aed" # Dark purple (low score)
return f"""
<div style="
background: rgba(10, 10, 26, 0.6);
border: 1px solid rgba(124, 58, 237, 0.3);
border-radius: 16px;
padding: 20px;
height: 100%;
display: flex;
align-items: flex-end;
justify-content: center;
padding-bottom: 40px;
">
<div style="
width: 160px;
height: 160px;
border-radius: 50%;
background: conic-gradient({color} 0deg {similarity_pct * 3.6}deg, rgba(124, 58, 237, 0.2) {similarity_pct * 3.6}deg 360deg);
display: flex;
align-items: center;
justify-content: center;
">
<div style="
width: 130px;
height: 130px;
border-radius: 50%;
background: rgba(10, 10, 26, 0.9);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
">
<span style="font-size: 40px; font-weight: 700; color: {color};">{similarity_pct}</span>
<span style="font-size: 11px; color: #a5b4fc; letter-spacing: 0.5px;">SIMILARITY</span>
</div>
</div>
</div>
"""
def create_similarity_empty():
"""Empty state for voice similarity analysis"""
return """
<div style="
background: rgba(10, 10, 26, 0.4);
border: 1px solid rgba(124, 58, 237, 0.2);
border-radius: 16px;
padding: 30px 20px;
text-align: center;
height: 100%;
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
">
<div style="margin-bottom: 12px; opacity: 0.5;">
<svg width="48" height="48" viewBox="0 0 24 24" fill="none" style="margin: 0 auto; display: block;">
<circle cx="12" cy="12" r="9" stroke="#A855F7" stroke-width="1" opacity="0.3"/>
<path d="M12 5L18 9L16.5 18H7.5L6 9L12 5Z" fill="#A855F7" fill-opacity="0.4" stroke="#A855F7" stroke-width="2" stroke-linejoin="round"/>
<circle cx="12" cy="5" r="1.5" fill="#A855F7"/>
</svg>
</div>
<div style="color: #a5b4fc; font-size: 12px; line-height: 1.5;">
Upload audio files for comprehensive similarity analysis
</div>
</div>
"""
def create_similarity_visualization(result):
"""Voice similarity visualization with radar chart"""
overall = result.get("overall", 0)
pronunciation = result.get("pronunciation", 0)
transcript = result.get("transcript", 0)
pitch = result.get("pitch", 0)
rhythm = result.get("rhythm", 0)
energy = result.get("energy", 0)
# Color based on overall score - Purple theme
if overall >= 80:
color = "#c084fc" # Light purple (high score)
elif overall >= 60:
color = "#a855f7" # Medium purple (medium score)
else:
color = "#7c3aed" # Dark purple (low score)
# Radar chart calculation
center_x, center_y = 150, 150
radius = 110
# 5 metrics in order: Pronunciation(top), Transcript(top-right), Pitch(bottom-right), Energy(bottom-left), Rhythm(top-left)
metrics = [
("Pronunciation", pronunciation, -90), # 0° - 90° = -90° (top)
("Transcript", transcript, -18), # 72° - 90° = -18° (top-right)
("Pitch", pitch, 54), # 144° - 90° = 54° (bottom-right)
("Energy", energy, 126), # 216° - 90° = 126° (bottom-left)
("Rhythm", rhythm, 198) # 288° - 90° = 198° (top-left)
]
# Calculate polygon points for data
data_points = []
for _, value, angle_deg in metrics:
angle_rad = math.radians(angle_deg)
point_radius = (value / 100) * radius
x = center_x + point_radius * math.cos(angle_rad)
y = center_y + point_radius * math.sin(angle_rad)
data_points.append(f"{x:.2f},{y:.2f}")
# Background concentric pentagons (20, 40, 60, 80, 100)
def create_pentagon_points(scale):
points = []
for _, _, angle_deg in metrics:
angle_rad = math.radians(angle_deg)
r = radius * scale
x = center_x + r * math.cos(angle_rad)
y = center_y + r * math.sin(angle_rad)
points.append(f"{x:.2f},{y:.2f}")
return " ".join(points)
background_pentagons = ""
for scale in [0.2, 0.4, 0.6, 0.8, 1.0]:
background_pentagons += f'<polygon points="{create_pentagon_points(scale)}" fill="none" stroke="rgba(124, 58, 237, 0.15)" stroke-width="1"/>'
# Axis lines from center to vertices
axis_lines = ""
for _, _, angle_deg in metrics:
angle_rad = math.radians(angle_deg)
x = center_x + radius * math.cos(angle_rad)
y = center_y + radius * math.sin(angle_rad)
axis_lines += f'<line x1="{center_x}" y1="{center_y}" x2="{x:.2f}" y2="{y:.2f}" stroke="rgba(124, 58, 237, 0.3)" stroke-width="1"/>'
# Labels at vertices
labels = ""
for label, value, angle_deg in metrics:
angle_rad = math.radians(angle_deg)
# Position label outside the pentagon
label_radius = radius + 25
x = center_x + label_radius * math.cos(angle_rad)
y = center_y + label_radius * math.sin(angle_rad)
labels += f'''<text x="{x:.2f}" y="{y:.2f}" text-anchor="middle" dominant-baseline="middle" fill="#a5b4fc" font-size="11" font-weight="600">
{label}
<tspan x="{x:.2f}" dy="12" fill="#a855f7" font-size="13" font-weight="700">{value}</tspan>
</text>'''
return f"""
<div style="
background: rgba(10, 10, 26, 0.6);
border: 1px solid rgba(124, 58, 237, 0.3);
border-radius: 16px;
padding: 20px;
display: flex;
align-items: center;
gap: 30px;
">
<!-- Left: Overall Score Donut -->
<div style="flex: 1; display: flex; align-items: center; justify-content: center;">
<div style="
width: 160px;
height: 160px;
border-radius: 50%;
background: conic-gradient({color} 0deg {overall * 3.6}deg, rgba(124, 58, 237, 0.2) {overall * 3.6}deg 360deg);
display: flex;
align-items: center;
justify-content: center;
">
<div style="
width: 130px;
height: 130px;
border-radius: 50%;
background: rgba(10, 10, 26, 0.9);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
">
<span style="font-size: 40px; font-weight: 700; color: {color};">{overall}</span>
<span style="font-size: 11px; color: #a5b4fc; letter-spacing: 0.5px;">OVERALL</span>
</div>
</div>
</div>
<!-- Right: Radar Chart -->
<div style="flex: 1; display: flex; align-items: center; justify-content: center;">
<svg width="300" height="300" viewBox="0 0 300 300">
<!-- Background pentagons -->
{background_pentagons}
<!-- Axis lines -->
{axis_lines}
<!-- Data polygon -->
<polygon points="{' '.join(data_points)}"
fill="rgba(124, 58, 237, 0.3)"
stroke="#a855f7"
stroke-width="2"/>
<!-- Data points -->
{''.join([f'<circle cx="{pt.split(",")[0]}" cy="{pt.split(",")[1]}" r="4" fill="#a855f7"/>' for pt in data_points])}
<!-- Labels -->
{labels}
</svg>
</div>
</div>
"""
# Clean audio functions removed - using gr.Audio component directly
# ============================================================================
# Gradio Interface with Dark Theme
# ============================================================================
custom_css = """
/* ===== DARK THEME STYLING (CSS-ONLY) ===== */
/* This CSS forces dark mode appearance regardless of system/Gradio theme */
/* All colors are SOLID (not rgba/transparent) to ensure consistent appearance */
:root {
color-scheme: dark !important;
--body-background-fill: #0a0a1a !important;
--background-fill-primary: #0d0d1a !important;
--background-fill-secondary: #12122a !important;
--block-background-fill: #0d0d1a !important;
--input-background-fill: #1a1a35 !important;
--body-text-color: #e0e7ff !important;
--block-title-text-color: #a5b4fc !important;
--block-label-text-color: #a5b4fc !important;
--input-text-color: #e0e7ff !important;
--neutral-50: #0a0a1a !important;
--neutral-100: #0d0d1a !important;
--neutral-200: #12122a !important;
--neutral-300: #1a1a35 !important;
--neutral-400: #2d2d4a !important;
--neutral-500: #4a4a6a !important;
--neutral-600: #7c7c9a !important;
--neutral-700: #a5b4fc !important;
--neutral-800: #c7d2fe !important;
--neutral-900: #e0e7ff !important;
--neutral-950: #ffffff !important;
}
/* Force dark mode on html and body */
html, body {
background: #0a0a1a !important;
background-color: #0a0a1a !important;
color: #e0e7ff !important;
}
/* ===== GLOBAL STYLES ===== */
body {
background: linear-gradient(180deg, #0a0a1a 0%, #0f0f23 100%) !important;
background-color: #0a0a1a !important;
color: #ffffff !important;
font-family: system-ui, -apple-system, sans-serif;
}
/* Override Gradio's light mode backgrounds AND text colors */
.dark, .light, [data-theme="light"], [data-theme="dark"],
html[data-theme="light"], html[data-theme="dark"],
body.light, body.dark {
--body-background-fill: #0a0a1a !important;
--background-fill-primary: #0d0d1a !important;
--background-fill-secondary: #12122a !important;
--block-background-fill: #0d0d1a !important;
--input-background-fill: #1a1a35 !important;
--body-text-color: #e0e7ff !important;
--block-title-text-color: #a5b4fc !important;
--block-label-text-color: #a5b4fc !important;
--input-text-color: #e0e7ff !important;
--neutral-50: #0a0a1a !important;
--neutral-100: #0d0d1a !important;
--neutral-200: #12122a !important;
--neutral-300: #1a1a35 !important;
--neutral-400: #2d2d4a !important;
--neutral-500: #4a4a6a !important;
--neutral-600: #7c7c9a !important;
--neutral-700: #a5b4fc !important;
--neutral-800: #c7d2fe !important;
--neutral-900: #e0e7ff !important;
--neutral-950: #ffffff !important;
color: #e0e7ff !important;
background: #0a0a1a !important;
background-color: #0a0a1a !important;
}
.gradio-container {
max-width: 100% !important;
width: 100% !important;
padding: 0px 16px 20px 16px !important;
background: #0a0a1a !important;
background-color: #0a0a1a !important;
margin: 0 !important;
}
.gradio-container > .main,
.gradio-container .main,
.main {
max-width: 100% !important;
width: 100% !important;
padding-left: 0 !important;
padding-right: 0 !important;
margin: 0 auto !important;
}
.contain {
max-width: 100% !important;
padding: 0 !important;
}
/* Force full width on all Gradio internal containers */
.gradio-container > div,
.gradio-container > div > div,
#component-0,
.wrap,
.app,
.contain,
footer,
.gradio-row,
.gradio-column,
.svelte-1gfkn6j,
[class*="svelte-"] {
max-width: 100% !important;
}
.gradio-row {
max-width: 100% !important;
width: 100% !important;
margin: 0 !important;
padding: 0 !important;
}
/* ===== HEADER (FLOATING, NO CARD) ===== */
.header-main {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 0;
padding: 0;
}
.header-left {
display: flex;
align-items: center;
gap: 16px;
}
.header-icon {
font-size: 48px;
filter: drop-shadow(0 4px 12px rgba(99, 102, 241, 0.6));
}
.header-title {
font-size: 42px;
font-weight: 900;
color: #e0e7ff;
margin: 0;
letter-spacing: -0.5px;
}
.header-subtitle {
color: #c7d2fe;
font-size: 20px;
font-weight: 700;
margin-left: 6px;
}
/* ===== DOCS BUTTON ===== */
.docs-button {
display: flex;
align-items: center;
gap: 8px;
padding: 10px 20px;
background: linear-gradient(135deg, rgba(124, 58, 237, 0.3), rgba(99, 102, 241, 0.3));
border: 1px solid rgba(124, 58, 237, 0.5);
border-radius: 12px;
color: #e0e7ff;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.3s ease;
text-transform: uppercase;
letter-spacing: 0.5px;
}
.docs-button:hover {
background: linear-gradient(135deg, rgba(124, 58, 237, 0.5), rgba(99, 102, 241, 0.5));
border-color: rgba(124, 58, 237, 0.8);
transform: translateY(-2px);
box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4);
}
.docs-button svg {
width: 18px;
height: 18px;
}
/* ===== DOCS MODAL ===== */
.docs-modal-overlay {
display: none;
position: fixed !important;
inset: 0 !important;
width: 100vw !important;
height: 100vh !important;
background: rgba(0, 0, 0, 0.85) !important;
backdrop-filter: blur(10px) !important;
z-index: 99999 !important;
justify-content: center !important;
align-items: flex-start !important;
padding-top: 60px !important;
box-sizing: border-box !important;
/* Modal positioned near top of viewport */
overflow: hidden !important;
}
.docs-modal-overlay.active {
display: flex !important;
}
.docs-modal {
position: relative !important;
background: #0d0d1a !important;
border: 2px solid #7c3aed !important;
border-radius: 20px !important;
width: calc(100vw - 80px) !important;
max-width: 1200px !important;
max-height: 55vh !important;
overflow: hidden !important;
box-shadow: 0 25px 80px rgba(0, 0, 0, 0.9) !important;
/* Remove margin that could affect centering */
margin: 0 !important;
/* Prevent any transform inheritance issues */
transform: none !important;
}
.docs-modal-header {
display: flex !important;
justify-content: space-between !important;
align-items: center !important;
padding: 20px 24px !important;
border-bottom: 2px solid #7c3aed !important;
background: #1a1a2e !important;
}
.docs-modal-title {
font-size: 20px;
font-weight: 700;
color: #e0e7ff;
display: flex;
align-items: center;
gap: 10px;
}
.docs-modal-close {
background: rgba(124, 58, 237, 0.3);
border: 2px solid rgba(124, 58, 237, 0.5);
border-radius: 12px;
color: #e0e7ff;
font-size: 28px;
font-weight: 300;
cursor: pointer;
padding: 4px 14px;
line-height: 1;
transition: all 0.2s;
}
.docs-modal-close:hover {
background: rgba(124, 58, 237, 0.4);
border-color: rgba(124, 58, 237, 0.6);
}
.docs-modal-content {
padding: 24px !important;
overflow-y: auto !important;
max-height: calc(55vh - 80px) !important;
color: #c7d2fe !important;
font-size: 15px !important;
line-height: 1.7 !important;
background: #0d0d1a !important;
}
.docs-modal-content h1 { font-size: 28px; color: #e0e7ff; margin: 0 0 16px 0; padding-bottom: 12px; border-bottom: 2px solid rgba(124, 58, 237, 0.3); }
.docs-modal-content h2 { font-size: 22px; color: #e0e7ff; margin: 24px 0 12px 0; }
.docs-modal-content h3 { font-size: 18px; color: #a5b4fc; margin: 20px 0 10px 0; }
.docs-modal-content p { margin: 12px 0; }
.docs-modal-content ul, .docs-modal-content ol { margin: 12px 0; padding-left: 24px; }
.docs-modal-content li { margin: 6px 0; }
.docs-modal-content code { background: rgba(124, 58, 237, 0.2); padding: 2px 6px; border-radius: 4px; font-family: 'SF Mono', 'Monaco', 'Consolas', monospace; font-size: 13px; color: #c4b5fd; }
.docs-modal-content pre { background: rgba(0, 0, 0, 0.4); border: 1px solid rgba(124, 58, 237, 0.2); border-radius: 12px; padding: 16px; overflow-x: auto; margin: 16px 0; white-space: pre; }
.docs-modal-content pre code { background: transparent; padding: 0; color: #a5b4fc; white-space: pre; display: block; }
.docs-modal-content table { width: 100%; border-collapse: collapse; margin: 16px 0; }
.docs-modal-content th, .docs-modal-content td { padding: 10px 12px; text-align: left; border: 1px solid rgba(124, 58, 237, 0.2); }
.docs-modal-content th { background: rgba(124, 58, 237, 0.15); color: #e0e7ff; font-weight: 600; }
.docs-modal-content td { color: #c7d2fe; }
.docs-modal-content a { color: #a78bfa; text-decoration: none; }
.docs-modal-content a:hover { text-decoration: underline; }
.docs-modal-content strong { color: #e0e7ff; }
.docs-modal-content img { max-width: 100%; max-height: 400px; height: auto; border-radius: 8px; margin: 12px 0; object-fit: contain; }
/* ===== CARD STYLES ===== */
.card {
background: #0f0f23 !important;
background-color: #0f0f23 !important;
border: 1px solid #3d2a6b !important;
border-radius: 20px;
padding: 30px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
transition: all 0.3s ease;
height: 100%;
display: flex;
flex-direction: column;
}
.card:hover {
border-color: #5b3d99 !important;
box-shadow: 0 12px 48px rgba(124, 58, 237, 0.3);
}
/* Ensure columns in top row have equal height */
.gradio-row:first-of-type .gradio-column {
display: flex !important;
flex-direction: column !important;
}
.gradio-row:first-of-type .gradio-column > div {
flex: 1 !important;
display: flex !important;
flex-direction: column !important;
}
/* Set minimum height for top row cards */
.gradio-row:first-of-type .card {
min-height: 550px;
}
.card-title {
font-size: 16px;
font-weight: 700;
color: #a5b4fc;
text-transform: uppercase;
letter-spacing: 1px;
margin-bottom: 20px;
display: flex;
align-items: center;
}
/* ===== ROW SPACING ===== */
.gradio-row {
gap: 24px !important;
}
/* ===== QUICK START - CODE BLOCK (TERMINAL/IDE STYLE) ===== */
.terminal-window {
background: #1a1b26;
border: 1px solid rgba(124, 58, 237, 0.3);
border-radius: 12px;
overflow: hidden;
margin-bottom: 16px;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.6);
}
.terminal-header {
background: #16161e;
padding: 12px 16px;
display: flex;
align-items: center;
justify-content: space-between;
border-bottom: 1px solid rgba(124, 58, 237, 0.2);
}
.terminal-dots {
display: flex;
gap: 8px;
}
.terminal-dot {
width: 12px;
height: 12px;
border-radius: 50%;
}
.terminal-dot.red {
background: #ff5f56 !important;
box-shadow: 0 0 8px rgba(255, 95, 86, 0.8) !important;
}
.terminal-dot.yellow {
background: #ffbd2e !important;
box-shadow: 0 0 8px rgba(255, 189, 46, 0.8) !important;
}
.terminal-dot.green {
background: #27c93f !important;
box-shadow: 0 0 8px rgba(39, 201, 63, 0.8) !important;
}
.terminal-title {
font-size: 12px;
color: #6b7280;
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
font-weight: 500;
}
.terminal-body {
background: #1a1b26;
padding: 0;
display: flex;
}
.line-numbers {
background: #16161e;
padding: 16px 12px;
border-right: 1px solid rgba(124, 58, 237, 0.15);
user-select: none;
text-align: right;
min-width: 48px;
}
.line-num {
display: block;
color: #4a5568;
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
font-size: 14px;
line-height: 1.8;
}
.code-content {
flex: 1;
padding: 16px 20px;
overflow-x: auto;
}
.code-line {
display: block;
white-space: pre;
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
font-size: 14px;
line-height: 1.8;
color: #a9b1d6;
}
.json-key {
color: #7dcfff;
font-weight: 500;
}
.json-string {
color: #9ece6a;
}
.json-bracket {
color: #bb9af7;
font-weight: 600;
}
.json-colon {
color: #c0caf5;
}
.json-comma {
color: #c0caf5;
}
.copy-button {
width: 100%;
background: linear-gradient(135deg, #7c3aed, #6366f1) !important;
border: none !important;
border-radius: 12px !important;
padding: 14px 24px !important;
font-weight: 700 !important;
font-size: 13px !important;
color: white !important;
text-transform: uppercase;
letter-spacing: 1px;
cursor: pointer;
box-shadow: 0 4px 16px rgba(124, 58, 237, 0.4) !important;
transition: all 0.3s ease !important;
display: flex;
align-items: center;
justify-content: center;
gap: 8px;
}
.copy-button:hover {
transform: translateY(-2px) !important;
box-shadow: 0 6px 24px rgba(124, 58, 237, 0.6) !important;
}
/* ===== TOOLS TABLE ===== */
.tools-table,
table.tools-table,
.light .tools-table,
.dark .tools-table,
[data-theme="light"] .tools-table,
[data-theme="dark"] .tools-table {
width: 100%;
border-collapse: separate;
border-spacing: 0;
background: #0d0d1f !important;
background-color: #0d0d1f !important;
border-radius: 12px;
overflow: hidden;
border: 1px solid #3d2a6b !important;
margin-bottom: 0;
flex: 1;
color: #cbd5e1 !important;
}
.tools-table th,
table.tools-table th,
.light .tools-table th,
.dark .tools-table th,
[data-theme="light"] .tools-table th,
[data-theme="dark"] .tools-table th {
background: #1f1545 !important;
background-color: #1f1545 !important;
color: #a5b4fc !important;
font-weight: 700;
font-size: 16px;
text-transform: uppercase;
letter-spacing: 1.5px;
padding: 20px 14px;
text-align: left;
border-bottom: 1px solid #3d2a6b !important;
}
.tools-table td,
table.tools-table td,
.light .tools-table td,
.dark .tools-table td,
[data-theme="light"] .tools-table td,
[data-theme="dark"] .tools-table td {
padding: 20px 14px;
color: #cbd5e1 !important;
background: #0d0d1f !important;
background-color: #0d0d1f !important;
font-size: 16px;
border-bottom: 1px solid #1a1535 !important;
}
.tools-table tr:last-child td {
border-bottom: none;
}
.tools-table tr:hover,
.tools-table tr:hover td {
background: #1a1540 !important;
background-color: #1a1540 !important;
}
.tool-name,
.light .tool-name,
.dark .tool-name,
[data-theme="light"] .tool-name,
[data-theme="dark"] .tool-name {
color: #22d3ee !important;
font-family: 'SF Mono', 'Monaco', 'Consolas', monospace;
font-weight: 600;
font-size: 13px;
vertical-align: middle;
}
/* ===== COMPOSITE SECTION ===== */
.composite-section,
.light .composite-section,
.dark .composite-section,
[data-theme="light"] .composite-section,
[data-theme="dark"] .composite-section {
background: #0d0d1f !important;
background-color: #0d0d1f !important;
border: 1px solid #3d2a6b !important;
border-radius: 12px;
padding: 20px;
color: #cbd5e1 !important;
}
.composite-header,
.light .composite-header,
.dark .composite-header,
[data-theme="light"] .composite-header,
[data-theme="dark"] .composite-header {
font-size: 11px;
font-weight: 700;
color: #a5b4fc !important;
text-transform: uppercase;
letter-spacing: 1.5px;
margin-bottom: 12px;
}
.composite-content,
.light .composite-content,
.dark .composite-content,
[data-theme="light"] .composite-content,
[data-theme="dark"] .composite-content {
color: #cbd5e1 !important;
font-size: 12px;
line-height: 1.6;
margin-bottom: 16px;
}
.try-demo-button {
width: 100%;
background: transparent !important;
border: 2px solid #7c3aed !important;
border-radius: 12px !important;
padding: 12px 24px !important;
font-weight: 700 !important;
font-size: 12px !important;
color: #7c3aed !important;
text-transform: uppercase;
letter-spacing: 1px;
cursor: pointer;
transition: all 0.3s ease !important;
}
.try-demo-button:hover {
background: rgba(124, 58, 237, 0.1) !important;
border-color: #7c3aed !important;
color: #8b5cf6 !important;
}
/* ===== BUTTONS ===== */
button[variant="primary"] {
background: linear-gradient(135deg, #7c3aed, #6366f1) !important;
border: none !important;
border-radius: 12px !important;
padding: 14px 32px !important;
font-weight: 700 !important;
font-size: 14px !important;
color: white !important;
box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4) !important;
transition: all 0.3s ease !important;
}
button[variant="primary"]:hover {
transform: translateY(-2px) !important;
box-shadow: 0 8px 32px rgba(124, 58, 237, 0.6) !important;
}
/* ===== AUDIO COMPONENT ===== */
.gradio-audio {
background: rgba(30, 27, 75, 0.6) !important;
border: 1px solid rgba(124, 58, 237, 0.3) !important;
border-radius: 12px !important;
}
/* ===== TEXTBOX ===== */
textarea {
background: rgba(30, 27, 75, 0.6) !important;
border: 1px solid rgba(124, 58, 237, 0.3) !important;
border-radius: 12px !important;
color: #e0e7ff !important;
font-size: 13px !important;
}
/* ===== DROPDOWN ===== */
select {
background: rgba(30, 27, 75, 0.6) !important;
border: 1px solid rgba(124, 58, 237, 0.3) !important;
border-radius: 12px !important;
color: #e0e7ff !important;
}
/* ===== LABELS ===== */
label {
color: #a5b4fc !important;
font-weight: 600 !important;
font-size: 12px !important;
text-transform: uppercase;
letter-spacing: 0.5px;
}
/* ===== HTML OUTPUT ===== */
.gradio-html {
background: transparent !important;
border: none !important;
}
/* ===== DEMO ROW LAYOUT ===== */
.demo-row {
display: flex !important;
gap: 24px !important;
align-items: stretch !important;
}
/* Only apply card style to the outer column (demo-card-column) */
.demo-card-column {
display: flex !important;
flex-direction: column !important;
height: 700px !important;
min-height: 700px !important;
max-height: 700px !important;
background: rgba(15, 15, 35, 0.8) !important;
backdrop-filter: blur(20px) !important;
border: 1px solid rgba(124, 58, 237, 0.3) !important;
border-radius: 20px !important;
padding: 4px 4px 2px 4px !important;
box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4) !important;
transition: all 0.3s ease !important;
gap: 2px !important;
overflow-y: auto !important;
}
.demo-card-column:hover {
border-color: rgba(124, 58, 237, 0.5) !important;
box-shadow: 0 12px 48px rgba(124, 58, 237, 0.3) !important;
}
/* Remove any border/background from inner elements */
.demo-card-column > div,
.demo-card-column > div > div,
.demo-row > div > div {
background: transparent !important;
border: none !important;
box-shadow: none !important;
padding: 0 !important;
border-radius: 0 !important;
}
/* Remove card background from inner HTML - we use column background instead */
.demo-row .card {
background: transparent !important;
backdrop-filter: none !important;
border: none !important;
border-radius: 0 !important;
padding: 0 !important;
box-shadow: none !important;
margin-bottom: 12px !important;
}
.demo-row .card:hover {
border: none !important;
box-shadow: none !important;
}
/* Ensure all inner components have transparent background */
.demo-row .gradio-audio,
.demo-row .gradio-dropdown,
.demo-row .gradio-textbox,
.demo-row .gradio-button {
background: transparent !important;
}
/* Create a wrapper for input elements (flex container) */
.demo-card-column > div:not(:last-child) {
flex: 0 0 auto !important;
}
/* Adjust spacing for input elements in demo cards */
.demo-row .gradio-audio {
margin-top: 6px !important;
margin-bottom: 0px !important;
max-height: 50px !important;
min-height: 40px !important;
height: 45px !important;
}
/* Target all child elements of audio component */
.demo-row .gradio-audio > div,
.demo-row .gradio-audio .wrap,
.demo-row .gradio-audio .upload-container,
.demo-row .gradio-audio .record-container,
.demo-row .gradio-audio * {
max-height: 50px !important;
}
/* Audio player specific height reduction */
.demo-row .gradio-audio audio {
height: 26px !important;
max-height: 26px !important;
min-height: 26px !important;
}
/* Upload/record button container height */
.demo-row .gradio-audio .upload-container,
.demo-row .gradio-audio .record-container {
min-height: 38px !important;
max-height: 38px !important;
padding: 4px !important;
}
/* Audio component buttons */
.demo-row .gradio-audio button {
height: 28px !important;
min-height: 28px !important;
max-height: 28px !important;
padding: 4px 10px !important;
font-size: 10px !important;
}
/* Hide text nodes in audio upload area - keep icons */
.demo-row .gradio-audio .upload-text {
display: none !important;
}
.demo-row .gradio-audio .placeholder {
display: none !important;
}
.demo-row .gradio-audio span:not(:has(svg)) {
font-size: 0 !important;
}
.demo-row .gradio-audio p {
display: none !important;
}
/* Hide "Drop Audio Here", "- or -", "Click to Upload" text */
.demo-row .gradio-audio .upload-container span,
.demo-row .gradio-audio .upload-container p {
font-size: 0 !important;
line-height: 0 !important;
}
/* Keep SVG icons visible */
.demo-row .gradio-audio svg {
font-size: initial !important;
}
/* ADDITIONAL METHODS: Hide all text in audio upload area */
.demo-row .gradio-audio label {
font-size: 0 !important;
}
.demo-row .gradio-audio label span:not(:has(svg)) {
display: none !important;
}
.demo-row .gradio-audio .file-preview {
font-size: 0 !important;
}
.demo-row .gradio-audio .file-preview span {
font-size: 0 !important;
display: none !important;
}
.demo-row .gradio-audio [data-testid="upload-text"],
.demo-row .gradio-audio [data-testid="file-preview-text"],
.demo-row .gradio-audio .upload-text,
.demo-row .gradio-audio .file-preview-text {
display: none !important;
visibility: hidden !important;
font-size: 0 !important;
}
/* Target all text nodes (more aggressive) */
.demo-row .gradio-audio *:not(svg):not(path):not(circle):not(rect):not(line) {
color: transparent !important;
}
.demo-row .gradio-audio button {
color: white !important;
}
/* Ensure icons remain visible */
.demo-row .gradio-audio svg,
.demo-row .gradio-audio svg * {
color: initial !important;
fill: currentColor !important;
stroke: currentColor !important;
}
/* NUCLEAR OPTION: Hide everything in label, then show only necessary elements */
.demo-row .gradio-audio label > div > div {
display: none !important;
}
.demo-row .gradio-audio label::before {
content: '' !important;
}
.demo-row .gradio-audio label * {
visibility: hidden !important;
}
.demo-row .gradio-audio label svg {
visibility: visible !important;
}
.demo-row .gradio-audio label button {
visibility: visible !important;
}
.demo-row .gradio-audio label audio {
visibility: visible !important;
}
/* Force hide any text content */
.demo-row .gradio-audio label > div::after,
.demo-row .gradio-audio label > div::before {
content: '' !important;
display: none !important;
}
/* Additional override for upload text elements */
.demo-row .gradio-audio [class*="upload"],
.demo-row .gradio-audio [class*="placeholder"],
.demo-row .gradio-audio [class*="text"] {
font-size: 0 !important;
line-height: 0 !important;
width: 0 !important;
height: 0 !important;
opacity: 0 !important;
visibility: hidden !important;
position: absolute !important;
left: -9999px !important;
}
/* NUCLEAR OPTION 2: Complete removal of label content */
.demo-row .gradio-audio label.block {
display: none !important;
}
.demo-row .gradio-audio .file-upload {
display: none !important;
}
/* Hide all direct text children */
.demo-row .gradio-audio label > span:not(:has(button)):not(:has(audio)):not(:has(svg)) {
display: none !important;
}
/* Gradio 6.0 specific selectors - upload area */
.demo-row .gradio-audio [data-testid="upload-button"],
.demo-row .gradio-audio [data-testid="file-upload"],
.demo-row .gradio-audio .upload-area {
display: none !important;
}
/* Hide all paragraph elements in audio component */
.demo-row .gradio-audio label p,
.demo-row .gradio-audio label span.text,
.demo-row .gradio-audio label div.text {
display: none !important;
}
/* More aggressive text hiding - target by content */
.demo-row .gradio-audio *::before,
.demo-row .gradio-audio *::after {
content: '' !important;
display: none !important;
}
/* Make sure only buttons and audio players are visible */
.demo-row .gradio-audio > label > div > div:not(:has(button)):not(:has(audio)) {
display: none !important;
}
/* Gradio Blocks specific - Hide wrapper divs that contain text */
.demo-row .gradio-audio .wrap > div:not(:has(button)):not(:has(audio)):not(:has(svg)) {
display: none !important;
}
/* Override for Gradio 6.x structure */
.demo-row .gradio-audio [class*="svelte-"] span:not(:has(svg)):not(:has(button)) {
display: none !important;
}
.demo-row .gradio-dropdown,
.demo-row .gradio-textbox {
margin-bottom: 2px !important;
}
.demo-row .gradio-row {
margin-bottom: 2px !important;
}
/* IMPORTANT: Button alignment - push buttons to bottom with margin-top: auto */
.demo-row .gradio-button {
margin-top: auto !important;
margin-bottom: 0px !important;
flex-shrink: 0 !important;
}
/* Output area should not push button down - set flex: 1 */
.demo-row .gradio-html {
flex: 1 !important;
margin-bottom: 0 !important;
display: flex !important;
flex-direction: column !important;
max-height: 300px !important;
overflow-y: auto !important;
}
/* Output audio component (clean_audio_output) height limit */
.demo-row .gradio-audio[data-testid="audio-output"],
.demo-row > div:last-child .gradio-audio {
max-height: 120px !important;
min-height: 60px !important;
height: auto !important;
margin-bottom: 0px !important;
}
/* ===== CUSTOM ACTION BUTTONS (DEMO CARDS) ===== */
.custom-action-btn,
.custom-action-btn button,
.custom-action-btn button[data-testid="button"],
button.custom-action-btn,
.demo-row .custom-action-btn,
.demo-row .custom-action-btn button {
width: 100% !important;
min-width: 100% !important;
max-width: 100% !important;
background: linear-gradient(135deg, #6366f1, #7c3aed) !important;
border: none !important;
border-radius: 12px !important;
padding: 8px 16px !important;
height: 38px !important;
min-height: 38px !important;
max-height: 38px !important;
font-weight: 700 !important;
font-size: 16px !important;
letter-spacing: 1.5px !important;
text-transform: uppercase !important;
color: white !important;
box-shadow: 0 4px 20px rgba(124, 58, 237, 0.4) !important;
transition: all 0.3s ease !important;
}
.custom-action-btn:hover,
.custom-action-btn button:hover,
.custom-action-btn button[data-testid="button"]:hover,
button.custom-action-btn:hover,
.demo-row .custom-action-btn:hover,
.demo-row .custom-action-btn button:hover {
transform: translateY(-2px) !important;
box-shadow: 0 8px 32px rgba(124, 58, 237, 0.6) !important;
background: linear-gradient(135deg, #6366f1, #7c3aed) !important;
}
/* ===== DECORATIVE ELEMENTS ===== */
.diamond-decoration {
position: fixed;
bottom: 40px;
right: 40px;
width: 80px;
height: 80px;
border: 2px solid rgba(124, 58, 237, 0.2);
transform: rotate(45deg);
pointer-events: none;
z-index: 1;
}
.star-decoration {
display: none;
}
"""
with gr.Blocks() as demo:
# Inject custom CSS and decorative elements (positioned fixed, no DOM space)
gr.HTML(f"""
<style>{custom_css}</style>
<div class="diamond-decoration"></div>
<div class="star-decoration">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none">
<path d="M12 2l3.09 6.26L22 9.27l-5 4.87 1.18 6.88L12 17.77l-6.18 3.25L7 14.14 2 9.27l6.91-1.01L12 2z" fill="#a5b4fc" opacity="0.4"/>
</svg>
</div>
<script>
// Force dark mode styling (no redirect, just add classes)
(function() {{
// Add dark mode classes immediately
document.documentElement.classList.add('dark');
document.documentElement.setAttribute('data-theme', 'dark');
document.body.classList.add('dark');
document.body.setAttribute('data-theme', 'dark');
// Also observe for Gradio container and add dark class there
const observer = new MutationObserver(function(mutations) {{
const container = document.querySelector('.gradio-container');
if (container && !container.classList.contains('dark')) {{
container.classList.add('dark');
container.setAttribute('data-theme', 'dark');
}}
}});
observer.observe(document.body, {{ childList: true, subtree: true }});
}})();
// JavaScript to completely remove upload text from Audio components in demo-row
function removeAudioUploadText() {{
// Find all audio components in demo-row
const demoRows = document.querySelectorAll('.demo-row');
demoRows.forEach(row => {{
const audioComponents = row.querySelectorAll('.gradio-audio');
audioComponents.forEach(audio => {{
// METHOD 1: Remove ALL text nodes (most aggressive)
const walker = document.createTreeWalker(
audio,
NodeFilter.SHOW_TEXT,
null,
false
);
const textNodesToRemove = [];
while(walker.nextNode()) {{
const node = walker.currentNode;
// Only keep text that's inside button or audio elements
const parentTag = node.parentElement?.tagName?.toLowerCase();
if (parentTag !== 'button' && parentTag !== 'audio') {{
textNodesToRemove.push(node);
}}
}}
textNodesToRemove.forEach(node => {{
if (node.parentNode) {{
node.parentNode.removeChild(node);
}}
}});
// METHOD 2: Hide elements by class/data attributes
const elementsToHide = audio.querySelectorAll(
'[class*="upload"], [class*="placeholder"], [class*="text"], ' +
'[data-testid*="upload"], [data-testid*="file"], ' +
'label.block, .file-upload, p, span:not(:has(button)):not(:has(svg))'
);
elementsToHide.forEach(el => {{
el.style.display = 'none';
el.style.visibility = 'hidden';
el.style.fontSize = '0';
el.style.lineHeight = '0';
el.style.width = '0';
el.style.height = '0';
el.style.opacity = '0';
el.style.position = 'absolute';
el.style.left = '-9999px';
}});
// METHOD 3: Remove label.block entirely if it exists
const labelBlocks = audio.querySelectorAll('label.block');
labelBlocks.forEach(label => {{
// Only remove if it doesn't contain button or audio
if (!label.querySelector('button') && !label.querySelector('audio')) {{
label.remove();
}}
}});
// METHOD 4: Clear innerHTML of divs that don't contain buttons/audio
const allDivs = audio.querySelectorAll('div');
allDivs.forEach(div => {{
if (!div.querySelector('button') && !div.querySelector('audio') && !div.querySelector('svg')) {{
// Check if div only contains text
const hasOnlyText = Array.from(div.childNodes).every(node =>
node.nodeType === Node.TEXT_NODE ||
(node.nodeType === Node.ELEMENT_NODE && !node.querySelector('button, audio, svg'))
);
if (hasOnlyText) {{
div.innerHTML = '';
}}
}}
}});
}});
}});
}}
// Run immediately
removeAudioUploadText();
// Run after DOM changes (MutationObserver)
const observer = new MutationObserver(() => {{
removeAudioUploadText();
}});
// Start observing after a short delay to ensure Gradio has loaded
setTimeout(() => {{
observer.observe(document.body, {{
childList: true,
subtree: true
}});
}}, 500);
// Also run on window load
window.addEventListener('load', removeAudioUploadText);
// Run periodically for the first 5 seconds (catch late renders)
let attempts = 0;
const interval = setInterval(() => {{
removeAudioUploadText();
attempts++;
if (attempts > 10) {{
clearInterval(interval);
}}
}}, 500);
</script>
""")
# ==================== HEADER (FLOATING) ====================
gr.HTML(f"""
<div class="header-main">
<div class="header-left">
<span class="header-icon">
<svg width="72" height="72" viewBox="0 0 52 52" fill="none">
<defs>
<linearGradient id="logoGradHeader" x1="0%" y1="0%" x2="100%" y2="100%">
<stop offset="0%" style="stop-color:#7c3aed"/>
<stop offset="100%" style="stop-color:#6366f1"/>
</linearGradient>
</defs>
<!-- Left: Microphone (rounded capsule + stand) -->
<!-- Microphone capsule (rounded rect) -->
<rect x="8" y="12" width="9" height="14" rx="4.5" fill="url(#logoGradHeader)"/>
<!-- Microphone grill lines (horizontal detail) -->
<line x1="9" y1="16" x2="14" y2="16" stroke="#000000" stroke-width="0.8" stroke-linecap="round"/>
<line x1="9" y1="19.5" x2="14" y2="19.5" stroke="#000000" stroke-width="0.8" stroke-linecap="round"/>
<line x1="9" y1="23" x2="14" y2="23" stroke="#000000" stroke-width="0.8" stroke-linecap="round"/>
<!-- Arc stand -->
<path d="M6.5 26c0 2.5 2.2 5 6 5s6-2.5 6-5" stroke="url(#logoGradHeader)" stroke-width="2" fill="none" stroke-linecap="round"/>
<!-- Pole -->
<rect x="11.5" y="31" width="2" height="5" fill="url(#logoGradHeader)"/>
<!-- Base -->
<rect x="7.5" y="36" width="9" height="2" rx="1" fill="url(#logoGradHeader)"/>
<!-- Right: Audio Wave Bars (4 vertical bars with different heights) -->
<rect x="28" y="18" width="3" height="16" rx="1.5" fill="url(#logoGradHeader)" opacity="0.9"/>
<rect x="34" y="14" width="3" height="24" rx="1.5" fill="url(#logoGradHeader)" opacity="0.95"/>
<rect x="40" y="20" width="3" height="12" rx="1.5" fill="url(#logoGradHeader)" opacity="0.85"/>
<rect x="46" y="22" width="3" height="8" rx="1.5" fill="url(#logoGradHeader)" opacity="0.8"/>
</svg>
</span>
<div>
<span class="header-title">VoiceKit</span>
<span class="header-subtitle">MCP Server</span>
</div>
</div>
<button class="docs-button" onclick="document.getElementById('docsModal').classList.add('active')">
<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
<polyline points="14 2 14 8 20 8"/>
<line x1="16" y1="13" x2="8" y2="13"/>
<line x1="16" y1="17" x2="8" y2="17"/>
<polyline points="10 9 9 9 8 9"/>
</svg>
DOCS
</button>
</div>
<!-- DOCS Modal -->
<div id="docsModal" class="docs-modal-overlay" onclick="if(event.target === this) this.classList.remove('active')">
<div class="docs-modal">
<div class="docs-modal-header">
<div class="docs-modal-title">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="#a78bfa" stroke-width="2">
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"/>
<polyline points="14 2 14 8 20 8"/>
</svg>
Documentation
</div>
<button class="docs-modal-close" onclick="document.getElementById('docsModal').classList.remove('active')">×</button>
</div>
<div class="docs-modal-content">
{readme_html}
</div>
</div>
</div>
""")
# ==================== TOP ROW: QUICK START + AVAILABLE TOOLS ====================
with gr.Row(equal_height=True):
# QUICK START CARD
with gr.Column(scale=1):
gr.HTML("""
<div class="card" style="min-height: 550px;">
<div class="card-title">
<svg width="18" height="18" viewBox="0 0 24 24" fill="#7c3aed" style="margin-right: 8px;">
<path d="M19.14 12.94c.04-.31.06-.63.06-.94 0-.31-.02-.63-.06-.94l2.03-1.58c.18-.14.23-.41.12-.61l-1.92-3.32c-.12-.22-.37-.29-.59-.22l-2.39.96c-.5-.38-1.03-.7-1.62-.94l-.36-2.54c-.04-.24-.24-.41-.48-.41h-3.84c-.24 0-.43.17-.47.41l-.36 2.54c-.59.24-1.13.57-1.62.94l-2.39-.96c-.22-.08-.47 0-.59.22L2.74 8.87c-.12.21-.08.47.12.61l2.03 1.58c-.04.31-.06.63-.06.94s.02.63.06.94l-2.03 1.58c-.18.14-.23.41-.12.61l1.92 3.32c.12.22.37.29.59.22l2.39-.96c.5.38 1.03.7 1.62.94l.36 2.54c.05.24.24.41.48.41h3.84c.24 0 .44-.17.47-.41l.36-2.54c.59-.24 1.13-.56 1.62-.94l2.39.96c.22.08.47 0 .59-.22l1.92-3.32c.12-.22.07-.47-.12-.61l-2.01-1.58zM12 15.6c-1.98 0-3.6-1.62-3.6-3.6s1.62-3.6 3.6-3.6 3.6 1.62 3.6 3.6-1.62 3.6-3.6 3.6z"/>
</svg>
QUICK START
</div>
<div class="terminal-window">
<!-- Terminal Header with Dots and Filename -->
<div class="terminal-header">
<div class="terminal-dots">
<div class="terminal-dot red"></div>
<div class="terminal-dot yellow"></div>
<div class="terminal-dot green"></div>
</div>
<div class="terminal-title">claude_desktop_config.json</div>
<div style="width: 60px;"></div> <!-- Spacer for center alignment -->
</div>
<!-- Terminal Body with Line Numbers and Code -->
<div class="terminal-body">
<div class="line-numbers">
<div class="line-num">1</div>
<div class="line-num">2</div>
<div class="line-num">3</div>
<div class="line-num">4</div>
<div class="line-num">5</div>
<div class="line-num">6</div>
<div class="line-num">7</div>
<div class="line-num">8</div>
<div class="line-num">9</div>
<div class="line-num">10</div>
<div class="line-num">11</div>
<div class="line-num">12</div>
</div>
<div class="code-content">
<div class="code-line"><span class="json-bracket">{</span></div>
<div class="code-line"> <span class="json-key">"mcpServers"</span><span class="json-colon">:</span> <span class="json-bracket">{</span></div>
<div class="code-line"> <span class="json-key">"voicekit"</span><span class="json-colon">:</span> <span class="json-bracket">{</span></div>
<div class="code-line"> <span class="json-key">"command"</span><span class="json-colon">:</span> <span class="json-string">"npx"</span><span class="json-comma">,</span></div>
<div class="code-line"> <span class="json-key">"args"</span><span class="json-colon">:</span> <span class="json-bracket">[</span></div>
<div class="code-line"> <span class="json-string">"-y"</span><span class="json-comma">,</span></div>
<div class="code-line"> <span class="json-string">"mcp-remote"</span><span class="json-comma">,</span></div>
<div class="code-line"> <span class="json-string">"https://mcp-1st-birthday-voicekit.hf.space/gradio_api/mcp/sse"</span></div>
<div class="code-line"> <span class="json-bracket">]</span></div>
<div class="code-line"> <span class="json-bracket">}</span></div>
<div class="code-line"> <span class="json-bracket">}</span></div>
<div class="code-line"><span class="json-bracket">}</span></div>
</div>
</div>
</div>
<button class="copy-button" onclick="navigator.clipboard.writeText(JSON.stringify({mcpServers:{voicekit:{command:'npx',args:['-y','mcp-remote','https://mcp-1st-birthday-voicekit.hf.space/gradio_api/mcp/sse']}}},null,2))">
<svg width="16" height="16" viewBox="0 0 24 24" fill="white" style="display: inline-block; vertical-align: middle;">
<rect x="9" y="9" width="13" height="13" rx="2" ry="2" fill="white"/>
<path d="M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1" fill="none" stroke="white" stroke-width="2"/>
</svg>
COPY CONFIG
</button>
</div>
""")
# AVAILABLE TOOLS CARD
with gr.Column(scale=1):
gr.HTML("""
<div class="card" style="min-height: 550px;">
<div class="card-title">
<svg width="18" height="18" viewBox="0 0 24 24" fill="#7c3aed" style="margin-right: 8px;">
<path d="M22.7 19l-9.1-9.1c.9-2.3.4-5-1.5-6.9-2-2-5-2.4-7.4-1.3L9 6 6 9 1.6 4.7C.4 7.1.9 10.1 2.9 12.1c1.9 1.9 4.6 2.4 6.9 1.5l9.1 9.1c.4.4 1 .4 1.4 0l2.3-2.3c.5-.4.5-1.1.1-1.4z"/>
</svg>
AVAILABLE TOOLS
</div>
<table class="tools-table">
<thead>
<tr>
<th>TOOL</th>
<th>PURPOSE</th>
<th>INPUT</th>
<th>OUTPUT</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<div style="display: flex; align-items: center; gap: 12px;">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<path d="M21 16V8L12 4L3 8V16L12 20L21 16Z" stroke="#A855F7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 4V12M12 12V20M12 12L21 8M12 12L3 8" stroke="#A855F7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="12" cy="12" r="2" fill="#A855F7"/>
<circle cx="16.5" cy="10" r="1.5" fill="#A855F7"/>
<circle cx="7.5" cy="14" r="1.5" fill="#A855F7"/>
<path d="M12 12L16.5 10M12 12L7.5 14" stroke="#A855F7" stroke-width="1.5" stroke-linecap="round"/>
</svg>
<span class="tool-name">extract_embedding</span>
</div>
</td>
<td>Extract 768-dim voice fingerprint</td>
<td>audio_base64</td>
<td>embedding, model, dim</td>
</tr>
<tr>
<td>
<div style="display: flex; align-items: center; gap: 12px;">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<path d="M2 10V14" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M5 8V16" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M8 11V13" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M22 10V14" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M19 7V17" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M16 11V13" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M10 12H14" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M10 12L11.5 10.5" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M10 12L11.5 13.5" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M14 12L12.5 10.5" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M14 12L12.5 13.5" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
</svg>
<span class="tool-name">match_voice</span>
</div>
</td>
<td>Compare two voice similarities</td>
<td>audio1_base64, audio2_base64</td>
<td>similarity, tone_score</td>
</tr>
<tr>
<td>
<div style="display: flex; align-items: center; gap: 12px;">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<path d="M22 10C22 10 20 4 17 4C14 4 12 16 9 16C6 16 4 10 2 10" stroke="#A855F7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<g transform="translate(13, 11)">
<circle cx="5" cy="5" r="4" stroke="#A855F7" stroke-width="1.5"/>
<path d="M8 8L11 11" stroke="#A855F7" stroke-width="1.5" stroke-linecap="round"/>
</g>
</svg>
<span class="tool-name">analyze_acoustics</span>
</div>
</td>
<td>Analyze pitch, energy, rhythm, tempo</td>
<td>audio_base64</td>
<td>pitch, energy, rhythm, tempo</td>
</tr>
<tr>
<td>
<div style="display: flex; align-items: center; gap: 12px;">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<path d="M2 12C2 12 4 5 7 5C10 5 11 19 14 19C15.5 19 16.5 15 16.5 15" stroke="#A855F7" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19 7H22" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M19 12H22" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
<path d="M19 17H22" stroke="#A855F7" stroke-width="2" stroke-linecap="round"/>
</svg>
<span class="tool-name">transcribe_audio</span>
</div>
</td>
<td>Convert speech to text</td>
<td>audio_base64, language</td>
<td>text, language, model</td>
</tr>
<tr>
<td>
<div style="display: flex; align-items: center; gap: 12px;">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<path d="M12 5V19" stroke="#A855F7" stroke-width="2.5" stroke-linecap="round"/>
<path d="M9 8V16" stroke="#A855F7" stroke-width="2.5" stroke-linecap="round"/>
<path d="M15 8V16" stroke="#A855F7" stroke-width="2.5" stroke-linecap="round"/>
<path d="M5 4H3V20H5" stroke="#A855F7" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19 4H21V20H19" stroke="#A855F7" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<span class="tool-name">isolate_voice</span>
</div>
</td>
<td>Remove background music/noise</td>
<td>audio_base64</td>
<td>isolated_audio_base64, metadata</td>
</tr>
<tr>
<td>
<div style="display: flex; align-items: center; gap: 12px;">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<circle cx="12" cy="12" r="9" stroke="#A855F7" stroke-width="1" opacity="0.3"/>
<path d="M12 3V21" stroke="#A855F7" stroke-width="1" opacity="0.3"/>
<path d="M4.2 7.5L19.8 16.5" stroke="#A855F7" stroke-width="1" opacity="0.3"/>
<path d="M19.8 7.5L4.2 16.5" stroke="#A855F7" stroke-width="1" opacity="0.3"/>
<path d="M12 5L18 9L16.5 18H7.5L6 9L12 5Z" fill="#A855F7" fill-opacity="0.4" stroke="#A855F7" stroke-width="2" stroke-linejoin="round"/>
<circle cx="12" cy="5" r="1.5" fill="#A855F7"/>
<circle cx="18" cy="9" r="1.5" fill="#A855F7"/>
<circle cx="16.5" cy="18" r="1.5" fill="#A855F7"/>
<circle cx="7.5" cy="18" r="1.5" fill="#A855F7"/>
<circle cx="6" cy="9" r="1.5" fill="#A855F7"/>
</svg>
<span class="tool-name">grade_voice</span>
</div>
</td>
<td>5-metric comprehensive analysis</td>
<td>user_audio, reference_audio, text, category</td>
<td>overall, metrics, feedback</td>
</tr>
</tbody>
</table>
</div>
""")
# ==================== FIRST ROW: 3 DEMO CARDS ====================
with gr.Row(equal_height=True, elem_classes="demo-row"):
# EXTRACT EMBEDDING
with gr.Column(scale=1, elem_classes="demo-card-column"):
gr.HTML("""
<div style="display: flex; align-items: center; gap: 6px; margin-bottom: 8px; padding-left: 18px; padding-top: 10px;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<path d="M21 16V8L12 4L3 8V16L12 20L21 16Z" stroke="#7c3aed" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M12 4V12M12 12V20M12 12L21 8M12 12L3 8" stroke="#7c3aed" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<circle cx="12" cy="12" r="2" fill="#7c3aed"/>
<circle cx="16.5" cy="10" r="1.5" fill="#7c3aed"/>
<circle cx="7.5" cy="14" r="1.5" fill="#7c3aed"/>
<path d="M12 12L16.5 10M12 12L7.5 14" stroke="#7c3aed" stroke-width="1.5" stroke-linecap="round"/>
</svg>
<div style="font-size: 16px; font-weight: 700; color: #a5b4fc; text-transform: uppercase; letter-spacing: 1px;">
EXTRACT EMBEDDING
</div>
</div>
""")
embedding_audio = gr.Audio(
type="filepath",
label="Audio Input",
show_label=False,
format="wav"
)
embedding_btn = gr.Button("EXTRACT", variant="primary", size="lg", elem_classes="custom-action-btn")
embedding_output = gr.HTML(value=create_embedding_empty())
embedding_btn.click(
demo_extract_embedding,
inputs=[embedding_audio],
outputs=[embedding_output],
api_visibility="private"
)
# COMPARE VOICES
with gr.Column(scale=1, elem_classes="demo-card-column"):
gr.HTML("""
<div style="display: flex; align-items: center; gap: 6px; margin-bottom: 8px; padding-left: 18px; padding-top: 10px;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<path d="M2 10V14" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M5 8V16" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M8 11V13" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M22 10V14" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M19 7V17" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M16 11V13" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M10 12H14" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M10 12L11.5 10.5" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M10 12L11.5 13.5" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M14 12L12.5 10.5" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M14 12L12.5 13.5" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
</svg>
<div style="font-size: 16px; font-weight: 700; color: #a5b4fc; text-transform: uppercase; letter-spacing: 1px;">
MATCH VOICE
</div>
</div>
""")
with gr.Row():
compare_audio1 = gr.Audio(
type="filepath",
label="Audio 1",
show_label=False,
format="wav"
)
compare_audio2 = gr.Audio(
type="filepath",
label="Audio 2",
show_label=False,
format="wav"
)
compare_btn = gr.Button("COMPARE", variant="primary", size="lg", elem_classes="custom-action-btn")
compare_output = gr.HTML(value=create_compare_empty())
compare_btn.click(
demo_match_voice,
inputs=[compare_audio1, compare_audio2],
outputs=[compare_output],
api_visibility="private"
)
# ACOUSTIC ANALYSIS
with gr.Column(scale=1, elem_classes="demo-card-column"):
gr.HTML("""
<div style="display: flex; align-items: center; gap: 6px; margin-bottom: 8px; padding-left: 18px; padding-top: 10px;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<path d="M22 10C22 10 20 4 17 4C14 4 12 16 9 16C6 16 4 10 2 10" stroke="#7c3aed" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<g transform="translate(13, 11)">
<circle cx="5" cy="5" r="4" stroke="#7c3aed" stroke-width="1.5"/>
<path d="M8 8L11 11" stroke="#7c3aed" stroke-width="1.5" stroke-linecap="round"/>
</g>
</svg>
<div style="font-size: 16px; font-weight: 700; color: #a5b4fc; text-transform: uppercase; letter-spacing: 1px;">
ANALYZE ACOUSTICS
</div>
</div>
""")
acoustic_audio = gr.Audio(
type="filepath",
label="Audio Input",
show_label=False,
format="wav"
)
acoustic_btn = gr.Button("ANALYZE", variant="primary", size="lg", elem_classes="custom-action-btn")
acoustic_output = gr.HTML(value=create_acoustic_empty())
acoustic_btn.click(
demo_acoustic_analysis,
inputs=[acoustic_audio],
outputs=[acoustic_output],
api_visibility="private"
)
# ==================== SECOND ROW: 3 MORE DEMO CARDS ====================
with gr.Row(equal_height=True, elem_classes="demo-row"):
# AUDIO TRANSCRIPTION
with gr.Column(scale=1, elem_classes="demo-card-column"):
gr.HTML("""
<div style="display: flex; align-items: center; gap: 6px; margin-bottom: 8px; padding-left: 18px; padding-top: 10px;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<path d="M2 12C2 12 4 5 7 5C10 5 11 19 14 19C15.5 19 16.5 15 16.5 15" stroke="#7c3aed" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19 7H22" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M19 12H22" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
<path d="M19 17H22" stroke="#7c3aed" stroke-width="2" stroke-linecap="round"/>
</svg>
<div style="font-size: 16px; font-weight: 700; color: #a5b4fc; text-transform: uppercase; letter-spacing: 1px;">
TRANSCRIBE AUDIO
</div>
</div>
""")
transcribe_audio_input = gr.Audio(
type="filepath",
label="Audio Input",
show_label=False,
format="wav"
)
transcribe_btn = gr.Button("TRANSCRIBE", variant="primary", size="lg", elem_classes="custom-action-btn")
transcribe_output = gr.HTML(value=create_transcription_empty())
transcribe_btn.click(
lambda audio: demo_transcribe_audio(audio, "en"),
inputs=[transcribe_audio_input],
outputs=[transcribe_output],
api_visibility="private"
)
# CLEAN AUDIO EXTRACTION
with gr.Column(scale=1, elem_classes="demo-card-column"):
gr.HTML("""
<div style="display: flex; align-items: center; gap: 6px; margin-bottom: 8px; padding-left: 18px; padding-top: 10px;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<path d="M12 5V19" stroke="#7c3aed" stroke-width="2.5" stroke-linecap="round"/>
<path d="M9 8V16" stroke="#7c3aed" stroke-width="2.5" stroke-linecap="round"/>
<path d="M15 8V16" stroke="#7c3aed" stroke-width="2.5" stroke-linecap="round"/>
<path d="M5 4H3V20H5" stroke="#7c3aed" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
<path d="M19 4H21V20H19" stroke="#7c3aed" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>
</svg>
<div style="font-size: 16px; font-weight: 700; color: #a5b4fc; text-transform: uppercase; letter-spacing: 1px;">
ISOLATE VOICE
</div>
</div>
""")
clean_audio_input = gr.Audio(
type="filepath",
label="Audio with Background",
show_label=False,
format="wav"
)
clean_btn = gr.Button("EXTRACT VOICE", variant="primary", size="lg", elem_classes="custom-action-btn")
clean_audio_output = gr.Audio(label="Clean Audio", type="filepath", visible=True)
clean_btn.click(
demo_clean_extraction,
inputs=[clean_audio_input],
outputs=[clean_audio_output],
api_visibility="private"
)
# VOICE SIMILARITY
with gr.Column(scale=1, elem_classes="demo-card-column"):
gr.HTML("""
<div style="display: flex; align-items: center; gap: 6px; margin-bottom: 8px; padding-left: 18px; padding-top: 10px;">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" style="flex-shrink: 0;">
<circle cx="12" cy="12" r="9" stroke="#7c3aed" stroke-width="1" opacity="0.3"/>
<path d="M12 3V21" stroke="#7c3aed" stroke-width="1" opacity="0.3"/>
<path d="M4.2 7.5L19.8 16.5" stroke="#7c3aed" stroke-width="1" opacity="0.3"/>
<path d="M19.8 7.5L4.2 16.5" stroke="#7c3aed" stroke-width="1" opacity="0.3"/>
<path d="M12 5L18 9L16.5 18H7.5L6 9L12 5Z" fill="#7c3aed" fill-opacity="0.4" stroke="#7c3aed" stroke-width="2" stroke-linejoin="round"/>
<circle cx="12" cy="5" r="1.5" fill="#7c3aed"/>
<circle cx="18" cy="9" r="1.5" fill="#7c3aed"/>
<circle cx="16.5" cy="18" r="1.5" fill="#7c3aed"/>
<circle cx="7.5" cy="18" r="1.5" fill="#7c3aed"/>
<circle cx="6" cy="9" r="1.5" fill="#7c3aed"/>
</svg>
<div style="font-size: 16px; font-weight: 700; color: #a5b4fc; text-transform: uppercase; letter-spacing: 1px;">
GRADE VOICE
</div>
</div>
""")
with gr.Row():
similarity_user_audio = gr.Audio(
type="filepath",
label="User Audio",
show_label=False,
format="wav"
)
similarity_ref_audio = gr.Audio(
type="filepath",
label="Reference Audio",
show_label=False,
format="wav"
)
similarity_btn = gr.Button("ANALYZE", variant="primary", size="lg", elem_classes="custom-action-btn")
similarity_output = gr.HTML(value=create_similarity_empty())
similarity_btn.click(
demo_voice_similarity,
inputs=[similarity_user_audio, similarity_ref_audio],
outputs=[similarity_output],
api_visibility="private"
)
# ==================== MCP TOOL INTERFACES (HIDDEN, API ONLY) ====================
with gr.Row(visible=False):
# extract_embedding
mcp_emb_input = gr.Textbox()
mcp_emb_output = gr.Textbox()
mcp_emb_btn = gr.Button()
mcp_emb_btn.click(extract_embedding, inputs=[mcp_emb_input], outputs=[mcp_emb_output])
# match_voice
mcp_cmp_input1 = gr.Textbox()
mcp_cmp_input2 = gr.Textbox()
mcp_cmp_output = gr.Textbox()
mcp_cmp_btn = gr.Button()
mcp_cmp_btn.click(match_voice, inputs=[mcp_cmp_input1, mcp_cmp_input2], outputs=[mcp_cmp_output])
# analyze_acoustics
mcp_ac_input = gr.Textbox()
mcp_ac_output = gr.Textbox()
mcp_ac_btn = gr.Button()
mcp_ac_btn.click(analyze_acoustics, inputs=[mcp_ac_input], outputs=[mcp_ac_output])
# transcribe_audio
mcp_tr_input = gr.Textbox()
mcp_tr_lang = gr.Textbox(value="en")
mcp_tr_output = gr.Textbox()
mcp_tr_btn = gr.Button()
mcp_tr_btn.click(transcribe_audio, inputs=[mcp_tr_input, mcp_tr_lang], outputs=[mcp_tr_output])
# isolate_voice
mcp_iso_input = gr.Textbox()
mcp_iso_output = gr.Textbox()
mcp_iso_btn = gr.Button()
mcp_iso_btn.click(isolate_voice, inputs=[mcp_iso_input], outputs=[mcp_iso_output])
# grade_voice
mcp_sim_user = gr.Textbox()
mcp_sim_ref = gr.Textbox()
mcp_sim_text = gr.Textbox()
mcp_sim_cat = gr.Textbox(value="meme")
mcp_sim_output = gr.Textbox()
mcp_sim_btn = gr.Button()
mcp_sim_btn.click(grade_voice, inputs=[mcp_sim_user, mcp_sim_ref, mcp_sim_text, mcp_sim_cat], outputs=[mcp_sim_output])
if __name__ == "__main__":
demo.launch(
server_name="0.0.0.0",
server_port=7860,
mcp_server=True
)
|