raktimhugging commited on
Commit
f3d6f52
Β·
verified Β·
1 Parent(s): c059189

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +98 -57
app.py CHANGED
@@ -297,11 +297,19 @@ css = """
297
  }
298
  """
299
 
300
- # Create the main chat interface - FIXED VERSION
301
- iface = gr.ChatInterface(
302
- fn=chat_interface,
303
  title="πŸ€– RAGtim Bot - Markdown Knowledge Base",
304
- description=f"""
 
 
 
 
 
 
 
 
 
305
  **Complete Markdown Knowledge Base**: This Hugging Face Space loads all markdown files from Raktim Mondol's portfolio with **{len(bot.knowledge_base)} knowledge sections**.
306
 
307
  **Loaded Markdown Files:**
@@ -333,66 +341,99 @@ iface = gr.ChatInterface(
333
  - Contact information and collaboration opportunities
334
 
335
  **Note**: This demo shows search results from the complete markdown knowledge base. In hybrid mode, these results are passed to DeepSeek LLM for natural response generation.
336
- """,
337
- examples=[
338
- "What is Raktim's research about?",
339
- "Tell me about BioFusionNet in detail",
340
- "What are his LLM and RAG expertise?",
341
- "Describe his statistical methods and biostatistics work",
342
- "What programming languages and frameworks does he use?",
343
- "Tell me about his educational background",
344
- "What is his current position at UNSW?",
345
- "How can I contact Raktim for collaboration?",
346
- "What awards and recognition has he received?",
347
- "Explain his multimodal AI research",
348
- "What is hist2RNA and its impact?",
349
- "Tell me about his teaching experience"
350
- ],
351
- css=css,
352
- theme=gr.themes.Soft(
353
- primary_hue="green",
354
- secondary_hue="blue",
355
- neutral_hue="slate"
356
- ),
357
- # FIXED: Use type='messages' and remove deprecated parameters
358
- type='messages',
359
- chatbot=gr.Chatbot(
360
  height=600,
361
  show_label=False,
362
- container=True
363
- ),
364
- textbox=gr.Textbox(
365
- placeholder="Ask me anything about Raktim Mondol's research, skills, experience, publications...",
366
- container=False,
367
- scale=7
368
- ),
369
- submit_btn="Search Knowledge Base"
370
- # REMOVED: retry_btn, undo_btn, clear_btn (deprecated in this version)
371
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
372
 
373
  # Create API interface for search-only functionality
374
- search_api = gr.Interface(
375
- fn=search_only_api,
376
- inputs=[
377
- gr.Textbox(label="Search Query", placeholder="Enter your search query about Raktim Mondol..."),
378
- gr.Slider(minimum=1, maximum=15, value=5, step=1, label="Top K Results")
379
- ],
380
- outputs=gr.JSON(label="Markdown Knowledge Base Search Results"),
381
- title="πŸ” Markdown Knowledge Base Search API",
382
- description="Direct access to semantic search across all loaded markdown files"
383
- )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
384
 
385
- stats_api = gr.Interface(
386
- fn=get_stats_api,
387
- inputs=[],
388
- outputs=gr.JSON(label="Markdown Knowledge Base Statistics"),
389
- title="πŸ“Š Knowledge Base Stats",
390
- description="Detailed statistics about the loaded markdown knowledge base"
391
- )
 
 
 
 
 
 
392
 
393
- # Combine interfaces
394
  demo = gr.TabbedInterface(
395
- [iface, search_api, stats_api],
396
  ["πŸ’¬ Markdown Chat", "πŸ” Search API", "πŸ“Š Stats API"],
397
  title="πŸ€– RAGtim Bot - Complete Markdown Knowledge Base"
398
  )
 
297
  }
298
  """
299
 
300
+ # Create the main chat interface - UPDATED FOR GRADIO 5.34.0
301
+ with gr.Blocks(
 
302
  title="πŸ€– RAGtim Bot - Markdown Knowledge Base",
303
+ css=css,
304
+ theme=gr.themes.Soft(
305
+ primary_hue="green",
306
+ secondary_hue="blue",
307
+ neutral_hue="slate"
308
+ )
309
+ ) as chat_demo:
310
+ gr.Markdown(f"""
311
+ # πŸ€– RAGtim Bot - Markdown Knowledge Base
312
+
313
  **Complete Markdown Knowledge Base**: This Hugging Face Space loads all markdown files from Raktim Mondol's portfolio with **{len(bot.knowledge_base)} knowledge sections**.
