Spaces:
Running
on
Zero
Running
on
Zero
Nursing Citizen Development
commited on
Commit
Β·
0a7637c
1
Parent(s):
15e05d2
Fix: Simplify to ChatInterface and pin Gradio 4.44.1 for stability
Browse files- app.py +40 -211
- requirements.txt +1 -1
app.py
CHANGED
|
@@ -1,7 +1,6 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from knowledge_base import PNAKnowledgeBase
|
| 3 |
from pna_client import PNAAssistantClient
|
| 4 |
-
import os
|
| 5 |
|
| 6 |
# --- Constants ---
|
| 7 |
GUIDE_FILENAME = "Professional nurse advocate A-EQUIP model Guide.md"
|
|
@@ -24,226 +23,56 @@ def chat_response(message, history):
|
|
| 24 |
CUSTOM_CSS = """
|
| 25 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@600;700&display=swap');
|
| 26 |
|
| 27 |
-
/* Root Variables */
|
| 28 |
-
:root {
|
| 29 |
-
--primary: #4f46e5;
|
| 30 |
-
--primary-light: #818cf8;
|
| 31 |
-
--secondary: #0d9488;
|
| 32 |
-
--bg-main: #f8fafc;
|
| 33 |
-
--bg-card: rgba(255, 255, 255, 0.85);
|
| 34 |
-
--text-primary: #1e293b;
|
| 35 |
-
--text-secondary: #64748b;
|
| 36 |
-
--border-color: rgba(148, 163, 184, 0.2);
|
| 37 |
-
--shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
|
| 38 |
-
--shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -2px rgba(0, 0, 0, 0.1);
|
| 39 |
-
--shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -4px rgba(0, 0, 0, 0.1);
|
| 40 |
-
}
|
| 41 |
-
|
| 42 |
-
/* Global Styles */
|
| 43 |
.gradio-container {
|
| 44 |
-
max-width:
|
| 45 |
margin: 0 auto !important;
|
| 46 |
-
font-family: 'Inter',
|
| 47 |
-
background: var(--bg-main) !important;
|
| 48 |
-
}
|
| 49 |
-
|
| 50 |
-
/* Header */
|
| 51 |
-
.header-container {
|
| 52 |
-
text-align: center;
|
| 53 |
-
padding: 2rem 1rem 1.5rem;
|
| 54 |
-
background: linear-gradient(135deg, var(--primary) 0%, var(--secondary) 100%);
|
| 55 |
-
border-radius: 0 0 24px 24px;
|
| 56 |
-
margin: -1rem -1rem 1.5rem -1rem;
|
| 57 |
-
box-shadow: var(--shadow-lg);
|
| 58 |
-
}
|
| 59 |
-
|
| 60 |
-
.header-title {
|
| 61 |
-
font-family: 'Outfit', sans-serif;
|
| 62 |
-
font-size: 1.75rem;
|
| 63 |
-
font-weight: 700;
|
| 64 |
-
color: white;
|
| 65 |
-
margin: 0 0 0.5rem 0;
|
| 66 |
-
letter-spacing: -0.02em;
|
| 67 |
-
}
|
| 68 |
-
|
| 69 |
-
.header-subtitle {
|
| 70 |
-
font-size: 0.95rem;
|
| 71 |
-
color: rgba(255, 255, 255, 0.9);
|
| 72 |
-
margin: 0;
|
| 73 |
-
font-weight: 400;
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
.emoji-bar {
|
| 77 |
-
font-size: 1.5rem;
|
| 78 |
-
margin-top: 0.75rem;
|
| 79 |
-
letter-spacing: 0.25rem;
|
| 80 |
-
}
|
| 81 |
-
|
| 82 |
-
/* Chat Container */
|
| 83 |
-
.chat-container {
|
| 84 |
-
background: var(--bg-card) !important;
|
| 85 |
-
backdrop-filter: blur(12px);
|
| 86 |
-
border-radius: 16px !important;
|
| 87 |
-
border: 1px solid var(--border-color) !important;
|
| 88 |
-
box-shadow: var(--shadow-md) !important;
|
| 89 |
-
padding: 1rem !important;
|
| 90 |
-
}
|
| 91 |
-
|
| 92 |
-
/* Chatbot Messages */
|
| 93 |
-
.message-wrap {
|
| 94 |
-
padding: 0.75rem 1rem !important;
|
| 95 |
-
}
|
| 96 |
-
|
| 97 |
-
.user-message, .bot-message {
|
| 98 |
-
border-radius: 16px !important;
|
| 99 |
-
padding: 0.875rem 1rem !important;
|
| 100 |
-
font-size: 0.95rem !important;
|
| 101 |
-
line-height: 1.6 !important;
|
| 102 |
-
}
|
| 103 |
-
|
| 104 |
-
.user-message {
|
| 105 |
-
background: var(--primary) !important;
|
| 106 |
-
color: white !important;
|
| 107 |
-
border-bottom-right-radius: 4px !important;
|
| 108 |
-
}
|
| 109 |
-
|
| 110 |
-
.bot-message {
|
| 111 |
-
background: white !important;
|
| 112 |
-
color: var(--text-primary) !important;
|
| 113 |
-
border: 1px solid var(--border-color) !important;
|
| 114 |
-
border-bottom-left-radius: 4px !important;
|
| 115 |
-
}
|
| 116 |
-
|
| 117 |
-
/* Input Area */
|
| 118 |
-
.input-container textarea {
|
| 119 |
-
border-radius: 24px !important;
|
| 120 |
-
border: 2px solid var(--border-color) !important;
|
| 121 |
-
padding: 0.875rem 1.25rem !important;
|
| 122 |
-
font-size: 0.95rem !important;
|
| 123 |
-
transition: border-color 0.2s ease, box-shadow 0.2s ease !important;
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
.input-container textarea:focus {
|
| 127 |
-
border-color: var(--primary) !important;
|
| 128 |
-
box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.1) !important;
|
| 129 |
-
outline: none !important;
|
| 130 |
}
|
| 131 |
|
| 132 |
-
|
| 133 |
-
.submit-btn {
|
| 134 |
-
background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%) !important;
|
| 135 |
-
border: none !important;
|
| 136 |
-
border-radius: 24px !important;
|
| 137 |
-
padding: 0.75rem 1.5rem !important;
|
| 138 |
-
font-weight: 600 !important;
|
| 139 |
-
color: white !important;
|
| 140 |
-
cursor: pointer !important;
|
| 141 |
-
transition: transform 0.15s ease, box-shadow 0.15s ease !important;
|
| 142 |
-
}
|
| 143 |
-
|
| 144 |
-
.submit-btn:hover {
|
| 145 |
-
transform: translateY(-1px) !important;
|
| 146 |
-
box-shadow: var(--shadow-md) !important;
|
| 147 |
-
}
|
| 148 |
-
|
| 149 |
-
/* Examples */
|
| 150 |
-
.examples-container {
|
| 151 |
-
margin-top: 1rem !important;
|
| 152 |
-
}
|
| 153 |
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
border: 1px solid var(--border-color) !important;
|
| 157 |
-
border-radius: 20px !important;
|
| 158 |
-
padding: 0.5rem 1rem !important;
|
| 159 |
-
font-size: 0.85rem !important;
|
| 160 |
-
color: var(--text-secondary) !important;
|
| 161 |
-
transition: all 0.2s ease !important;
|
| 162 |
-
}
|
| 163 |
-
|
| 164 |
-
.examples-container button:hover {
|
| 165 |
-
border-color: var(--primary) !important;
|
| 166 |
-
color: var(--primary) !important;
|
| 167 |
-
background: rgba(79, 70, 229, 0.05) !important;
|
| 168 |
-
}
|
| 169 |
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 174 |
|
| 175 |
-
|
| 176 |
-
.
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
color: var(--text-secondary);
|
| 180 |
-
margin-top: 1rem;
|
| 181 |
-
padding: 0.75rem;
|
| 182 |
-
background: rgba(148, 163, 184, 0.1);
|
| 183 |
-
border-radius: 8px;
|
| 184 |
-
}
|
| 185 |
"""
|
| 186 |
|
| 187 |
-
# ---
|
| 188 |
-
with gr.Blocks(css=CUSTOM_CSS, title="PNA Assistant"
|
| 189 |
-
|
| 190 |
-
gr.HTML("""
|
| 191 |
-
<div class="header-container">
|
| 192 |
-
<h1 class="header-title">Professional Nurse Advocate Assistant</h1>
|
| 193 |
-
<p class="header-subtitle">Guiding you through the A-EQUIP model and Restorative Supervision</p>
|
| 194 |
-
<div class="emoji-bar">π¨πΎββοΈ π©π½ββοΈ π¨πΏββοΈ π©π»ββοΈ π©ββοΈ</div>
|
| 195 |
-
</div>
|
| 196 |
-
""")
|
| 197 |
-
|
| 198 |
-
# Chat Interface
|
| 199 |
-
with gr.Column(elem_classes="chat-container"):
|
| 200 |
-
chatbot = gr.Chatbot(
|
| 201 |
-
label="",
|
| 202 |
-
height=400,
|
| 203 |
-
show_label=False,
|
| 204 |
-
avatar_images=(None, "https://em-content.zobj.net/source/apple/391/woman-health-worker-medium-skin-tone_1f469-1f3fd-200d-2695-fe0f.png"),
|
| 205 |
-
bubble_full_width=False,
|
| 206 |
-
)
|
| 207 |
-
|
| 208 |
-
with gr.Row():
|
| 209 |
-
msg = gr.Textbox(
|
| 210 |
-
placeholder="Ask about the A-EQUIP model, Restorative Supervision, or the PNA role...",
|
| 211 |
-
show_label=False,
|
| 212 |
-
container=False,
|
| 213 |
-
elem_classes="input-container",
|
| 214 |
-
scale=9
|
| 215 |
-
)
|
| 216 |
-
submit = gr.Button("Send", elem_classes="submit-btn", scale=1)
|
| 217 |
-
|
| 218 |
-
# Examples
|
| 219 |
-
gr.Examples(
|
| 220 |
-
examples=[
|
| 221 |
-
"What is the A-EQUIP model?",
|
| 222 |
-
"Explain the four functions of clinical supervision",
|
| 223 |
-
"How can I support a colleague through restorative supervision?",
|
| 224 |
-
"What does a Professional Nurse Advocate do?"
|
| 225 |
-
],
|
| 226 |
-
inputs=msg
|
| 227 |
-
)
|
| 228 |
-
|
| 229 |
-
# Disclaimer
|
| 230 |
-
gr.HTML("""
|
| 231 |
-
<div class="disclaimer">
|
| 232 |
-
β οΈ This tool is for educational purposes only. It does not provide clinical advice.
|
| 233 |
-
</div>
|
| 234 |
-
""")
|
| 235 |
|
| 236 |
-
|
| 237 |
-
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
| 241 |
-
|
| 242 |
-
|
| 243 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 244 |
|
| 245 |
-
|
| 246 |
-
submit.click(respond, [msg, chatbot], [msg, chatbot])
|
| 247 |
|
| 248 |
if __name__ == "__main__":
|
| 249 |
-
demo.launch(
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from knowledge_base import PNAKnowledgeBase
|
| 3 |
from pna_client import PNAAssistantClient
|
|
|
|
| 4 |
|
| 5 |
# --- Constants ---
|
| 6 |
GUIDE_FILENAME = "Professional nurse advocate A-EQUIP model Guide.md"
|
|
|
|
| 23 |
CUSTOM_CSS = """
|
| 24 |
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=Outfit:wght@600;700&display=swap');
|
| 25 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 26 |
.gradio-container {
|
| 27 |
+
max-width: 800px !important;
|
| 28 |
margin: 0 auto !important;
|
| 29 |
+
font-family: 'Inter', sans-serif !important;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 30 |
}
|
| 31 |
|
| 32 |
+
.contain { background: linear-gradient(135deg, #4f46e5 0%, #0d9488 100%) !important; }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
+
footer { display: none !important; }
|
| 35 |
+
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 36 |
|
| 37 |
+
HEADER_HTML = """
|
| 38 |
+
<div style="text-align: center; padding: 1.5rem; background: linear-gradient(135deg, #4f46e5 0%, #0d9488 100%); border-radius: 12px; margin-bottom: 1rem;">
|
| 39 |
+
<h1 style="color: white; font-family: 'Outfit', sans-serif; margin: 0; font-size: 1.5rem;">
|
| 40 |
+
Professional Nurse Advocate Assistant
|
| 41 |
+
</h1>
|
| 42 |
+
<p style="color: rgba(255,255,255,0.9); margin: 0.5rem 0 0 0; font-size: 0.9rem;">
|
| 43 |
+
Guiding you through the A-EQUIP model and Restorative Supervision
|
| 44 |
+
</p>
|
| 45 |
+
<div style="font-size: 1.25rem; margin-top: 0.5rem; letter-spacing: 0.2rem;">
|
| 46 |
+
π¨πΎββοΈ π©π½ββοΈ π¨πΏββοΈ π©π»ββοΈ π©ββοΈ
|
| 47 |
+
</div>
|
| 48 |
+
</div>
|
| 49 |
+
"""
|
| 50 |
|
| 51 |
+
DISCLAIMER_HTML = """
|
| 52 |
+
<div style="text-align: center; font-size: 0.75rem; color: #64748b; margin-top: 1rem; padding: 0.75rem; background: rgba(148, 163, 184, 0.1); border-radius: 8px;">
|
| 53 |
+
β οΈ This tool is for educational purposes only. It does not provide clinical advice.
|
| 54 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 55 |
"""
|
| 56 |
|
| 57 |
+
# --- Simple ChatInterface ---
|
| 58 |
+
with gr.Blocks(css=CUSTOM_CSS, title="PNA Assistant") as demo:
|
| 59 |
+
gr.HTML(HEADER_HTML)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
|
| 61 |
+
gr.ChatInterface(
|
| 62 |
+
fn=chat_response,
|
| 63 |
+
type="tuples",
|
| 64 |
+
examples=[
|
| 65 |
+
"What is the A-EQUIP model?",
|
| 66 |
+
"Explain the four functions of clinical supervision",
|
| 67 |
+
"How can I support a colleague through restorative supervision?",
|
| 68 |
+
"What does a Professional Nurse Advocate do?"
|
| 69 |
+
],
|
| 70 |
+
title="",
|
| 71 |
+
retry_btn=None,
|
| 72 |
+
undo_btn=None,
|
| 73 |
+
)
|
| 74 |
|
| 75 |
+
gr.HTML(DISCLAIMER_HTML)
|
|
|
|
| 76 |
|
| 77 |
if __name__ == "__main__":
|
| 78 |
+
demo.launch()
|
requirements.txt
CHANGED
|
@@ -1,4 +1,4 @@
|
|
| 1 |
-
gradio
|
| 2 |
transformers
|
| 3 |
torch
|
| 4 |
sentence-transformers
|
|
|
|
| 1 |
+
gradio==4.44.1
|
| 2 |
transformers
|
| 3 |
torch
|
| 4 |
sentence-transformers
|