Manavraj commited on
Commit
ab7850a
·
verified ·
1 Parent(s): cb207ff

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -7
app.py CHANGED
@@ -7,11 +7,15 @@ import time
7
  import logging
8
  import re
9
  from smolagents.tools import tool
 
 
10
 
11
  # Configure logging
12
  logging.basicConfig(level=logging.INFO)
13
  logger = logging.getLogger(__name__)
14
 
 
 
15
  @tool
16
  def search_knowledge_base(issue: str) -> str:
17
  """
@@ -146,7 +150,7 @@ def format_response(raw_steps: str) -> str:
146
  logger.error(f"Error formatting steps: {str(e)}")
147
  return f"Error formatting your steps: {str(e)}"
148
 
149
- # Knowledge Base Search Interface
150
  demo1 = gr.Interface(
151
  fn=search_knowledge_base,
152
  inputs=[gr.Textbox(label="Technical Issue", placeholder="Enter your technical problem")],
@@ -154,7 +158,6 @@ demo1 = gr.Interface(
154
  title="Knowledge Base Search"
155
  )
156
 
157
- # Web Search Interface
158
  demo2 = gr.Interface(
159
  fn=search_web,
160
  inputs=[gr.Textbox(label="Search Query", placeholder="Enter your search query")],
@@ -162,7 +165,6 @@ demo2 = gr.Interface(
162
  title="Web Search"
163
  )
164
 
165
- # Response Formatter Interface
166
  demo3 = gr.Interface(
167
  fn=format_response,
168
  inputs=[gr.Textbox(label="Raw Steps", placeholder="Enter steps separated by periods")],
@@ -172,8 +174,46 @@ demo3 = gr.Interface(
172
 
173
  demo = gr.TabbedInterface([demo1, demo2, demo3], ["Knowledge Base", "Web Search", "Formatter"])
174
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
175
  if __name__ == "__main__":
176
- demo.launch(
177
- server_name="0.0.0.0",
178
- server_port=7860
179
- )
 
7
  import logging
8
  import re
9
  from smolagents.tools import tool
10
+ from fastapi import FastAPI
11
+ import uvicorn
12
 
13
  # Configure logging
14
  logging.basicConfig(level=logging.INFO)
15
  logger = logging.getLogger(__name__)
16
 
17
+ app = FastAPI()
18
+
19
  @tool
20
  def search_knowledge_base(issue: str) -> str:
21
  """
 
150
  logger.error(f"Error formatting steps: {str(e)}")
151
  return f"Error formatting your steps: {str(e)}"
152
 
153
+ # Create interfaces
154
  demo1 = gr.Interface(
155
  fn=search_knowledge_base,
156
  inputs=[gr.Textbox(label="Technical Issue", placeholder="Enter your technical problem")],
 
158
  title="Knowledge Base Search"
159
  )
160
 
 
161
  demo2 = gr.Interface(
162
  fn=search_web,
163
  inputs=[gr.Textbox(label="Search Query", placeholder="Enter your search query")],
 
165
  title="Web Search"
166
  )
167
 
 
168
  demo3 = gr.Interface(
169
  fn=format_response,
170
  inputs=[gr.Textbox(label="Raw Steps", placeholder="Enter steps separated by periods")],
 
174
 
175
  demo = gr.TabbedInterface([demo1, demo2, demo3], ["Knowledge Base", "Web Search", "Formatter"])
176
 
177
+ # Add MCP schema endpoint
178
+ @app.get("/gradio_api/mcp/schema")
179
+ async def mcp_schema():
180
+ return {
181
+ "tools": [
182
+ {
183
+ "name": "search_knowledge_base",
184
+ "description": "Search knowledge base for technical solutions",
185
+ "parameters": {
186
+ "type": "object",
187
+ "properties": {
188
+ "issue": {"type": "string"}
189
+ }
190
+ }
191
+ },
192
+ {
193
+ "name": "search_web",
194
+ "description": "Perform web search",
195
+ "parameters": {
196
+ "type": "object",
197
+ "properties": {
198
+ "query": {"type": "string"}
199
+ }
200
+ }
201
+ },
202
+ {
203
+ "name": "format_response",
204
+ "description": "Format steps into numbered list",
205
+ "parameters": {
206
+ "type": "object",
207
+ "properties": {
208
+ "raw_steps": {"type": "string"}
209
+ }
210
+ }
211
+ }
212
+ ]
213
+ }
214
+
215
+ # Mount Gradio app
216
+ app = gr.mount_gradio_app(app, demo, path="/")
217
+
218
  if __name__ == "__main__":
219
+ uvicorn.run(app, host="0.0.0.0", port=7860)