File size: 2,331 Bytes
0006fec
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
48aba8d
e5b527a
 
 
 
 
 
0006fec
 
48aba8d
 
0006fec
48aba8d
e5b527a
 
0006fec
 
 
e5b527a
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
import gradio as gr

# HTML ์œ„์ ฏ ์ฝ”๋“œ. ์‹ค์ œ `<assistant_id>`์™€ `<your_public_api_key>`๋Š” ์ ์ ˆํ•œ ๊ฐ’์œผ๋กœ ๋Œ€์ฒดํ•ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.
widget_html = """
<div id="vapi-widget-container"></div>
<script>
  var vapiInstance = null;
  const assistant = "d7aa8e1f-e2c6-4c97-a7d7-b32101eb1e0a"; // Assistant ID๋กœ ๋Œ€์ฒด
  const apiKey = "ea671a92-bb34-46dc-b999-70ef53b64a4b"; // Public key๋กœ ๋Œ€์ฒด
  const buttonConfig = {
    position: "bottom-right",
    offset: "40px",
    width: "50px",
    height: "50px",
    idle: {
      color: `rgb(93, 254, 202)`,
      type: "pill",
      title: "Have a quick question?",
      subtitle: "Talk with our AI assistant",
      icon: `https://unpkg.com/lucide-static@0.321.0/icons/phone.svg`,
    },
    loading: {
      color: `rgb(93, 124, 202)`,
      type: "pill",
      title: "Connecting...",
      subtitle: "Please wait",
      icon: `https://unpkg.com/lucide-static@0.321.0/icons/loader-2.svg`,
    },
    active: {
      color: `rgb(255, 0, 0)`,
      type: "pill",
      title: "Call is in progress...",
      subtitle: "End the call.",
      icon: `https://unpkg.com/lucide-static@0.321.0/icons/phone-off.svg`,
    },
  };

  (function (d, t) {
    var g = d.createElement(t), s = d.getElementsByTagName(t)[0];
    g.src = "https://cdn.jsdelivr.net/gh/VapiAI/html-script-tag@latest/dist/assets/index.js";
    g.defer = true;
    g.async = true;
    s.parentNode.insertBefore(g, s);
    g.onload = function () {
      vapiInstance = window.vapiSDK.run({
        apiKey: apiKey,
        assistant: assistant,
        config: buttonConfig,
        containerId: 'vapi-widget-container',  // Vapi ์œ„์ ฏ์„ ํฌํ•จํ•  ์ปจํ…Œ์ด๋„ˆ ID
      });
    };
  })(document, "script");
</script>
"""

def show_widget():
    # Gradio HTML ์ปดํฌ๋„ŒํŠธ์— ์œ„์ ฏ ์ฝ”๋“œ๋ฅผ ์ „๋‹ฌํ•ฉ๋‹ˆ๋‹ค.
    return widget_html


css = """
.gradio button.gr-button:enabled {
    display: none;
}
"""

iface = gr.Interface(
    fn=show_widget,
    inputs=[],
    outputs=gr.HTML(label="Vapi Voice Widget"),
    title="Vapi Voice Widget Integration Example",
    description="This is an example of integrating the Vapi Voice Widget into a Gradio web app.",
    live=True,  # live ๋ชจ๋“œ ํ™œ์„ฑํ™”
    css=css  # CSS๋ฅผ ์ถ”๊ฐ€ํ•˜์—ฌ "Generate" ๋ฒ„ํŠผ์„ ์ˆจ๊น๋‹ˆ๋‹ค.
)

# ์ธํ„ฐํŽ˜์ด์Šค ์‹คํ–‰
iface.launch()