-
Notifications
You must be signed in to change notification settings - Fork 0
/
ui.py
67 lines (61 loc) · 2.12 KB
/
ui.py
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
import gradio as gr
# Placeholder for chat UI
chat_placeholder = """
<div style="margin: 40px 20px;">
<h1 style="text-align: center; background: #18181c; border: 2px solid #f97316; padding: 10px 20px; border-radius: 15px;">
Welcome to NeMo Guardrails Documentation AI
</h1>
<p style="font-size: 16px; text-align: center; margin: 10px auto; max-width: 650px">
Explore seamless integration of GitHub repositories and documentation with LLM-powered assistance, enhanced by NeMo Guardrails for advanced safety and security.
</p>
</div>
"""
# Chat examples for user guidance
chat_examples = [
["What LLMs are supported by NeMo Guardrails ?"],
["Can I deploy NeMo Guardrails in production ?"]
]
# Custom CSS for styling
custom_css = """
a {
color: #f97316;
}
.avatar-image {
margin: 0;
}
"""
# Function to create a chatbot with custom settings
def chat():
return gr.Chatbot(
height=600,
type="messages",
elem_classes="chatbot",
placeholder=chat_placeholder,
layout="panel",
avatar_images=("./images/user.png", "./images/ai.png"),
)
# Function to render the header
def header():
return gr.Markdown(
"""
# NeMo Guardrails Chatbot 💂🏼
Ask questions about [NVIDIA's NeMo Guardrails](https://docs.nvidia.com/nemo/guardrails/index.html) documentations.
"""
)
def demo_header_settings(model_list):
gr.HTML("""<div style='height: 10px'></div>""")
with gr.Row():
with gr.Column(scale=1):
header()
with gr.Column(scale=2):
with gr.Row():
guardrail = gr.Checkbox(label="Enable NeMo Guardrails", value=True, scale=1)
provider = gr.Dropdown(list(model_list.keys()), value=list(model_list.keys())[0], show_label=False, scale=2)
model_key = gr.Textbox(
placeholder="Enter your OpenAI/Gemini/Groq API key",
type="password",
show_label=False,
scale=4
)
start_chat = gr.Button("Initialize Chat")
return model_key, provider, guardrail, start_chat