Update src/streamlit_app.py
Browse files- src/streamlit_app.py +38 -9
src/streamlit_app.py
CHANGED
|
@@ -15,7 +15,6 @@ st.set_page_config(
|
|
| 15 |
# Initialize OpenAI model for Spaces
|
| 16 |
@st.cache_resource
|
| 17 |
def get_model():
|
| 18 |
-
# Try to get API key from Spaces secrets or environment
|
| 19 |
api_key = os.environ.get("OPENAI_API_KEY")
|
| 20 |
if not api_key:
|
| 21 |
st.error("⚠️ OpenAI API Key not found in Spaces secrets!")
|
|
@@ -31,7 +30,12 @@ def get_model():
|
|
| 31 |
# Tool 1: Query SAP Purchase Requisition
|
| 32 |
@tool
|
| 33 |
def query_sap_pr(pr_number: str) -> str:
|
| 34 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
materials = ["Steel Pipes", "Cement", "Electrical Cables", "Safety Equipment"]
|
| 36 |
mock_data = {
|
| 37 |
"pr_number": pr_number,
|
|
@@ -48,7 +52,12 @@ def query_sap_pr(pr_number: str) -> str:
|
|
| 48 |
# Tool 2: Check Vendor Financial Health
|
| 49 |
@tool
|
| 50 |
def check_vendor_solvency(vendor_name: str) -> str:
|
| 51 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
scores = ["A+", "A", "A-", "B+", "B"]
|
| 53 |
risk_levels = ["Low", "Medium", "High"]
|
| 54 |
mock_data = {
|
|
@@ -57,7 +66,7 @@ def check_vendor_solvency(vendor_name: str) -> str:
|
|
| 57 |
"financial_stability": "Stable",
|
| 58 |
"solvency_score": random.randint(65, 95),
|
| 59 |
"debt_ratio": round(random.uniform(0.2, 0.6), 2),
|
| 60 |
-
"risk_level": random.choice(risk_levels[:2]),
|
| 61 |
"recommendation": "Approved for business"
|
| 62 |
}
|
| 63 |
return json.dumps(mock_data, indent=2)
|
|
@@ -65,7 +74,12 @@ def check_vendor_solvency(vendor_name: str) -> str:
|
|
| 65 |
# Tool 3: Get Vendor Performance History
|
| 66 |
@tool
|
| 67 |
def get_vendor_performance(vendor_name: str) -> str:
|
| 68 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 69 |
mock_data = {
|
| 70 |
"vendor_name": vendor_name,
|
| 71 |
"evaluation_period": "12 months",
|
|
@@ -82,7 +96,12 @@ def get_vendor_performance(vendor_name: str) -> str:
|
|
| 82 |
# Tool 4: Compare Material Rates
|
| 83 |
@tool
|
| 84 |
def compare_material_rates(material: str) -> str:
|
| 85 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 86 |
vendors = ["Alpha Corp", "Beta Supplies", "Gamma Materials", "Delta Industries"]
|
| 87 |
base_price = random.randint(80, 250)
|
| 88 |
|
|
@@ -107,7 +126,12 @@ def compare_material_rates(material: str) -> str:
|
|
| 107 |
# Tool 5: Optimize Vendor Selection
|
| 108 |
@tool
|
| 109 |
def optimize_vendor_selection(requirements: str) -> str:
|
| 110 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 111 |
vendors = ["ABC Supplies", "XYZ Materials", "DEF Corp", "GHI Industries"]
|
| 112 |
selected_vendor = random.choice(vendors)
|
| 113 |
|
|
@@ -126,7 +150,13 @@ def optimize_vendor_selection(requirements: str) -> str:
|
|
| 126 |
# Tool 6: Create SAP Purchase Order
|
| 127 |
@tool
|
| 128 |
def create_purchase_order(vendor: str, amount: str) -> str:
|
| 129 |
-
"""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 130 |
po_number = f"PO{datetime.now().strftime('%Y%m%d%H%M%S')[-8:]}"
|
| 131 |
|
| 132 |
mock_data = {
|
|
@@ -239,7 +269,6 @@ def main():
|
|
| 239 |
with st.container():
|
| 240 |
st.success("✅ Agent completed successfully!")
|
| 241 |
|
| 242 |
-
# Display response in an expandable section
|
| 243 |
with st.expander("📋 Full Agent Response", expanded=True):
|
| 244 |
st.markdown(st.session_state['agent_response'])
|
| 245 |
|
|
|
|
| 15 |
# Initialize OpenAI model for Spaces
|
| 16 |
@st.cache_resource
|
| 17 |
def get_model():
|
|
|
|
| 18 |
api_key = os.environ.get("OPENAI_API_KEY")
|
| 19 |
if not api_key:
|
| 20 |
st.error("⚠️ OpenAI API Key not found in Spaces secrets!")
|
|
|
|
| 30 |
# Tool 1: Query SAP Purchase Requisition
|
| 31 |
@tool
|
| 32 |
def query_sap_pr(pr_number: str) -> str:
|
| 33 |
+
"""
|
| 34 |
+
Query SAP purchase requisition details
|
| 35 |
+
|
| 36 |
+
Args:
|
| 37 |
+
pr_number: The purchase requisition number to query
|
| 38 |
+
"""
|
| 39 |
materials = ["Steel Pipes", "Cement", "Electrical Cables", "Safety Equipment"]
|
| 40 |
mock_data = {
|
| 41 |
"pr_number": pr_number,
|
|
|
|
| 52 |
# Tool 2: Check Vendor Financial Health
|
| 53 |
@tool
|
| 54 |
def check_vendor_solvency(vendor_name: str) -> str:
|
| 55 |
+
"""
|
| 56 |
+
Check vendor financial solvency from external sources
|
| 57 |
+
|
| 58 |
+
Args:
|
| 59 |
+
vendor_name: Name of the vendor to check financial solvency for
|
| 60 |
+
"""
|
| 61 |
scores = ["A+", "A", "A-", "B+", "B"]
|
| 62 |
risk_levels = ["Low", "Medium", "High"]
|
| 63 |
mock_data = {
|
|
|
|
| 66 |
"financial_stability": "Stable",
|
| 67 |
"solvency_score": random.randint(65, 95),
|
| 68 |
"debt_ratio": round(random.uniform(0.2, 0.6), 2),
|
| 69 |
+
"risk_level": random.choice(risk_levels[:2]),
|
| 70 |
"recommendation": "Approved for business"
|
| 71 |
}
|
| 72 |
return json.dumps(mock_data, indent=2)
|
|
|
|
| 74 |
# Tool 3: Get Vendor Performance History
|
| 75 |
@tool
|
| 76 |
def get_vendor_performance(vendor_name: str) -> str:
|
| 77 |
+
"""
|
| 78 |
+
Get historical vendor performance metrics
|
| 79 |
+
|
| 80 |
+
Args:
|
| 81 |
+
vendor_name: Name of the vendor to get performance history for
|
| 82 |
+
"""
|
| 83 |
mock_data = {
|
| 84 |
"vendor_name": vendor_name,
|
| 85 |
"evaluation_period": "12 months",
|
|
|
|
| 96 |
# Tool 4: Compare Material Rates
|
| 97 |
@tool
|
| 98 |
def compare_material_rates(material: str) -> str:
|
| 99 |
+
"""
|
| 100 |
+
Compare current market rates for materials
|
| 101 |
+
|
| 102 |
+
Args:
|
| 103 |
+
material: Type of material to compare rates for
|
| 104 |
+
"""
|
| 105 |
vendors = ["Alpha Corp", "Beta Supplies", "Gamma Materials", "Delta Industries"]
|
| 106 |
base_price = random.randint(80, 250)
|
| 107 |
|
|
|
|
| 126 |
# Tool 5: Optimize Vendor Selection
|
| 127 |
@tool
|
| 128 |
def optimize_vendor_selection(requirements: str) -> str:
|
| 129 |
+
"""
|
| 130 |
+
Run optimization to find best vendor combination
|
| 131 |
+
|
| 132 |
+
Args:
|
| 133 |
+
requirements: Procurement requirements and constraints to optimize for
|
| 134 |
+
"""
|
| 135 |
vendors = ["ABC Supplies", "XYZ Materials", "DEF Corp", "GHI Industries"]
|
| 136 |
selected_vendor = random.choice(vendors)
|
| 137 |
|
|
|
|
| 150 |
# Tool 6: Create SAP Purchase Order
|
| 151 |
@tool
|
| 152 |
def create_purchase_order(vendor: str, amount: str) -> str:
|
| 153 |
+
"""
|
| 154 |
+
Create purchase order in SAP system
|
| 155 |
+
|
| 156 |
+
Args:
|
| 157 |
+
vendor: Name of the vendor to create purchase order for
|
| 158 |
+
amount: Total amount for the purchase order
|
| 159 |
+
"""
|
| 160 |
po_number = f"PO{datetime.now().strftime('%Y%m%d%H%M%S')[-8:]}"
|
| 161 |
|
| 162 |
mock_data = {
|
|
|
|
| 269 |
with st.container():
|
| 270 |
st.success("✅ Agent completed successfully!")
|
| 271 |
|
|
|
|
| 272 |
with st.expander("📋 Full Agent Response", expanded=True):
|
| 273 |
st.markdown(st.session_state['agent_response'])
|
| 274 |
|