Shreyas094 commited on
Commit
ec6fc01
·
verified ·
1 Parent(s): aca394a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +57 -48
app.py CHANGED
@@ -267,11 +267,10 @@ class ChatBot:
267
  self.score_threshold = 0.8
268
  self.temperature = 0.1
269
  self.history = []
270
- self.base_url = "https://shreyas094-searxng-local.hf.space/search"
271
  self.headers = {
272
  "X-Searx-API-Key": "f9f07f93b37b8483aadb5ba717f556f3a4ac507b281b4ca01e6c6288aa3e3ae5"
273
  }
274
- # Default search engines in case we can't fetch from SearxNG
275
  self.default_engines = ["google", "bing", "duckduckgo", "brave"]
276
 
277
  async def get_search_results(self,
@@ -402,53 +401,63 @@ class ChatBot:
402
  def create_gradio_interface() -> gr.Interface:
403
  chatbot = ChatBot()
404
 
405
- with gr.Blocks(theme=gr.themes.Soft()) as demo:
406
- gr.Markdown("# Research Assistant")
407
- gr.Markdown("Enter your search query, and I'll search, analyze, and summarize relevant articles for you.")
408
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
409
  with gr.Row():
410
  with gr.Column(scale=3):
411
- chatbot_interface = gr.ChatInterface(
412
- fn=chatbot.chat,
413
- additional_inputs=[
414
- gr.Slider(minimum=5, maximum=30, value=10, step=1, label="Number of Results"),
415
- gr.Slider(minimum=1000, maximum=50000, value=10000, step=1000, label="Max Characters per Article"),
416
- gr.Slider(minimum=0.0, maximum=1.0, value=0.8, step=0.05, label="Score Threshold"),
417
- gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.05, label="Temperature"),
418
- gr.Radio(["BM25", "TF-IDF", "Combined"], value="Combined", label="Scoring Method"),
419
- gr.CheckboxGroup(
420
- choices=["google", "bing", "duckduckgo", "brave", "wikipedia"],
421
- value=["google", "bing", "duckduckgo"],
422
- label="Search Engines"
423
- )
424
- ],
425
- examples=[
426
- ["What are the latest developments in quantum computing?"],
427
- ["Explain the impact of artificial intelligence on healthcare"],
428
- ["What are the current trends in renewable energy?"]
429
- ]
430
- )
431
-
432
  with gr.Column(scale=1):
433
- gr.Markdown("### Parameter Descriptions")
434
- gr.Markdown("""
435
- - **Number of Results**: Number of search results to fetch
436
- - **Max Characters**: Maximum characters to analyze per article
437
- - **Score Threshold**: Minimum relevance score (0-1) for including articles
438
- - **Temperature**: Controls creativity in summary generation (0=focused, 1=creative)
439
- - **Scoring Method**: Algorithm for ranking article relevance
440
- - BM25: Traditional keyword-based ranking
441
- - TF-IDF: Semantic similarity-based ranking
442
- - Combined: Balanced approach using both methods
443
- - **Search Engines**: Select which search engines to use
444
- """)
445
-
446
- return demo
447
-
448
- if __name__ == "__main__":
449
- # Configure logging
450
- logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s: %(message)s')
451
 
452
- # Create and launch the interface
453
- demo = create_gradio_interface()
454
- demo.launch(share=True)
 
267
  self.score_threshold = 0.8
268
  self.temperature = 0.1
269
  self.history = []
270
+ self.base_url = "http://localhost:8888"
271
  self.headers = {
272
  "X-Searx-API-Key": "f9f07f93b37b8483aadb5ba717f556f3a4ac507b281b4ca01e6c6288aa3e3ae5"
273
  }
 
274
  self.default_engines = ["google", "bing", "duckduckgo", "brave"]
275
 
276
  async def get_search_results(self,
 
401
  def create_gradio_interface() -> gr.Interface:
402
  chatbot = ChatBot()
403
 
404
+ # Create the interface with advanced styling
405
+ iface = gr.ChatInterface(
406
+ chatbot.chat,
407
+ title="Web Scraper for News with Sentinel AI",
408
+ description="Ask Sentinel any question. It will search the web for recent information or use its knowledge base as appropriate.",
409
+ theme=gr.Theme.from_hub("allenai/gradio-theme"),
410
+ additional_inputs=[
411
+ gr.Slider(minimum=5, maximum=30, value=10, step=1, label="Number of Results"),
412
+ gr.Slider(minimum=1000, maximum=50000, value=10000, step=1000, label="Max Characters per Article"),
413
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.8, step=0.05, label="Score Threshold"),
414
+ gr.Slider(minimum=0.0, maximum=1.0, value=0.1, step=0.05, label="Temperature"),
415
+ gr.Radio(["BM25", "TF-IDF", "Combined"], value="Combined", label="Scoring Method"),
416
+ gr.CheckboxGroup(
417
+ choices=["google", "bing", "duckduckgo", "brave", "wikipedia"],
418
+ value=["google", "bing", "duckduckgo"],
419
+ label="Search Engines"
420
+ )
421
+ ],
422
+ additional_inputs_accordion=gr.Accordion("⚙️ Advanced Parameters", open=True),
423
+ retry_btn="Retry",
424
+ undo_btn="Undo",
425
+ clear_btn="Clear",
426
+ chatbot=gr.Chatbot(
427
+ show_copy_button=True,
428
+ likeable=True,
429
+ layout="bubble",
430
+ height=500,
431
+ )
432
+ )
433
+
434
+ return iface
435
+
436
+ def create_parameter_description():
437
+ return """
438
+ ### Parameter Descriptions
439
+
440
+ - **Number of Results**: Number of search results to fetch
441
+ - **Max Characters**: Maximum characters to analyze per article
442
+ - **Score Threshold**: Minimum relevance score (0-1) for including articles
443
+ - **Temperature**: Controls creativity in summary generation (0=focused, 1=creative)
444
+ - **Scoring Method**: Algorithm for ranking article relevance
445
+ - BM25: Traditional keyword-based ranking
446
+ - TF-IDF: Semantic similarity-based ranking
447
+ - Combined: Balanced approach using both methods
448
+ - **Search Engines**: Select which search engines to use
449
+ """
450
+
451
+ if __name__ == "__main__":
452
+ iface = create_gradio_interface()
453
+
454
+ # Create the layout with two columns
455
+ with gr.Blocks(theme=gr.Theme.from_hub("allenai/gradio-theme")) as demo:
456
  with gr.Row():
457
  with gr.Column(scale=3):
458
+ iface.render()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
459
  with gr.Column(scale=1):
460
+ gr.Markdown(create_parameter_description())
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
461
 
462
+ # Launch the interface
463
+ demo.launch(server_name="0.0.0.0", server_port=7862, share=True)