Spaces:
Sleeping
Sleeping
Commit
Β·
8558835
1
Parent(s):
474f5b6
Refactor UI to Single Page Dashboard layout
Browse files- apps/web/app.py +45 -64
apps/web/app.py
CHANGED
|
@@ -145,74 +145,55 @@ with gr.Blocks(title="RAG Knowledge Assistant", theme=gr.themes.Soft()) as demo:
|
|
| 145 |
gr.Markdown("# π€ RAG Knowledge Assistant")
|
| 146 |
|
| 147 |
with gr.Row():
|
| 148 |
-
# Left Column:
|
| 149 |
-
with gr.Column(scale=1):
|
| 150 |
-
gr.Markdown("###
|
| 151 |
-
gr.Markdown("
|
| 152 |
|
| 153 |
-
with gr.Group():
|
| 154 |
-
gr.Markdown("#### Step 1: Teach Me π")
|
| 155 |
-
gr.Markdown("1. Go to **'1. Teach Me'** tab.\n2. Upload a PDF or check **'Load Sports Legends'**.\n3. Click **π Ingest**.")
|
| 156 |
-
|
| 157 |
-
with gr.Group():
|
| 158 |
-
gr.Markdown("#### Step 2: Chat with Me π¬")
|
| 159 |
-
gr.Markdown("1. Go to **'2. Talk to Me'** tab.\n2. Pick **Gemini/OpenAI**.\n3. Ask me anything!")
|
| 160 |
-
|
| 161 |
-
# Right Column: Main App (Scale 3)
|
| 162 |
-
with gr.Column(scale=3):
|
| 163 |
with gr.Tabs():
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
with gr.Column():
|
| 170 |
-
gr.Markdown("#### Option A: Upload Documents")
|
| 171 |
-
file_upload = gr.File(
|
| 172 |
-
label="Upload PDF / TXT / HTML",
|
| 173 |
-
file_count="multiple",
|
| 174 |
-
file_types=[".pdf", ".txt", ".html"]
|
| 175 |
-
)
|
| 176 |
-
with gr.Column():
|
| 177 |
-
gr.Markdown("#### Option B: Use Sample Data")
|
| 178 |
-
use_sample_chk = gr.Checkbox(
|
| 179 |
-
label="Load 'Sports Legends' Dataset",
|
| 180 |
-
info="Perfect for testing without your own files."
|
| 181 |
-
)
|
| 182 |
-
|
| 183 |
-
gr.Markdown("### Step 2: Build Index")
|
| 184 |
-
ingest_btn = gr.Button("π Ingest & Re-Index", variant="primary")
|
| 185 |
-
|
| 186 |
-
status_box = gr.Textbox(label="System Status", value="Ready.", interactive=False, lines=5)
|
| 187 |
-
|
| 188 |
-
ingest_btn.click(
|
| 189 |
-
admin_ingest,
|
| 190 |
-
inputs=[file_upload, use_sample_chk],
|
| 191 |
-
outputs=[status_box]
|
| 192 |
)
|
| 193 |
-
|
| 194 |
-
|
| 195 |
-
|
| 196 |
-
|
| 197 |
-
|
| 198 |
-
with gr.Accordion("βοΈ Model Settings", open=True):
|
| 199 |
-
backend_radio = gr.Radio(
|
| 200 |
-
choices=["openai", "gemini", "local"],
|
| 201 |
-
value="openai",
|
| 202 |
-
label="Select LLM Backend",
|
| 203 |
-
info="OpenAI/Gemini require API Keys. Local runs on ZeroGPU (slower cold start)."
|
| 204 |
-
)
|
| 205 |
-
|
| 206 |
-
chatbot = gr.ChatInterface(
|
| 207 |
-
fn=chat_fn,
|
| 208 |
-
additional_inputs=[backend_radio],
|
| 209 |
-
title="Chat with your Documents",
|
| 210 |
-
description="Ask questions about the content you indexed in the 'Knowledge Base' tab.",
|
| 211 |
-
examples=[
|
| 212 |
-
["Who is the greatest quarterback?", "openai"],
|
| 213 |
-
["Summary of Lionel Messi", "local"]
|
| 214 |
-
]
|
| 215 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
|
| 217 |
if __name__ == "__main__":
|
| 218 |
# specific server_name needed for Docker/Spaces
|
|
|
|
| 145 |
gr.Markdown("# π€ RAG Knowledge Assistant")
|
| 146 |
|
| 147 |
with gr.Row():
|
| 148 |
+
# Left Column: Sidebar (Controls & Guide)
|
| 149 |
+
with gr.Column(scale=1, variant="panel"):
|
| 150 |
+
gr.Markdown("### 1. Teach Me π")
|
| 151 |
+
gr.Markdown("Upload docs to build your brain.")
|
| 152 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
with gr.Tabs():
|
| 154 |
+
with gr.Tab("Upload"):
|
| 155 |
+
file_upload = gr.File(
|
| 156 |
+
label="Files (PDF/TXT)",
|
| 157 |
+
file_count="multiple",
|
| 158 |
+
file_types=[".pdf", ".txt", ".html"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 159 |
)
|
| 160 |
+
with gr.Tab("Sample"):
|
| 161 |
+
use_sample_chk = gr.Checkbox(
|
| 162 |
+
label="Load 'Sports Legends'",
|
| 163 |
+
info="Demo Data (Messi, Brady...)"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 164 |
)
|
| 165 |
+
|
| 166 |
+
ingest_btn = gr.Button("π Ingest", variant="primary")
|
| 167 |
+
status_box = gr.Textbox(label="Status", value="Ready.", interactive=False, lines=4, max_lines=4)
|
| 168 |
+
|
| 169 |
+
ingest_btn.click(
|
| 170 |
+
admin_ingest,
|
| 171 |
+
inputs=[file_upload, use_sample_chk],
|
| 172 |
+
outputs=[status_box]
|
| 173 |
+
)
|
| 174 |
+
|
| 175 |
+
gr.HTML("<hr>")
|
| 176 |
+
|
| 177 |
+
gr.Markdown("### 2. Configure βοΈ")
|
| 178 |
+
backend_radio = gr.Radio(
|
| 179 |
+
choices=["openai", "gemini", "local"],
|
| 180 |
+
value="openai",
|
| 181 |
+
label="Brain / Model",
|
| 182 |
+
info="Local = ZeroGPU (Slow Start)"
|
| 183 |
+
)
|
| 184 |
+
|
| 185 |
+
# Right Column: Main App (Chat)
|
| 186 |
+
with gr.Column(scale=4):
|
| 187 |
+
chatbot = gr.ChatInterface(
|
| 188 |
+
fn=chat_fn,
|
| 189 |
+
additional_inputs=[backend_radio],
|
| 190 |
+
title="π¬ Talk to Me",
|
| 191 |
+
description="I will answer based on the documents you taught me!",
|
| 192 |
+
examples=[
|
| 193 |
+
["Who is the greatest quarterback?", "openai"],
|
| 194 |
+
["Summary of Lionel Messi", "local"]
|
| 195 |
+
]
|
| 196 |
+
)
|
| 197 |
|
| 198 |
if __name__ == "__main__":
|
| 199 |
# specific server_name needed for Docker/Spaces
|