betki commited on
Commit
7ca8f3d
Β·
verified Β·
1 Parent(s): bea97d8

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +49 -38
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 a MCP server.
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
- from tools.rag_tools import search_groundx_for_rag_context
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 (GroundX),
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 document for RAG context {query}")
43
- response = search_groundx_for_rag_context(query)
44
- logger.info(f"RAG Response: {response}")
45
- return response
 
 
 
 
 
 
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
- try:
69
- logger.info(f"Researching the topic: {query}")
70
- result = run_research_workflow(query)
71
- return result or "Research completed, but no content was generated."
72
- except Exception as e:
73
- return f"Error: {e}"
 
 
 
 
74
 
75
  with gr.Blocks() as server_info:
76
  gr.Markdown("""
77
- # MCP-Powered RAG and Research Topic
78
 
79
- I present to you an MCP-powered RAG and Research.
 
80
 
81
- RAG Tool uses the knowledge base stored on the **GroundX by eyelevel.ai**. The knowledge base is a document that contains information about the SU-35 aircraft, including its features, capabilities, and specifications.
82
- Please check [this PDF](https://airgroup2000.com/gallery/albums/userpics/32438/SU-35_TM_eng.pdf) to formulate queries on Sukhoi.
83
 
84
- The Research Tool is implemented using multi-agent workflow using **LlamaIndex** (ResearchAgent, WriteAgent, and ReviewAgent).
85
- The Agents uses LLM provided by **Nebius**
 
86
 
87
- ## Available Tools
88
 
89
- ### search_knowledge_base_for_context
90
- - **Description**: Searches and retrieves relevant context from a knowledge base based on the user's query.
91
- - **Example Queries**:
92
- - "What are the main features of fuel system of SU-35."
93
- - "What are the combat potential of SU-35."
94
 
95
- ### research_write_review_topic
96
- - **Description**: Helps with writing a report with research, writing, and review on any topic.
97
- - **Example Queries**:
98
- - "Write me a report on the history of the internet."
99
- - "Write me a report on origin of the universe."
100
- - "Write me a report on the impact of climate change on polar bears."
101
 
102
- ## How to Use
103
- - Use the MCP RAG Tool tab above to query the knowledge base.
104
- - Use the Research Tool tab above to write report on any topic.
105
 
106
- ## Watch the Demo Video here
107
- [Link to Demo on Youtube](https://youtu.be/wvHBqW2ABGg)
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(