Update app.py
Browse files
app.py
CHANGED
@@ -1,11 +1,12 @@
|
|
1 |
"""
|
2 |
This file is the main file for the hackathon.
|
3 |
-
It contains the Gradio interface for the hackathon as
|
4 |
It exposes the following tools:
|
5 |
- search_knowledge_base_for_context
|
6 |
- research_write_review_topic
|
7 |
-
|
8 |
"""
|
|
|
|
|
9 |
from dotenv import load_dotenv
|
10 |
load_dotenv() # Load environment variables from .env file
|
11 |
|
@@ -21,12 +22,11 @@ logging.basicConfig(
|
|
21 |
logger = logging.getLogger(__name__)
|
22 |
|
23 |
import gradio as gr
|
24 |
-
|
25 |
-
from tools.multi_agent_workflow_for_research import run_research_workflow
|
26 |
|
27 |
def search_knowledge_base_for_context(query: str) -> str:
|
28 |
"""
|
29 |
-
Searches and retrieves relevant context from a knowledge base
|
30 |
based on the user's query.
|
31 |
|
32 |
Example queries:
|
@@ -39,10 +39,16 @@ def search_knowledge_base_for_context(query: str) -> str:
|
|
39 |
Returns:
|
40 |
str: Relevant text content that can be used by the LLM to answer the query.
|
41 |
"""
|
42 |
-
logger.info(f"Searching
|
43 |
-
|
44 |
-
|
45 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
46 |
|
47 |
def research_write_review_topic(query: str) -> str:
|
48 |
"""
|
@@ -65,46 +71,51 @@ def research_write_review_topic(query: str) -> str:
|
|
65 |
Returns:
|
66 |
str: A nicely formatted string.
|
67 |
"""
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
|
|
|
|
|
|
|
|
74 |
|
75 |
with gr.Blocks() as server_info:
|
76 |
gr.Markdown("""
|
77 |
-
|
78 |
|
79 |
-
|
|
|
80 |
|
81 |
-
|
82 |
-
Please check [this PDF](https://airgroup2000.com/gallery/albums/userpics/32438/SU-35_TM_eng.pdf) to formulate queries on Sukhoi.
|
83 |
|
84 |
-
|
85 |
-
|
|
|
86 |
|
87 |
-
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
|
106 |
-
|
107 |
-
|
108 |
""")
|
109 |
|
110 |
mcp_rag_tool = gr.Interface(
|
|
|
1 |
"""
|
2 |
This file is the main file for the hackathon.
|
3 |
+
It contains the Gradio interface for the hackathon as an MCP server.
|
4 |
It exposes the following tools:
|
5 |
- search_knowledge_base_for_context
|
6 |
- research_write_review_topic
|
|
|
7 |
"""
|
8 |
+
|
9 |
+
import os
|
10 |
from dotenv import load_dotenv
|
11 |
load_dotenv() # Load environment variables from .env file
|
12 |
|
|
|
22 |
logger = logging.getLogger(__name__)
|
23 |
|
24 |
import gradio as gr
|
25 |
+
import requests
|
|
|
26 |
|
27 |
def search_knowledge_base_for_context(query: str) -> str:
|
28 |
"""
|
29 |
+
Searches and retrieves relevant context from a knowledge base on Sukhoi SU-35,
|
30 |
based on the user's query.
|
31 |
|
32 |
Example queries:
|
|
|
39 |
Returns:
|
40 |
str: Relevant text content that can be used by the LLM to answer the query.
|
41 |
"""
|
42 |
+
logger.info(f"Searching knowledge base for RAG context via modal labs: {query}")
|
43 |
+
|
44 |
+
data = {"query": query}
|
45 |
+
modal_url = os.getenv("MODAL_LABS_HACKATHON_RAG_TOOLS_URL")
|
46 |
+
response = requests.post(modal_url, json=data, timeout=1000.0)
|
47 |
+
logger.info(f"modal RAG Response: {response}")
|
48 |
+
if response.status_code != 200:
|
49 |
+
logger.error(f"Error in modal RAG response: {response.status_code} - {response.text}")
|
50 |
+
return "Error in retrieving context from the knowledge base."
|
51 |
+
return response.text or "No relevant information found"
|
52 |
|
53 |
def research_write_review_topic(query: str) -> str:
|
54 |
"""
|
|
|
71 |
Returns:
|
72 |
str: A nicely formatted string.
|
73 |
"""
|
74 |
+
logger.info(f"Researching the topic via modal labs: {query}")
|
75 |
+
|
76 |
+
data = {"query": query}
|
77 |
+
modal_url = os.getenv("MODAL_LABS_HACKATHON_RESEARCH_TOOLS_URL")
|
78 |
+
response = requests.post(modal_url, json=data, timeout=1000.0)
|
79 |
+
logger.info(f"modal RESEARCH Response: {response}")
|
80 |
+
if response.status_code != 200:
|
81 |
+
logger.error(f"Error in modal RESEARCH response: {response.status_code} - {response.text}")
|
82 |
+
return "Error in retrieving research topic."
|
83 |
+
return response.text or "Research completed, but no content was generated."
|
84 |
|
85 |
with gr.Blocks() as server_info:
|
86 |
gr.Markdown("""
|
87 |
+
# π MCP Powered RAG and Research Topic π
|
88 |
|
89 |
+
I present to you an MCP-powered RAG and Research Topic.
|
90 |
+
The Tools are hosted and executed on **Modal Labs**
|
91 |
|
92 |
+
RAG Tool uses the **GroundX** storage by **eyelevel.ai** to fetch the knowledge base. The knowledge base is a document that contains information about the SU-35 aircraft, including its features, capabilities, and specifications. Please check [this PDF](https://airgroup2000.com/gallery/albums/userpics/32438/SU-35_TM_eng.pdf) to formulate queries on Sukhoi.
|
|
|
93 |
|
94 |
+
The Research Tool is implemented using a multi-agent workflow using **LlamaIndex** (ResearchAgent, WriteAgent, and ReviewAgent).
|
95 |
+
<br>
|
96 |
+
The Agents use **Nebius** provided LLM.
|
97 |
|
98 |
+
## Available Tools
|
99 |
|
100 |
+
### search_knowledge_base_for_context
|
101 |
+
- **Description**: Searches and retrieves relevant context from a knowledge base based on the user's query.
|
102 |
+
- **Example Queries**:
|
103 |
+
- "What are the main features of fuel system of SU-35?"
|
104 |
+
- "What is the combat potential of SU-35?"
|
105 |
|
106 |
+
### research_write_review_topic
|
107 |
+
- **Description**: Helps with writing a report with research, writing, and review on any topic.
|
108 |
+
- **Example Queries**:
|
109 |
+
- "Write me a report on the history of the internet."
|
110 |
+
- "Write me a report on origin of the universe."
|
111 |
+
- "Write me a report on the impact of climate change on polar bears."
|
112 |
|
113 |
+
## How to Use
|
114 |
+
- Use the MCP RAG Tool tab above to query the knowledge base.
|
115 |
+
- Use the Research Tool tab above to write a report on any topic.
|
116 |
|
117 |
+
## Watch the Demo Video here
|
118 |
+
[Link to Demo on Youtube](https://youtu.be/wvHBqW2ABGg)
|
119 |
""")
|
120 |
|
121 |
mcp_rag_tool = gr.Interface(
|