Update app.py
Browse files
app.py
CHANGED
@@ -8,18 +8,7 @@ It exposes the following tools:
|
|
8 |
|
9 |
import os
|
10 |
from dotenv import load_dotenv
|
11 |
-
load_dotenv() # Load environment variables
|
12 |
-
|
13 |
-
import logging
|
14 |
-
|
15 |
-
# Configure logging to write to a file instead of stdout/stderr
|
16 |
-
# This avoids interference with the MCP communication channel
|
17 |
-
logging.basicConfig(
|
18 |
-
filename='hackathon-mcp.log', # Log to a file instead of stdout/stderr
|
19 |
-
level=logging.INFO,
|
20 |
-
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s'
|
21 |
-
)
|
22 |
-
logger = logging.getLogger(__name__)
|
23 |
|
24 |
import gradio as gr
|
25 |
import requests
|
@@ -39,14 +28,14 @@ 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 |
-
|
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=
|
47 |
-
|
48 |
if response.status_code != 200:
|
49 |
-
|
50 |
return "Error in retrieving context from the knowledge base."
|
51 |
return response.text or "No relevant information found"
|
52 |
|
@@ -71,14 +60,14 @@ def research_write_review_topic(query: str) -> str:
|
|
71 |
Returns:
|
72 |
str: A nicely formatted string.
|
73 |
"""
|
74 |
-
|
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=
|
79 |
-
|
80 |
if response.status_code != 200:
|
81 |
-
|
82 |
return "Error in retrieving research topic."
|
83 |
return response.text or "Research completed, but no content was generated."
|
84 |
|
@@ -121,7 +110,7 @@ with gr.Blocks() as server_info:
|
|
121 |
mcp_rag_tool = gr.Interface(
|
122 |
fn=search_knowledge_base_for_context,
|
123 |
inputs=["text"],
|
124 |
-
outputs=[gr.Textbox(label="Knowledge Base", max_lines=
|
125 |
title="MCP RAG Tool",
|
126 |
description="Searches and retrieves relevant context from a knowledge base"
|
127 |
)
|
@@ -129,10 +118,10 @@ mcp_rag_tool = gr.Interface(
|
|
129 |
research_tool = gr.Interface(
|
130 |
fn=research_write_review_topic,
|
131 |
inputs=["text"],
|
132 |
-
outputs=[gr.Textbox(label="Reviewed Topic", max_lines=
|
133 |
title="Research Tool",
|
134 |
description="Helps with report writing with research, writing, and review agents on any topic. ",
|
135 |
-
concurrency_limit=
|
136 |
)
|
137 |
|
138 |
named_interfaces = {
|
@@ -153,7 +142,7 @@ mcp_server = gr.TabbedInterface(
|
|
153 |
|
154 |
# Launch the MCP Server
|
155 |
if __name__ == "__main__":
|
156 |
-
mcp_server.queue(default_concurrency_limit=
|
157 |
mcp_server.launch(
|
158 |
server_name="0.0.0.0",
|
159 |
server_port=7860,
|
|
|
8 |
|
9 |
import os
|
10 |
from dotenv import load_dotenv
|
11 |
+
load_dotenv() # Load environment variables
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
|
13 |
import gradio as gr
|
14 |
import requests
|
|
|
28 |
Returns:
|
29 |
str: Relevant text content that can be used by the LLM to answer the query.
|
30 |
"""
|
31 |
+
print(f"Searching knowledge base for RAG context via modal labs: {query}")
|
32 |
|
33 |
data = {"query": query}
|
34 |
modal_url = os.getenv("MODAL_LABS_HACKATHON_RAG_TOOLS_URL")
|
35 |
+
response = requests.post(modal_url, json=data, timeout=600.0)
|
36 |
+
print(f"modal RAG Response: {response}")
|
37 |
if response.status_code != 200:
|
38 |
+
print(f"Error in modal RAG response: {response.status_code} - {response.text}")
|
39 |
return "Error in retrieving context from the knowledge base."
|
40 |
return response.text or "No relevant information found"
|
41 |
|
|
|
60 |
Returns:
|
61 |
str: A nicely formatted string.
|
62 |
"""
|
63 |
+
print(f"Researching the topic via modal labs: {query}")
|
64 |
|
65 |
data = {"query": query}
|
66 |
modal_url = os.getenv("MODAL_LABS_HACKATHON_RESEARCH_TOOLS_URL")
|
67 |
+
response = requests.post(modal_url, json=data, timeout=600.0)
|
68 |
+
print(f"modal RESEARCH Response: {response}")
|
69 |
if response.status_code != 200:
|
70 |
+
print(f"Error in modal RESEARCH response: {response.status_code} - {response.text}")
|
71 |
return "Error in retrieving research topic."
|
72 |
return response.text or "Research completed, but no content was generated."
|
73 |
|
|
|
110 |
mcp_rag_tool = gr.Interface(
|
111 |
fn=search_knowledge_base_for_context,
|
112 |
inputs=["text"],
|
113 |
+
outputs=[gr.Textbox(label="Knowledge Base", max_lines=15)],
|
114 |
title="MCP RAG Tool",
|
115 |
description="Searches and retrieves relevant context from a knowledge base"
|
116 |
)
|
|
|
118 |
research_tool = gr.Interface(
|
119 |
fn=research_write_review_topic,
|
120 |
inputs=["text"],
|
121 |
+
outputs=[gr.Textbox(label="Reviewed Topic", max_lines=15)],
|
122 |
title="Research Tool",
|
123 |
description="Helps with report writing with research, writing, and review agents on any topic. ",
|
124 |
+
concurrency_limit=1
|
125 |
)
|
126 |
|
127 |
named_interfaces = {
|
|
|
142 |
|
143 |
# Launch the MCP Server
|
144 |
if __name__ == "__main__":
|
145 |
+
mcp_server.queue(default_concurrency_limit=1)
|
146 |
mcp_server.launch(
|
147 |
server_name="0.0.0.0",
|
148 |
server_port=7860,
|