Spaces:
Sleeping
Sleeping
| import os | |
| import json | |
| import streamlit as st | |
| from transformers import pipeline | |
| # Set environment variables for Hugging Face cache | |
| os.environ['HF_HOME'] = os.path.expanduser('~/.cache/huggingface') | |
| os.environ['TRANSFORMERS_CACHE'] = os.environ['HF_HOME'] | |
| # Streamlit configuration | |
| st.set_page_config(page_title="SmartProcureAI", layout="wide") | |
| # Load data | |
| with open("sap_data.json") as f: | |
| sap_data = json.load(f) | |
| # Initialize the text generation pipeline | |
| summarizer = pipeline("text-generation", model="gpt2", max_new_tokens=150) | |
| # App title | |
| st.title("π¦ SmartProcureAI: GenAI-Powered SAP Procurement Assistant") | |
| # Sidebar inputs | |
| st.sidebar.header("π RFQ Generator") | |
| product_type = st.sidebar.selectbox("Select Product", [p["name"] for p in sap_data["products"]]) | |
| budget = st.sidebar.number_input("Enter Budget (INR)", value=50000) | |
| # Retrieve selected product and vendor | |
| product = next(p for p in sap_data["products"] if p["name"] == product_type) | |
| vendor = next(v for v in sap_data["vendors"] if v["id"] == product["vendor_id"]) | |
| # Generate prompt | |
| prompt = f""" | |
| Write a professional RFQ email for the following procurement need: | |
| - Product: {product['name']} | |
| - Vendor: {vendor['name']} | |
| - Price: βΉ{product['price']} | |
| - Delivery Time: {vendor['delivery_time']} days | |
| - Max Budget: βΉ{budget} | |
| Keep it concise and formal. | |
| """ | |
| # Generate RFQ | |
| if st.sidebar.button("π Generate RFQ"): | |
| with st.spinner("Generating RFQ..."): | |
| output = summarizer(prompt)[0]["generated_text"] | |
| st.subheader("π Generated RFQ:") | |
| st.code(output) | |
| # Display vendor information | |
| st.sidebar.markdown("---") | |
| st.sidebar.subheader("π Vendor Summary") | |
| if st.sidebar.button("π Show Vendor Info"): | |
| st.write("### π§Ύ Vendor Details") | |
| st.json(vendor) | |