Update app.py
Browse files
app.py
CHANGED
|
@@ -1,36 +1,30 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
|
| 4 |
-
MCP_URL = "https://
|
| 5 |
-
|
| 6 |
-
API_URL = "https://api-inference.huggingface.co/models/google/flan-t5-base"
|
| 7 |
|
| 8 |
def query_llm(prompt):
|
| 9 |
-
|
|
|
|
|
|
|
| 10 |
if response.status_code == 200:
|
| 11 |
result = response.json()
|
| 12 |
-
|
| 13 |
-
return result[0].get('generated_text', '')
|
| 14 |
-
else:
|
| 15 |
-
raise ValueError("Unexpected response structure:", result)
|
| 16 |
else:
|
| 17 |
raise ValueError(f"API Error: {response.status_code}")
|
| 18 |
|
| 19 |
def extract_query_params(query):
|
| 20 |
prompt = f"""
|
| 21 |
-
Extract date and quantity from the
|
| 22 |
-
|
| 23 |
-
{{"date_from":
|
| 24 |
"""
|
| 25 |
-
|
| 26 |
llm_response = query_llm(prompt)
|
| 27 |
|
| 28 |
-
import re, json
|
| 29 |
try:
|
| 30 |
json_text = re.search(r"\{.*\}", llm_response, re.DOTALL).group()
|
| 31 |
return json.loads(json_text)
|
| 32 |
except:
|
| 33 |
-
# Default fallback if parsing fails
|
| 34 |
return {"date_from":"2023-01-01","min_quantity":0}
|
| 35 |
|
| 36 |
def agent_query(user_query):
|
|
@@ -64,7 +58,7 @@ iface = gr.Interface(
|
|
| 64 |
fn=agent_query,
|
| 65 |
inputs="text",
|
| 66 |
outputs="text",
|
| 67 |
-
title="Dynamic MCP Agent for SAP (Free LLM)",
|
| 68 |
description="Ask SAP queries naturally, e.g., 'Orders after 2023-04-01 with at least 10 units.'"
|
| 69 |
)
|
| 70 |
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
import requests, json, re
|
| 3 |
|
| 4 |
+
MCP_URL = "https://pretty-areas-make.loca.lt/mcp"
|
|
|
|
|
|
|
| 5 |
|
| 6 |
def query_llm(prompt):
|
| 7 |
+
url = "https://huggingface-projects-falcon-7b-instruct.hf.space/run/predict"
|
| 8 |
+
response = requests.post(url, json={"data": [prompt]})
|
| 9 |
+
|
| 10 |
if response.status_code == 200:
|
| 11 |
result = response.json()
|
| 12 |
+
return result['data'][0]
|
|
|
|
|
|
|
|
|
|
| 13 |
else:
|
| 14 |
raise ValueError(f"API Error: {response.status_code}")
|
| 15 |
|
| 16 |
def extract_query_params(query):
|
| 17 |
prompt = f"""
|
| 18 |
+
Extract date and quantity from the sentence '{query}'.
|
| 19 |
+
Respond only in JSON format:
|
| 20 |
+
{{"date_from":"YYYY-MM-DD","min_quantity":number}}
|
| 21 |
"""
|
|
|
|
| 22 |
llm_response = query_llm(prompt)
|
| 23 |
|
|
|
|
| 24 |
try:
|
| 25 |
json_text = re.search(r"\{.*\}", llm_response, re.DOTALL).group()
|
| 26 |
return json.loads(json_text)
|
| 27 |
except:
|
|
|
|
| 28 |
return {"date_from":"2023-01-01","min_quantity":0}
|
| 29 |
|
| 30 |
def agent_query(user_query):
|
|
|
|
| 58 |
fn=agent_query,
|
| 59 |
inputs="text",
|
| 60 |
outputs="text",
|
| 61 |
+
title="Dynamic MCP Agent for SAP (Free Falcon LLM)",
|
| 62 |
description="Ask SAP queries naturally, e.g., 'Orders after 2023-04-01 with at least 10 units.'"
|
| 63 |
)
|
| 64 |
|