314
 
315
  **Loaded Markdown Files:**
 
341
  - Contact information and collaboration opportunities
342
 
343
  **Note**: This demo shows search results from the complete markdown knowledge base. In hybrid mode, these results are passed to DeepSeek LLM for natural response generation.
344
+ """)
345
+
346
+ chatbot = gr.Chatbot(
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
347
  height=600,
348
  show_label=False,
349
+ container=True,
350
+ type="messages"
351
+ )
352
+
353
+ with gr.Row():
354
+ msg = gr.Textbox(
355
+ placeholder="Ask me anything about Raktim Mondol's research, skills, experience, publications...",
356
+ container=False,
357
+ scale=7,
358
+ show_label=False
359
+ )
360
+ submit_btn = gr.Button("Search Knowledge Base", scale=1)
361
+
362
+ # Example buttons
363
+ with gr.Row():
364
+ examples = [
365
+ "What is Raktim's research about?",
366
+ "Tell me about BioFusionNet in detail",
367
+ "What are his LLM and RAG expertise?",
368
+ "Describe his statistical methods and biostatistics work"
369
+ ]
370
+ for example in examples:
371
+ gr.Button(example, size="sm").click(
372
+ lambda x=example: x, outputs=msg
373
+ )
374
+
375
+ def respond(message, history):
376
+ if not message.strip():
377
+ return history, ""
378
+
379
+ # Add user message to history
380
+ history.append({"role": "user", "content": message})
381
+
382
+ # Get bot response
383
+ bot_response = chat_interface(message, history)
384
+
385
+ # Add bot response to history
386
+ history.append({"role": "assistant", "content": bot_response})
387
+
388
+ return history, ""
389
+
390
+ submit_btn.click(respond, [msg, chatbot], [chatbot, msg])
391
+ msg.submit(respond, [msg, chatbot], [chatbot, msg])
392
 
393
  # Create API interface for search-only functionality
394
+ with gr.Blocks(title="πŸ” Search API") as search_demo:
395
+ gr.Markdown("# πŸ” Markdown Knowledge Base Search API")
396
+ gr.Markdown("Direct access to semantic search across all loaded markdown files")
397
+
398
+ with gr.Row():
399
+ search_input = gr.Textbox(
400
+ label="Search Query",
401
+ placeholder="Enter your search query about Raktim Mondol..."
402
+ )
403
+ top_k_slider = gr.Slider(
404
+ minimum=1,
405
+ maximum=15,
406
+ value=5,
407
+ step=1,
408
+ label="Top K Results"
409
+ )
410
+
411
+ search_output = gr.JSON(label="Markdown Knowledge Base Search Results")
412
+ search_btn = gr.Button("Search")
413
+
414
+ search_btn.click(
415
+ search_only_api,
416
+ inputs=[search_input, top_k_slider],
417
+ outputs=search_output
418
+ )
419
 
420
+ # Create stats interface
421
+ with gr.Blocks(title="πŸ“Š Stats API") as stats_demo:
422
+ gr.Markdown("# πŸ“Š Knowledge Base Stats")
423
+ gr.Markdown("Detailed statistics about the loaded markdown knowledge base")
424
+
425
+ stats_output = gr.JSON(label="Markdown Knowledge Base Statistics")
426
+ stats_btn = gr.Button("Get Statistics")
427
+
428
+ stats_btn.click(
429
+ get_stats_api,
430
+ inputs=[],
431
+ outputs=stats_output
432
+ )
433
 
434
+ # Combine interfaces using TabbedInterface
435
  demo = gr.TabbedInterface(
436
+ [chat_demo, search_demo, stats_demo],
437
  ["πŸ’¬ Markdown Chat", "πŸ” Search API", "πŸ“Š Stats API"],
438
  title="πŸ€– RAGtim Bot - Complete Markdown Knowledge Base"
439
  )