File size: 3,187 Bytes
4647fd4
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import gradio as gr
import os
import requests
import json

# Configuration
ULTRAVOX_API_KEY = os.getenv("ULTRAVOX_API_KEY")
ULTRAVOX_API_URL = "https://api.ultravox.ai/api/chat"  # Modified to use chat endpoint

SYSTEM_PROMPT = """Your name is Steve and you're answering queries on behalf of Knolabs AI Agency, a UK-based company specializing in AI Automation and Web Development services.

Greet the user warmly and introduce yourself as a representative of Knolabs AI Agency. Ask how you can assist them today.

If they inquire about services, explain that Knolabs specializes in:
- AI Automation solutions (including Voice AI)
- Web Development services
- Multimodal AI use cases
- Customized business automation solutions

If asked about pricing, explain that Knolabs AI Agency operates both as a Pure AI Automation Agency and a Web Development Agency. After understanding their requirements, you'll pass the details to the relevant team, and a team member will reach out within 24 hours with a detailed timeline and quotation tailored to their specific needs.

Focus on:
- Understanding their business needs
- Gathering specific requirements
- Being professional and helpful
- Explaining Knolabs' expertise in delivering effective business solutions

Remember to collect their contact details for follow-up if they show interest."""

def create_ultravox_chat(message, history):
    # Prepare the chat request
    headers = {
        "Content-Type": "application/json",
        "X-API-Key": ULTRAVOX_API_KEY
    }
    
    # Include conversation history
    messages = []
    for human, assistant in history:
        messages.append({"role": "user", "content": human})
        messages.append({"role": "assistant", "content": assistant})
    messages.append({"role": "user", "content": message})
    
    data = {
        "messages": messages,
        "systemPrompt": SYSTEM_PROMPT,
        "model": "fixie-ai/ultravox",
        "temperature": 0.3
    }
    
    try:
        response = requests.post(ULTRAVOX_API_URL, headers=headers, json=data)
        response.raise_for_status()
        return response.json()["response"]
    except Exception as e:
        return f"I apologize, but I encountered an error: {str(e)}. Please try again later."

# Create the Gradio interface
with gr.Blocks(css="footer {display: none !important}") as demo:
    gr.Markdown("""
    # Knolabs AI Agency Assistant
    Welcome to Knolabs AI Agency! I'm Steve, your virtual assistant. How can I help you today?
    """)
    
    chatbot = gr.Chatbot(
        [],
        elem_id="chatbot",
        bubble_full_width=False,
        avatar_images=(None, "https://api.dicebear.com/7.x/bottts/svg?seed=steve")
    )
    msg = gr.Textbox(
        placeholder="Type your message here...",
        show_label=False
    )
    clear = gr.Button("Clear Conversation")
    
    def respond(message, chat_history):
        bot_message = create_ultravox_chat(message, chat_history)
        chat_history.append((message, bot_message))
        return "", chat_history
    
    msg.submit(respond, [msg, chatbot], [msg, chatbot])
    clear.click(lambda: None, None, chatbot, queue=False)

# Launch the app
demo.launch()