Dheeraj-13 commited on
Commit
8558835
Β·
1 Parent(s): 474f5b6

Refactor UI to Single Page Dashboard layout

Browse files
Files changed (1) hide show
  1. 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: Guide (Scale 1)
149
- with gr.Column(scale=1):
150
- gr.Markdown("### πŸ‘‹ Hi! I'm your AI Helper!")
151
- gr.Markdown("I can learn from **ANY** document you give me. Creating your own Google is easy as 1-2-3!")
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
- # Tab 1: Knowledge Base (Ingestion)
165
- with gr.Tab("1. Teach Me (Knowledge Base)"):
166
- gr.Markdown("### Step 1: Choose Your Data Source")
167
-
168
- with gr.Row():
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
- # Tab 2: Chat Interface
195
- with gr.Tab("2. Talk to Me (Chat)"):
196
- gr.Markdown("### Step 3: Ask Questions")
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