Spaces:
Running
Running
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
import os
|
3 |
+
import requests
|
4 |
+
import json
|
5 |
+
|
6 |
+
# Configuration
|
7 |
+
ULTRAVOX_API_KEY = os.getenv("ULTRAVOX_API_KEY")
|
8 |
+
ULTRAVOX_API_URL = "https://api.ultravox.ai/api/chat" # Modified to use chat endpoint
|
9 |
+
|
10 |
+
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.
|
11 |
+
|
12 |
+
Greet the user warmly and introduce yourself as a representative of Knolabs AI Agency. Ask how you can assist them today.
|
13 |
+
|
14 |
+
If they inquire about services, explain that Knolabs specializes in:
|
15 |
+
- AI Automation solutions (including Voice AI)
|
16 |
+
- Web Development services
|
17 |
+
- Multimodal AI use cases
|
18 |
+
- Customized business automation solutions
|
19 |
+
|
20 |
+
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.
|
21 |
+
|
22 |
+
Focus on:
|
23 |
+
- Understanding their business needs
|
24 |
+
- Gathering specific requirements
|
25 |
+
- Being professional and helpful
|
26 |
+
- Explaining Knolabs' expertise in delivering effective business solutions
|
27 |
+
|
28 |
+
Remember to collect their contact details for follow-up if they show interest."""
|
29 |
+
|
30 |
+
def create_ultravox_chat(message, history):
|
31 |
+
# Prepare the chat request
|
32 |
+
headers = {
|
33 |
+
"Content-Type": "application/json",
|
34 |
+
"X-API-Key": ULTRAVOX_API_KEY
|
35 |
+
}
|
36 |
+
|
37 |
+
# Include conversation history
|
38 |
+
messages = []
|
39 |
+
for human, assistant in history:
|
40 |
+
messages.append({"role": "user", "content": human})
|
41 |
+
messages.append({"role": "assistant", "content": assistant})
|
42 |
+
messages.append({"role": "user", "content": message})
|
43 |
+
|
44 |
+
data = {
|
45 |
+
"messages": messages,
|
46 |
+
"systemPrompt": SYSTEM_PROMPT,
|
47 |
+
"model": "fixie-ai/ultravox",
|
48 |
+
"temperature": 0.3
|
49 |
+
}
|
50 |
+
|
51 |
+
try:
|
52 |
+
response = requests.post(ULTRAVOX_API_URL, headers=headers, json=data)
|
53 |
+
response.raise_for_status()
|
54 |
+
return response.json()["response"]
|
55 |
+
except Exception as e:
|
56 |
+
return f"I apologize, but I encountered an error: {str(e)}. Please try again later."
|
57 |
+
|
58 |
+
# Create the Gradio interface
|
59 |
+
with gr.Blocks(css="footer {display: none !important}") as demo:
|
60 |
+
gr.Markdown("""
|
61 |
+
# Knolabs AI Agency Assistant
|
62 |
+
Welcome to Knolabs AI Agency! I'm Steve, your virtual assistant. How can I help you today?
|
63 |
+
""")
|
64 |
+
|
65 |
+
chatbot = gr.Chatbot(
|
66 |
+
[],
|
67 |
+
elem_id="chatbot",
|
68 |
+
bubble_full_width=False,
|
69 |
+
avatar_images=(None, "https://api.dicebear.com/7.x/bottts/svg?seed=steve")
|
70 |
+
)
|
71 |
+
msg = gr.Textbox(
|
72 |
+
placeholder="Type your message here...",
|
73 |
+
show_label=False
|
74 |
+
)
|
75 |
+
clear = gr.Button("Clear Conversation")
|
76 |
+
|
77 |
+
def respond(message, chat_history):
|
78 |
+
bot_message = create_ultravox_chat(message, chat_history)
|
79 |
+
chat_history.append((message, bot_message))
|
80 |
+
return "", chat_history
|
81 |
+
|
82 |
+
msg.submit(respond, [msg, chatbot], [msg, chatbot])
|
83 |
+
clear.click(lambda: None, None, chatbot, queue=False)
|
84 |
+
|
85 |
+
# Launch the app
|
86 |
+
demo.launch()
|