Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from mcp import StdioServerParameters
|
| 3 |
+
from smolagents import MCPClient, CodeAgent
|
| 4 |
+
|
| 5 |
+
def respond(prompt, history=[]):
|
| 6 |
+
# Launch MCP subprocess
|
| 7 |
+
params = StdioServerParameters(command="python", args=["mcp_server.py"])
|
| 8 |
+
with MCPClient(params) as tools:
|
| 9 |
+
agent = CodeAgent(tools=tools, model="gpt-4") # Replace with your local or API model
|
| 10 |
+
result = agent.run(prompt)
|
| 11 |
+
history.append((prompt, result))
|
| 12 |
+
return history, history
|
| 13 |
+
|
| 14 |
+
with gr.Blocks() as demo:
|
| 15 |
+
chat_history = gr.State([])
|
| 16 |
+
chatbot = gr.Chatbot(label="Enterprise SQL Agent")
|
| 17 |
+
textbox = gr.Textbox(show_label=False, placeholder="Ask questions like 'List inactive customers in Northeast'")
|
| 18 |
+
textbox.submit(respond, [textbox, chat_history], [chatbot, chat_history])
|
| 19 |
+
|
| 20 |
+
gr.Markdown(\"\"\"\n
|
| 21 |
+
### Example Prompts:
|
| 22 |
+
- Who are my Northeast customers who haven’t ordered in 6 months?
|
| 23 |
+
- List customers sorted by last order date.
|
| 24 |
+
- Find clients from the West with recent orders.
|
| 25 |
+
\"\"\")
|
| 26 |
+
|
| 27 |
+
demo.launch()
|