PD03 commited on
Commit
2798042
·
verified ·
1 Parent(s): 35172bc

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +41 -0
app.py ADDED
@@ -0,0 +1,41 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import requests
3
+
4
+ # Updated MCP middleware URL
5
+ MCP_URL = "https://pretty-areas-make.loca.lt/mcp"
6
+
7
+ def get_sap_orders(top=5):
8
+ payload = {
9
+ "jsonrpc": "2.0",
10
+ "method": "SAP.getProcOrderConfirmation",
11
+ "params": {"top": top},
12
+ "id": "req-002"
13
+ }
14
+ try:
15
+ response = requests.post(MCP_URL, json=payload).json()
16
+ results = response.get("result", {}).get("d", {}).get("results", [])
17
+
18
+ if not results:
19
+ return "No process order confirmations found."
20
+
21
+ formatted_results = "\n\n".join([
22
+ f"Order ID: {r.get('ProcOrdConf', 'N/A')}\n"
23
+ f"Material: {r.get('Material', 'N/A')}\n"
24
+ f"Quantity: {r.get('YieldQty', 'N/A')} {r.get('YieldQtyUnit', '')}\n"
25
+ f"Posting Date: {r.get('PostingDate', 'N/A')}"
26
+ for r in results
27
+ ])
28
+
29
+ return formatted_results
30
+ except Exception as e:
31
+ return f"Error fetching data: {str(e)}"
32
+
33
+ iface = gr.Interface(
34
+ fn=get_sap_orders,
35
+ inputs=gr.Slider(minimum=1, maximum=10, step=1, value=3, label="Number of Orders"),
36
+ outputs="text",
37
+ title="Agentic AI MCP Client for SAP",
38
+ description="Fetch SAP Process Order Confirmations via MCP middleware."
39
+ )
40
+
41
+ iface.launch()