vp / app.py
arxivgpt kim
Create app.py
0006fec verified
raw
history blame
2.22 kB
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/[email protected]/icons/phone.svg`,
},
loading: {
color: `rgb(93, 124, 202)`,
type: "pill",
title: "Connecting...",
subtitle: "Please wait",
icon: `https://unpkg.com/[email protected]/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/[email protected]/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
# Gradio μΈν„°νŽ˜μ΄μŠ€ 생성
iface = gr.Interface(
fn=show_widget,
inputs=[], # μž…λ ₯ μ—†μŒ
outputs=gr.outputs.HTML(label="Vapi Voice Widget"), # HTML 좜λ ₯
title="Vapi Voice Widget Integration Example",
description="This is an example of integrating the Vapi Voice Widget into a Gradio web app."
)
# μΈν„°νŽ˜μ΄μŠ€ μ‹€ν–‰
iface.launch()