Add Gradio web interface for the intelligent research system
This commit is contained in:
parent
540bf22b52
commit
bdc3a8fe60
|
@ -33,6 +33,13 @@ We are currently developing an intelligent research system that automates the pr
|
||||||
- Improved result processing and deduplication
|
- Improved result processing and deduplication
|
||||||
- Created comprehensive test scripts for all search handlers
|
- Created comprehensive test scripts for all search handlers
|
||||||
|
|
||||||
|
5. **UI Development**:
|
||||||
|
- Created a Gradio web interface for the research system
|
||||||
|
- Implemented query input and result display components
|
||||||
|
- Added support for configuring the number of results
|
||||||
|
- Included example queries for easy testing
|
||||||
|
- Created a results directory for saving search results
|
||||||
|
|
||||||
### Current Tasks
|
### Current Tasks
|
||||||
|
|
||||||
1. **Report Generation Module Development**:
|
1. **Report Generation Module Development**:
|
||||||
|
@ -40,10 +47,10 @@ We are currently developing an intelligent research system that automates the pr
|
||||||
- Implementing result summarization using Groq's Llama 3.3 70B Versatile model
|
- Implementing result summarization using Groq's Llama 3.3 70B Versatile model
|
||||||
- Creating formatting and export options
|
- Creating formatting and export options
|
||||||
|
|
||||||
2. **Gradio UI Development**:
|
2. **UI Enhancement**:
|
||||||
- Designing the user interface for query input
|
- Adding more configuration options to the UI
|
||||||
- Implementing result display components
|
- Implementing report generation in the UI
|
||||||
- Creating configuration options in the UI
|
- Creating visualization components for search results
|
||||||
|
|
||||||
### Next Steps
|
### Next Steps
|
||||||
|
|
||||||
|
@ -69,3 +76,4 @@ We are currently developing an intelligent research system that automates the pr
|
||||||
- Using Jina AI's reranker for improved document ranking
|
- Using Jina AI's reranker for improved document ranking
|
||||||
- Using Groq's Llama 3.1 and 3.3 models for fast inference during testing
|
- Using Groq's Llama 3.1 and 3.3 models for fast inference during testing
|
||||||
- Managing API keys securely through environment variables and configuration files
|
- Managing API keys securely through environment variables and configuration files
|
||||||
|
- Using Gradio for the web interface to provide an easy-to-use frontend
|
||||||
|
|
|
@ -535,6 +535,74 @@ save_test_results(results, "search_execution_test_results.json")
|
||||||
- Saves results to a JSON file
|
- Saves results to a JSON file
|
||||||
- Provides detailed output of search results
|
- Provides detailed output of search results
|
||||||
|
|
||||||
|
## UI Module
|
||||||
|
|
||||||
|
### GradioInterface Class
|
||||||
|
|
||||||
|
#### Initialization
|
||||||
|
```python
|
||||||
|
from ui.gradio_interface import GradioInterface
|
||||||
|
interface = GradioInterface()
|
||||||
|
```
|
||||||
|
- **Description**: Initializes the Gradio interface for the research system
|
||||||
|
- **Requirements**: Gradio library installed
|
||||||
|
|
||||||
|
#### process_query
|
||||||
|
```python
|
||||||
|
markdown_results, results_file = interface.process_query(query, num_results=10)
|
||||||
|
```
|
||||||
|
- **Description**: Processes a query and returns the results
|
||||||
|
- **Parameters**:
|
||||||
|
- `query` (str): The query to process
|
||||||
|
- `num_results` (int): Number of results to return
|
||||||
|
- **Returns**:
|
||||||
|
- `markdown_results` (str): Markdown formatted results
|
||||||
|
- `results_file` (str): Path to the JSON file with saved results
|
||||||
|
- **Example**:
|
||||||
|
```python
|
||||||
|
results, file_path = interface.process_query("What are the latest advancements in quantum computing?", num_results=15)
|
||||||
|
```
|
||||||
|
|
||||||
|
#### create_interface
|
||||||
|
```python
|
||||||
|
interface_blocks = interface.create_interface()
|
||||||
|
```
|
||||||
|
- **Description**: Creates and returns the Gradio interface
|
||||||
|
- **Returns**: `gr.Blocks` - The Gradio interface object
|
||||||
|
- **Example**:
|
||||||
|
```python
|
||||||
|
blocks = interface.create_interface()
|
||||||
|
blocks.launch()
|
||||||
|
```
|
||||||
|
|
||||||
|
#### launch
|
||||||
|
```python
|
||||||
|
interface.launch(share=True, server_port=7860, debug=False)
|
||||||
|
```
|
||||||
|
- **Description**: Launches the Gradio interface
|
||||||
|
- **Parameters**:
|
||||||
|
- `share` (bool): Whether to create a public link for sharing
|
||||||
|
- `server_port` (int): Port to run the server on
|
||||||
|
- `debug` (bool): Whether to run in debug mode
|
||||||
|
- **Example**:
|
||||||
|
```python
|
||||||
|
interface.launch(share=True)
|
||||||
|
```
|
||||||
|
|
||||||
|
### Running the UI
|
||||||
|
```bash
|
||||||
|
python run_ui.py --share --port 7860
|
||||||
|
```
|
||||||
|
- **Description**: Runs the Gradio interface
|
||||||
|
- **Parameters**:
|
||||||
|
- `--share`: Create a public link for sharing
|
||||||
|
- `--port`: Port to run the server on (default: 7860)
|
||||||
|
- `--debug`: Run in debug mode
|
||||||
|
- **Example**:
|
||||||
|
```bash
|
||||||
|
python run_ui.py --share
|
||||||
|
```
|
||||||
|
|
||||||
## Document Ranking Interface
|
## Document Ranking Interface
|
||||||
|
|
||||||
### JinaReranker
|
### JinaReranker
|
||||||
|
|
|
@ -348,3 +348,48 @@ Fixed Serper API integration in the search execution module, ensuring proper fun
|
||||||
2. Implement the report generation module
|
2. Implement the report generation module
|
||||||
3. Develop the Gradio UI for user interaction
|
3. Develop the Gradio UI for user interaction
|
||||||
4. Test the complete pipeline from query to report
|
4. Test the complete pipeline from query to report
|
||||||
|
|
||||||
|
## Session: 2025-02-27 - Gradio UI Implementation
|
||||||
|
|
||||||
|
### Overview
|
||||||
|
Implemented a Gradio web interface for the intelligent research system, providing users with an intuitive way to interact with the system.
|
||||||
|
|
||||||
|
### Key Activities
|
||||||
|
1. Created the Gradio interface:
|
||||||
|
- Implemented a clean and user-friendly UI design
|
||||||
|
- Added query input with configurable number of results
|
||||||
|
- Created a markdown-based result display
|
||||||
|
- Included example queries for easy testing
|
||||||
|
|
||||||
|
2. Integrated with existing modules:
|
||||||
|
- Connected the UI to the query processor
|
||||||
|
- Integrated with the search executor
|
||||||
|
- Used the result collector for processing search results
|
||||||
|
- Added functionality to save results to JSON files
|
||||||
|
|
||||||
|
3. Added project management files:
|
||||||
|
- Created a comprehensive README.md with project overview and usage instructions
|
||||||
|
- Set up a git repository with proper .gitignore
|
||||||
|
- Made an initial commit with all project files
|
||||||
|
|
||||||
|
4. Updated documentation:
|
||||||
|
- Added UI module interfaces to interfaces.md
|
||||||
|
- Updated current_focus.md with UI development progress
|
||||||
|
- Added session log entry for UI implementation
|
||||||
|
|
||||||
|
### Insights
|
||||||
|
- Gradio provides a simple yet powerful way to create web interfaces for ML/AI systems
|
||||||
|
- The modular architecture of our system made UI integration straightforward
|
||||||
|
- Markdown formatting provides a clean way to display search results
|
||||||
|
- Saving results to files allows for easier debugging and analysis
|
||||||
|
|
||||||
|
### Challenges
|
||||||
|
- Ensuring a good user experience with potentially slow API calls
|
||||||
|
- Formatting different types of search results consistently
|
||||||
|
- Balancing simplicity and functionality in the UI
|
||||||
|
|
||||||
|
### Next Steps
|
||||||
|
1. Enhance the UI with more configuration options
|
||||||
|
2. Implement report generation in the UI
|
||||||
|
3. Add visualization components for search results
|
||||||
|
4. Test the UI with various query types and search engines
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
After each major successful test, please commit the changes to the repository with a meaningful commit message.
|
|
@ -0,0 +1,49 @@
|
||||||
|
#!/usr/bin/env python3
|
||||||
|
"""
|
||||||
|
Run script for the Intelligent Research System UI.
|
||||||
|
This script launches the Gradio interface for the research system.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
from ui.gradio_interface import GradioInterface
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args():
|
||||||
|
"""Parse command line arguments."""
|
||||||
|
parser = argparse.ArgumentParser(description="Run the Intelligent Research System UI")
|
||||||
|
parser.add_argument(
|
||||||
|
"--share",
|
||||||
|
action="store_true",
|
||||||
|
help="Create a public link for sharing"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--port",
|
||||||
|
type=int,
|
||||||
|
default=7860,
|
||||||
|
help="Port to run the server on"
|
||||||
|
)
|
||||||
|
parser.add_argument(
|
||||||
|
"--debug",
|
||||||
|
action="store_true",
|
||||||
|
help="Run in debug mode"
|
||||||
|
)
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main function to run the UI."""
|
||||||
|
args = parse_args()
|
||||||
|
|
||||||
|
print("Starting Intelligent Research System UI...")
|
||||||
|
interface = GradioInterface()
|
||||||
|
|
||||||
|
# Launch with the specified arguments
|
||||||
|
interface.launch(
|
||||||
|
share=args.share,
|
||||||
|
server_port=args.port,
|
||||||
|
debug=args.debug
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
|
@ -0,0 +1,200 @@
|
||||||
|
"""
|
||||||
|
Gradio interface for the intelligent research system.
|
||||||
|
This module provides a web interface for users to interact with the research system.
|
||||||
|
"""
|
||||||
|
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import gradio as gr
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
|
# Add the parent directory to the path to allow importing from other modules
|
||||||
|
sys.path.append(str(Path(__file__).parent.parent))
|
||||||
|
|
||||||
|
from query.query_processor import QueryProcessor
|
||||||
|
from execution.search_executor import SearchExecutor
|
||||||
|
from execution.result_collector import ResultCollector
|
||||||
|
|
||||||
|
|
||||||
|
class GradioInterface:
|
||||||
|
"""Gradio interface for the intelligent research system."""
|
||||||
|
|
||||||
|
def __init__(self):
|
||||||
|
"""Initialize the Gradio interface."""
|
||||||
|
self.query_processor = QueryProcessor()
|
||||||
|
self.search_executor = SearchExecutor()
|
||||||
|
self.result_collector = ResultCollector()
|
||||||
|
self.results_dir = Path(__file__).parent.parent / "results"
|
||||||
|
self.results_dir.mkdir(exist_ok=True)
|
||||||
|
|
||||||
|
def process_query(self, query, num_results=10):
|
||||||
|
"""
|
||||||
|
Process a query and return the results.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
query (str): The query to process
|
||||||
|
num_results (int): Number of results to return
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
tuple: (markdown_results, json_results_path)
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Process the query
|
||||||
|
processed_query = self.query_processor.process_query(query)
|
||||||
|
|
||||||
|
# Execute the search
|
||||||
|
search_results = self.search_executor.execute_search(processed_query)
|
||||||
|
|
||||||
|
# Process the results
|
||||||
|
processed_results = self.result_collector.process_results(
|
||||||
|
search_results, dedup=True, max_results=num_results
|
||||||
|
)
|
||||||
|
|
||||||
|
# Save results to file
|
||||||
|
timestamp = int(time.time())
|
||||||
|
results_file = self.results_dir / f"results_{timestamp}.json"
|
||||||
|
with open(results_file, "w") as f:
|
||||||
|
json.dump(processed_results, f, indent=2)
|
||||||
|
|
||||||
|
# Format results for display
|
||||||
|
markdown_results = self._format_results_as_markdown(processed_results)
|
||||||
|
|
||||||
|
return markdown_results, str(results_file)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
error_message = f"Error processing query: {str(e)}"
|
||||||
|
return f"## Error\n\n{error_message}", None
|
||||||
|
|
||||||
|
def _format_results_as_markdown(self, results):
|
||||||
|
"""
|
||||||
|
Format search results as markdown.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
results (list): List of search result dictionaries
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
str: Markdown formatted results
|
||||||
|
"""
|
||||||
|
if not results:
|
||||||
|
return "## No results found"
|
||||||
|
|
||||||
|
markdown = "## Search Results\n\n"
|
||||||
|
|
||||||
|
for i, result in enumerate(results):
|
||||||
|
title = result.get("title", "No title")
|
||||||
|
url = result.get("url", "#")
|
||||||
|
snippet = result.get("snippet", "No snippet available")
|
||||||
|
source = result.get("source", "unknown")
|
||||||
|
|
||||||
|
markdown += f"### {i+1}. {title}\n\n"
|
||||||
|
markdown += f"**Source**: {source}\n\n"
|
||||||
|
markdown += f"**URL**: [{url}]({url})\n\n"
|
||||||
|
markdown += f"**Snippet**: {snippet}\n\n"
|
||||||
|
|
||||||
|
# Add additional fields based on source
|
||||||
|
if source == "scholar" or source == "arxiv":
|
||||||
|
authors = result.get("authors", "Unknown")
|
||||||
|
if isinstance(authors, list):
|
||||||
|
authors = ", ".join(authors)
|
||||||
|
year = result.get("year", "Unknown")
|
||||||
|
markdown += f"**Authors**: {authors}\n\n"
|
||||||
|
markdown += f"**Year**: {year}\n\n"
|
||||||
|
|
||||||
|
if source == "arxiv":
|
||||||
|
categories = result.get("categories", [])
|
||||||
|
if categories:
|
||||||
|
markdown += f"**Categories**: {', '.join(categories)}\n\n"
|
||||||
|
|
||||||
|
pdf_url = result.get("pdf_url", "")
|
||||||
|
if pdf_url:
|
||||||
|
markdown += f"**PDF**: [{pdf_url}]({pdf_url})\n\n"
|
||||||
|
|
||||||
|
markdown += "---\n\n"
|
||||||
|
|
||||||
|
return markdown
|
||||||
|
|
||||||
|
def create_interface(self):
|
||||||
|
"""
|
||||||
|
Create and return the Gradio interface.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
gr.Blocks: The Gradio interface
|
||||||
|
"""
|
||||||
|
with gr.Blocks(title="Intelligent Research System") as interface:
|
||||||
|
gr.Markdown("# Intelligent Research System")
|
||||||
|
gr.Markdown(
|
||||||
|
"""
|
||||||
|
This system helps you research topics by searching across multiple sources
|
||||||
|
including Google (via Serper), Google Scholar, and arXiv.
|
||||||
|
"""
|
||||||
|
)
|
||||||
|
|
||||||
|
with gr.Row():
|
||||||
|
with gr.Column(scale=4):
|
||||||
|
query_input = gr.Textbox(
|
||||||
|
label="Research Query",
|
||||||
|
placeholder="Enter your research question here...",
|
||||||
|
lines=3
|
||||||
|
)
|
||||||
|
with gr.Column(scale=1):
|
||||||
|
num_results = gr.Slider(
|
||||||
|
minimum=5,
|
||||||
|
maximum=30,
|
||||||
|
value=10,
|
||||||
|
step=5,
|
||||||
|
label="Number of Results"
|
||||||
|
)
|
||||||
|
search_button = gr.Button("Search", variant="primary")
|
||||||
|
|
||||||
|
with gr.Row():
|
||||||
|
with gr.Column():
|
||||||
|
results_output = gr.Markdown(label="Results")
|
||||||
|
|
||||||
|
with gr.Row():
|
||||||
|
with gr.Column():
|
||||||
|
file_output = gr.Textbox(
|
||||||
|
label="Results saved to file",
|
||||||
|
interactive=False
|
||||||
|
)
|
||||||
|
|
||||||
|
search_button.click(
|
||||||
|
fn=self.process_query,
|
||||||
|
inputs=[query_input, num_results],
|
||||||
|
outputs=[results_output, file_output]
|
||||||
|
)
|
||||||
|
|
||||||
|
# Examples
|
||||||
|
gr.Examples(
|
||||||
|
[
|
||||||
|
["What are the latest advancements in quantum computing?"],
|
||||||
|
["Compare transformer and RNN architectures for NLP tasks"],
|
||||||
|
["Explain the environmental impact of electric vehicles"],
|
||||||
|
["What are the most effective treatments for depression?"],
|
||||||
|
["How does climate change affect biodiversity?"]
|
||||||
|
],
|
||||||
|
inputs=[query_input]
|
||||||
|
)
|
||||||
|
|
||||||
|
return interface
|
||||||
|
|
||||||
|
def launch(self, **kwargs):
|
||||||
|
"""
|
||||||
|
Launch the Gradio interface.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
**kwargs: Keyword arguments to pass to gr.Interface.launch()
|
||||||
|
"""
|
||||||
|
interface = self.create_interface()
|
||||||
|
interface.launch(**kwargs)
|
||||||
|
|
||||||
|
|
||||||
|
def main():
|
||||||
|
"""Main function to launch the Gradio interface."""
|
||||||
|
interface = GradioInterface()
|
||||||
|
interface.launch(share=True)
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
Loading…
Reference in New Issue