Spaces:
Sleeping
Sleeping
Download chatbot/ui.py from PradeepVerma23/PolicyAI: direct link, hf CLI and curl.
- Browser
- Download file 6.89 kB
-
https://huggingface.co/spaces/PradeepVerma23/PolicyAI/resolve/main/chatbot/ui.py
- Command line
-
hf download hf://spaces/PradeepVerma23/PolicyAI/chatbot/ui.py
-
curl -L -o ui.py https://huggingface.co/spaces/PradeepVerma23/PolicyAI/resolve/main/chatbot/ui.py
6.89 kB
| """ | |
| ui.py β Gradio layout and event wiring for PolicyAI Chatbot | |
| Exports | |
| ------- | |
| demo : gr.Blocks instance β passed to demo.launch() in app.py. | |
| """ | |
| import gradio as gr | |
| from handlers import respond, clear_chat | |
| SAMPLE_QUESTIONS = [ | |
| "What are the leave entitlements for employees?", | |
| "What are the password and authentication requirements?", | |
| "How should a security incident be reported and handled?", | |
| "What security measures are required for remote work?", | |
| "What are the disciplinary action procedures?", | |
| "How should employees be trained on IT security awareness?", | |
| ] | |
| # ββ Layout βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| with gr.Blocks(title="PolicyAI β HR & IT Security Intelligence") as demo: | |
| # ββ Header βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| gr.HTML(""" | |
| <div id="policyai-header"> | |
| <div class="header-logo"> | |
| <span class="logo-icon">🔐</span> | |
| <span class="logo-text">PolicyAI</span> | |
| </div> | |
| <p class="header-sub"> | |
| AI-powered HR & IT Security policy intelligence — instant answers grounded in | |
| your HR policies, NIST Cybersecurity Framework, incident response guides, | |
| and remote work security documents, with exact page citations. | |
| </p> | |
| <div class="badge-row"> | |
| <span class="badge badge-b">⚡ Groq · llama-3.1-8b</span> | |
| <span class="badge badge-g">✓ Zero hallucination</span> | |
| <span class="badge badge-v">📄 Page-level citations</span> | |
| <span class="badge badge-o">📄 5 Policy Sources</span> | |
| </div> | |
| </div> | |
| """) | |
| # ββ Main two-column layout ββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| with gr.Row(equal_height=False): | |
| # ββ Left β chat interface βββββββββββββββββββββββββββββββββββββββββββ | |
| with gr.Column(scale=63): | |
| chatbot = gr.Chatbot( | |
| value=[], | |
| height=500, | |
| show_label=False, | |
| layout="bubble", | |
| elem_id="policyai-chat", | |
| placeholder=( | |
| "<div style='text-align:center;padding:70px 20px;'>" | |
| "<div style='font-size:44px;margin-bottom:14px;'>🔐</div>" | |
| "<div style='font-size:15px;font-weight:600;color:#2a3f5a;'>" | |
| "Ask PolicyAI anything</div>" | |
| "<div style='font-size:13px;margin-top:8px;color:#1e2f42;'>" | |
| "HR policies, IT security standards, incident response, remote work — " | |
| "select a quick question or type your own.</div>" | |
| "</div>" | |
| ), | |
| ) | |
| with gr.Row(elem_id="policyai-input-row"): | |
| msg_input = gr.Textbox( | |
| placeholder="Ask a policy questionβ¦", | |
| show_label=False, | |
| scale=6, | |
| autofocus=True, | |
| lines=1, | |
| max_lines=5, | |
| container=False, | |
| elem_id="policyai-msg", | |
| ) | |
| send_btn = gr.Button( | |
| "Send β€", | |
| variant="primary", | |
| scale=1, | |
| min_width=78, | |
| elem_id="policyai-send", | |
| ) | |
| clear_btn = gr.Button( | |
| "β Clear", | |
| variant="secondary", | |
| scale=1, | |
| min_width=72, | |
| elem_id="policyai-clear", | |
| ) | |
| # ββ Right β quick questions + sources βββββββββββββββββββββββββββββββ | |
| with gr.Column(scale=37, min_width=260): | |
| # Quick questions card | |
| gr.HTML(""" | |
| <div class="panel-section"> | |
| <div class="panel-title">💡 Quick Questions</div> | |
| <div class="panel-body"> | |
| """) | |
| for q in SAMPLE_QUESTIONS: | |
| gr.Button(q, variant="secondary", size="sm", elem_classes="q-btn").click( | |
| fn=lambda question=q: question, | |
| outputs=msg_input, | |
| ) | |
| gr.HTML("</div></div>") | |
| # Sources card | |
| gr.HTML(""" | |
| <div class="panel-section" style="margin-top:12px;"> | |
| <div class="panel-title">📄 Retrieved Sources</div> | |
| """) | |
| sources_box = gr.Textbox( | |
| value="", | |
| placeholder="Source chunks will appear here after your first question...", | |
| interactive=False, | |
| lines=13, | |
| max_lines=22, | |
| show_label=False, | |
| container=False, | |
| elem_id="policyai-sources", | |
| ) | |
| gr.HTML("</div>") | |
| # ββ Footer ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| gr.HTML(""" | |
| <div id="policyai-footer"> | |
| Powered by | |
| <a href="https://groq.com" target="_blank">Groq</a> | |
| <span class="sep">·</span> | |
| <a href="https://qdrant.tech" target="_blank">Qdrant</a> | |
| <span class="sep">·</span> | |
| <a href="https://python.langchain.com" target="_blank">LangChain</a> | |
| <span class="sep">·</span> | |
| <a href="https://gradio.app" target="_blank">Gradio</a> | |
| <span class="sep">|</span> | |
| Codebasics AI Engineering Bootcamp | |
| </div> | |
| """) | |
| # ββ Event wiring ββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ | |
| send_btn.click( | |
| fn=respond, | |
| inputs=[msg_input, chatbot], | |
| outputs=[chatbot, sources_box], | |
| ).then(fn=lambda: "", outputs=msg_input) | |
| msg_input.submit( | |
| fn=respond, | |
| inputs=[msg_input, chatbot], | |
| outputs=[chatbot, sources_box], | |
| ).then(fn=lambda: "", outputs=msg_input) | |
| clear_btn.click( | |
| fn=clear_chat, | |
| outputs=[chatbot, msg_input, sources_box], | |
| ) | |