André Oliveira
commited on
Commit
·
dc0d368
1
Parent(s):
282d875
added new mcp upload tool
Browse files
app.py
CHANGED
|
@@ -29,7 +29,7 @@ def upload_docs_tool(files, docs_path="data/docs"):
|
|
| 29 |
Accepts:
|
| 30 |
- local file paths (str)
|
| 31 |
- URLs (str)
|
| 32 |
-
- file-like objects
|
| 33 |
"""
|
| 34 |
import shutil, tempfile
|
| 35 |
|
|
@@ -79,7 +79,6 @@ def upload_docs_tool(files, docs_path="data/docs"):
|
|
| 79 |
pass
|
| 80 |
|
| 81 |
|
| 82 |
-
|
| 83 |
def optimize_rag_tool(payload: str) -> str:
|
| 84 |
"""🔧 Explicit optimization request: user provides all pipeline configs manually."""
|
| 85 |
return call_api("/optimize_rag", json.loads(payload))
|
|
@@ -113,7 +112,7 @@ DEFAULT_QA_JSON = model_to_json(QARequest)
|
|
| 113 |
|
| 114 |
|
| 115 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 116 |
-
gr.Markdown("# Ragmint MCP
|
| 117 |
|
| 118 |
# Upload Documents
|
| 119 |
with gr.Column():
|
|
@@ -126,6 +125,42 @@ with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
|
| 126 |
upload_btn.click(upload_docs_tool, inputs=[upload_files, upload_path], outputs=upload_out)
|
| 127 |
gr.Markdown("---")
|
| 128 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 129 |
# Optimize RAG
|
| 130 |
with gr.Column():
|
| 131 |
gr.Markdown("## Optimize RAG")
|
|
|
|
| 29 |
Accepts:
|
| 30 |
- local file paths (str)
|
| 31 |
- URLs (str)
|
| 32 |
+
- file-like objects
|
| 33 |
"""
|
| 34 |
import shutil, tempfile
|
| 35 |
|
|
|
|
| 79 |
pass
|
| 80 |
|
| 81 |
|
|
|
|
| 82 |
def optimize_rag_tool(payload: str) -> str:
|
| 83 |
"""🔧 Explicit optimization request: user provides all pipeline configs manually."""
|
| 84 |
return call_api("/optimize_rag", json.loads(payload))
|
|
|
|
| 112 |
|
| 113 |
|
| 114 |
with gr.Blocks(theme=gr.themes.Soft()) as demo:
|
| 115 |
+
gr.Markdown("# Ragmint MCP Server")
|
| 116 |
|
| 117 |
# Upload Documents
|
| 118 |
with gr.Column():
|
|
|
|
| 125 |
upload_btn.click(upload_docs_tool, inputs=[upload_files, upload_path], outputs=upload_out)
|
| 126 |
gr.Markdown("---")
|
| 127 |
|
| 128 |
+
# Upload MCP Documents (no file uploader)
|
| 129 |
+
with gr.Column():
|
| 130 |
+
gr.Markdown("## Upload Documents via MCP")
|
| 131 |
+
gr.Markdown("📂 Upload files (local paths or URLs) to your `data/docs` folder on MCP.")
|
| 132 |
+
upload_mcp_input = gr.Textbox(
|
| 133 |
+
lines=5,
|
| 134 |
+
placeholder='Enter list of files/URLs, e.g., ["file1.txt","file2.pdf"]',
|
| 135 |
+
label="Files (JSON list)"
|
| 136 |
+
)
|
| 137 |
+
upload_mcp_path = gr.Textbox(value=DEFAULT_UPLOAD_PATH, label="Docs Path")
|
| 138 |
+
upload_mcp_out = gr.JSON(label="Response")
|
| 139 |
+
upload_mcp_btn = gr.Button("Upload via MCP", variant="primary")
|
| 140 |
+
|
| 141 |
+
# MCP callable function
|
| 142 |
+
def mcp_upload_wrapper(files_json, docs_path):
|
| 143 |
+
"""
|
| 144 |
+
Upload documents to the server's docs folder via MCP.
|
| 145 |
+
Accepts:
|
| 146 |
+
- local file paths (str)
|
| 147 |
+
- URLs (str)
|
| 148 |
+
- file-like objects
|
| 149 |
+
"""
|
| 150 |
+
import ast
|
| 151 |
+
try:
|
| 152 |
+
files = ast.literal_eval(files_json)
|
| 153 |
+
except Exception:
|
| 154 |
+
return {"error": "Invalid JSON list of files"}
|
| 155 |
+
return upload_docs_tool(files, docs_path)
|
| 156 |
+
|
| 157 |
+
upload_mcp_btn.click(
|
| 158 |
+
mcp_upload_wrapper,
|
| 159 |
+
inputs=[upload_mcp_input, upload_mcp_path],
|
| 160 |
+
outputs=upload_mcp_out
|
| 161 |
+
)
|
| 162 |
+
gr.Markdown("---")
|
| 163 |
+
|
| 164 |
# Optimize RAG
|
| 165 |
with gr.Column():
|
| 166 |
gr.Markdown("## Optimize RAG")
|