Update app.py
Browse files
app.py
CHANGED
|
@@ -214,21 +214,123 @@ def ask_agent_ui(question):
|
|
| 214 |
# -----------------------------
|
| 215 |
# Gradio UI
|
| 216 |
# -----------------------------
|
| 217 |
-
with gr.Blocks(title="# π Dox the Data Professional's Advisor π€", theme=gr.themes.Ocean()) as demo:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 218 |
gr.Markdown("# π Dox the Data Professional's Advisor π€")
|
| 219 |
gr.Markdown("π§ Dox knows about 4 DataCamp cheat sheets: (1οΈβ£ Hugging Face | 2οΈβ£ AI Agents | 3οΈβ£ SQL with AI | 4οΈβ£ Azure CLI):")
|
| 220 |
-
|
| 221 |
-
# Create two columns for better layout
|
| 222 |
with gr.Row():
|
|
|
|
|
|
|
| 223 |
with gr.Column(scale=3):
|
|
|
|
|
|
|
|
|
|
| 224 |
question = gr.Textbox(
|
| 225 |
label="Ask Dox a question:",
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
placeholder="π€ Type your question here..."
|
| 229 |
)
|
| 230 |
-
|
| 231 |
-
|
|
|
|
| 232 |
gr.Markdown("### π‘ Example Questions")
|
| 233 |
gr.Examples(
|
| 234 |
examples=[
|
|
@@ -238,65 +340,54 @@ with gr.Blocks(title="# π Dox the Data Professional's Advisor π€", theme=gr
|
|
| 238 |
"What SQL clause is used to filter data after grouping?"
|
| 239 |
],
|
| 240 |
inputs=question,
|
| 241 |
-
label="Example Questions"
|
| 242 |
-
)
|
| 243 |
-
|
| 244 |
-
ask_btn = gr.Button("Submit π€", variant="primary")
|
| 245 |
-
# Define CSS to hide the horizontal scrollbar
|
| 246 |
-
css = """
|
| 247 |
-
.hide-scrollbar {
|
| 248 |
-
overflow-x: hidden !important;
|
| 249 |
-
}
|
| 250 |
-
"""
|
| 251 |
-
gr.Markdown("### β
Answer: ")
|
| 252 |
-
answer = gr.Markdown(
|
| 253 |
-
label="β
Answer: ",
|
| 254 |
-
render=True,
|
| 255 |
-
#container=True,
|
| 256 |
-
buttons=['copy'],
|
| 257 |
-
min_height=200#,
|
| 258 |
-
#elem_id="answer_markdown",
|
| 259 |
-
#elem_id="hide-scrollbar"
|
| 260 |
)
|
| 261 |
|
| 262 |
-
#
|
| 263 |
with gr.Column(scale=2):
|
| 264 |
-
|
|
|
|
|
|
|
| 265 |
link_state = gr.State()
|
| 266 |
-
|
| 267 |
-
output_image = gr.Image(
|
| 268 |
-
|
| 269 |
-
|
| 270 |
-
|
| 271 |
-
|
| 272 |
-
|
| 273 |
-
|
| 274 |
-
|
| 275 |
-
|
| 276 |
-
|
| 277 |
-
|
| 278 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 279 |
ask_btn.click(
|
| 280 |
-
|
| 281 |
-
inputs=question,
|
| 282 |
-
outputs=[
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 283 |
).then(
|
| 284 |
-
# Show PDF functionality
|
| 285 |
display_pdf,
|
| 286 |
inputs=link_state,
|
| 287 |
outputs=output_image
|
| 288 |
)
|
| 289 |
-
|
| 290 |
-
# # Show PDF functionality
|
| 291 |
-
# show_btn.click(
|
| 292 |
-
# display_pdf,
|
| 293 |
-
# inputs=link_state,
|
| 294 |
-
# outputs=output_image
|
| 295 |
-
# ).then(
|
| 296 |
-
# lambda: gr.update(visible=True),
|
| 297 |
-
# None,
|
| 298 |
-
# output_image
|
| 299 |
-
# )
|
| 300 |
|
| 301 |
if __name__ == "__main__":
|
| 302 |
demo.launch()
|
|
|
|
| 214 |
# -----------------------------
|
| 215 |
# Gradio UI
|
| 216 |
# -----------------------------
|
| 217 |
+
# with gr.Blocks(title="# π Dox the Data Professional's Advisor π€", theme=gr.themes.Ocean()) as demo:
|
| 218 |
+
# gr.Markdown("# π Dox the Data Professional's Advisor π€")
|
| 219 |
+
# gr.Markdown("π§ Dox knows about 4 DataCamp cheat sheets: (1οΈβ£ Hugging Face | 2οΈβ£ AI Agents | 3οΈβ£ SQL with AI | 4οΈβ£ Azure CLI):")
|
| 220 |
+
|
| 221 |
+
# # Create two columns for better layout
|
| 222 |
+
# with gr.Row():
|
| 223 |
+
# with gr.Column(scale=3):
|
| 224 |
+
# question = gr.Textbox(
|
| 225 |
+
# label="Ask Dox a question:",
|
| 226 |
+
# lines=2,
|
| 227 |
+
# scale=9,
|
| 228 |
+
# placeholder="π€ Type your question here..."
|
| 229 |
+
# )
|
| 230 |
+
|
| 231 |
+
# # Examples section
|
| 232 |
+
# gr.Markdown("### π‘ Example Questions")
|
| 233 |
+
# gr.Examples(
|
| 234 |
+
# examples=[
|
| 235 |
+
# "How do you log into Azure using device code authentication?",
|
| 236 |
+
# "What are the three main components of an AI agent?",
|
| 237 |
+
# "What are the \"core four\" Hugging Face libraries?",
|
| 238 |
+
# "What SQL clause is used to filter data after grouping?"
|
| 239 |
+
# ],
|
| 240 |
+
# inputs=question,
|
| 241 |
+
# label="Example Questions"
|
| 242 |
+
# )
|
| 243 |
+
|
| 244 |
+
# ask_btn = gr.Button("Submit π€", variant="primary")
|
| 245 |
+
# # Define CSS to hide the horizontal scrollbar
|
| 246 |
+
# css = """
|
| 247 |
+
# .hide-scrollbar {
|
| 248 |
+
# overflow-x: hidden !important;
|
| 249 |
+
# }
|
| 250 |
+
# """
|
| 251 |
+
# gr.Markdown("### β
Answer: ")
|
| 252 |
+
# answer = gr.Markdown(
|
| 253 |
+
# label="β
Answer: ",
|
| 254 |
+
# render=True,
|
| 255 |
+
# #container=True,
|
| 256 |
+
# buttons=['copy'],
|
| 257 |
+
# min_height=200#,
|
| 258 |
+
# #elem_id="answer_markdown",
|
| 259 |
+
# #elem_id="hide-scrollbar"
|
| 260 |
+
# )
|
| 261 |
+
|
| 262 |
+
# # PDF preview column (Output)
|
| 263 |
+
# with gr.Column(scale=2):
|
| 264 |
+
# markdown = gr.Markdown("### π Referenced PDF Document will show here: ‡οΈ")
|
| 265 |
+
# link_state = gr.State()
|
| 266 |
+
# show_btn = gr.Button("Show PDF π", visible=False, variant="secondary")
|
| 267 |
+
# output_image = gr.Image(label="PDF Preview (Page 1)", visible=False)
|
| 268 |
+
|
| 269 |
+
# gr.Markdown("""
|
| 270 |
+
# ---
|
| 271 |
+
# ### π Tips:
|
| 272 |
+
# - **PDFs automatically appear** when I cite them
|
| 273 |
+
# - I prioritize my knowledge base then search the web
|
| 274 |
+
# - Citations include direct links to sources
|
| 275 |
+
# - Keep questions data/tech related
|
| 276 |
+
# """, visible=False)
|
| 277 |
+
|
| 278 |
+
# # Ask agent functionality
|
| 279 |
+
# ask_btn.click(
|
| 280 |
+
# ask_agent_ui,
|
| 281 |
+
# inputs=question,
|
| 282 |
+
# outputs=[answer, link_state, output_image]
|
| 283 |
+
# ).then(
|
| 284 |
+
# # Show PDF functionality
|
| 285 |
+
# display_pdf,
|
| 286 |
+
# inputs=link_state,
|
| 287 |
+
# outputs=output_image
|
| 288 |
+
# )
|
| 289 |
+
|
| 290 |
+
# # # Show PDF functionality
|
| 291 |
+
# # show_btn.click(
|
| 292 |
+
# # display_pdf,
|
| 293 |
+
# # inputs=link_state,
|
| 294 |
+
# # outputs=output_image
|
| 295 |
+
# # ).then(
|
| 296 |
+
# # lambda: gr.update(visible=True),
|
| 297 |
+
# # None,
|
| 298 |
+
# # output_image
|
| 299 |
+
# # )
|
| 300 |
+
|
| 301 |
+
# if __name__ == "__main__":
|
| 302 |
+
# demo.launch()
|
| 303 |
+
|
| 304 |
+
# -----------------------------
|
| 305 |
+
# Gradio UI (Improved)
|
| 306 |
+
# -----------------------------
|
| 307 |
+
with gr.Blocks(
|
| 308 |
+
title="# π Dox the Data Professional's Advisor π€",
|
| 309 |
+
theme=gr.themes.Ocean(),
|
| 310 |
+
css="""
|
| 311 |
+
.container { max-width: 1200px; margin: auto; }
|
| 312 |
+
.chatbot { height: 450px; overflow: auto; }
|
| 313 |
+
"""
|
| 314 |
+
) as demo:
|
| 315 |
+
|
| 316 |
gr.Markdown("# π Dox the Data Professional's Advisor π€")
|
| 317 |
gr.Markdown("π§ Dox knows about 4 DataCamp cheat sheets: (1οΈβ£ Hugging Face | 2οΈβ£ AI Agents | 3οΈβ£ SQL with AI | 4οΈβ£ Azure CLI):")
|
| 318 |
+
|
|
|
|
| 319 |
with gr.Row():
|
| 320 |
+
|
| 321 |
+
# LEFT SIDE (CHAT)
|
| 322 |
with gr.Column(scale=3):
|
| 323 |
+
|
| 324 |
+
chatbot = gr.Chatbot(label="π¬ Conversation", elem_classes="chatbot")
|
| 325 |
+
|
| 326 |
question = gr.Textbox(
|
| 327 |
label="Ask Dox a question:",
|
| 328 |
+
placeholder="π€ Type your question here...",
|
| 329 |
+
lines=2
|
|
|
|
| 330 |
)
|
| 331 |
+
|
| 332 |
+
ask_btn = gr.Button("Submit π€", variant="primary")
|
| 333 |
+
|
| 334 |
gr.Markdown("### π‘ Example Questions")
|
| 335 |
gr.Examples(
|
| 336 |
examples=[
|
|
|
|
| 340 |
"What SQL clause is used to filter data after grouping?"
|
| 341 |
],
|
| 342 |
inputs=question,
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 343 |
)
|
| 344 |
|
| 345 |
+
# RIGHT SIDE (PDF PREVIEW)
|
| 346 |
with gr.Column(scale=2):
|
| 347 |
+
|
| 348 |
+
gr.Markdown("### π Referenced PDF Document")
|
| 349 |
+
|
| 350 |
link_state = gr.State()
|
| 351 |
+
|
| 352 |
+
output_image = gr.Image(
|
| 353 |
+
label="Preview (Page 1)",
|
| 354 |
+
visible=False
|
| 355 |
+
)
|
| 356 |
+
|
| 357 |
+
# -----------------------------
|
| 358 |
+
# Chat Logic
|
| 359 |
+
# -----------------------------
|
| 360 |
+
def chat_ui(user_message, chat_history):
|
| 361 |
+
response_text, link = ask_agent(user_message)
|
| 362 |
+
|
| 363 |
+
chat_history = chat_history + [[user_message, response_text]]
|
| 364 |
+
|
| 365 |
+
return (
|
| 366 |
+
chat_history,
|
| 367 |
+
link,
|
| 368 |
+
gr.update(value=None, visible=False)
|
| 369 |
+
)
|
| 370 |
+
|
| 371 |
ask_btn.click(
|
| 372 |
+
chat_ui,
|
| 373 |
+
inputs=[question, chatbot],
|
| 374 |
+
outputs=[chatbot, link_state, output_image]
|
| 375 |
+
).then(
|
| 376 |
+
display_pdf,
|
| 377 |
+
inputs=link_state,
|
| 378 |
+
outputs=output_image
|
| 379 |
+
)
|
| 380 |
+
|
| 381 |
+
# Enter key submit
|
| 382 |
+
question.submit(
|
| 383 |
+
chat_ui,
|
| 384 |
+
inputs=[question, chatbot],
|
| 385 |
+
outputs=[chatbot, link_state, output_image]
|
| 386 |
).then(
|
|
|
|
| 387 |
display_pdf,
|
| 388 |
inputs=link_state,
|
| 389 |
outputs=output_image
|
| 390 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 391 |
|
| 392 |
if __name__ == "__main__":
|
| 393 |
demo.launch()
|