Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +13 -13
src/streamlit_app.py
CHANGED
|
@@ -3,33 +3,33 @@ import json
|
|
| 3 |
import streamlit as st
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
-
#
|
| 7 |
-
os.environ['HF_HOME'] = './
|
| 8 |
-
os.environ['TRANSFORMERS_CACHE'] =
|
| 9 |
|
| 10 |
-
#
|
| 11 |
st.set_page_config(page_title="SmartProcureAI", layout="wide")
|
| 12 |
|
| 13 |
-
#
|
| 14 |
-
with open("
|
| 15 |
sap_data = json.load(f)
|
| 16 |
|
| 17 |
-
#
|
| 18 |
summarizer = pipeline("text-generation", model="gpt2", max_new_tokens=150)
|
| 19 |
|
| 20 |
-
#
|
| 21 |
st.title("π¦ SmartProcureAI: GenAI-Powered SAP Procurement Assistant")
|
| 22 |
|
| 23 |
-
#
|
| 24 |
st.sidebar.header("π RFQ Generator")
|
| 25 |
product_type = st.sidebar.selectbox("Select Product", [p["name"] for p in sap_data["products"]])
|
| 26 |
budget = st.sidebar.number_input("Enter Budget (INR)", value=50000)
|
| 27 |
|
| 28 |
-
#
|
| 29 |
product = next(p for p in sap_data["products"] if p["name"] == product_type)
|
| 30 |
vendor = next(v for v in sap_data["vendors"] if v["id"] == product["vendor_id"])
|
| 31 |
|
| 32 |
-
#
|
| 33 |
prompt = f"""
|
| 34 |
Write a professional RFQ email for the following procurement need:
|
| 35 |
- Product: {product['name']}
|
|
@@ -40,14 +40,14 @@ Write a professional RFQ email for the following procurement need:
|
|
| 40 |
Keep it concise and formal.
|
| 41 |
"""
|
| 42 |
|
| 43 |
-
#
|
| 44 |
if st.sidebar.button("π Generate RFQ"):
|
| 45 |
with st.spinner("Generating RFQ..."):
|
| 46 |
output = summarizer(prompt)[0]["generated_text"]
|
| 47 |
st.subheader("π Generated RFQ:")
|
| 48 |
st.code(output)
|
| 49 |
|
| 50 |
-
#
|
| 51 |
st.sidebar.markdown("---")
|
| 52 |
st.sidebar.subheader("π Vendor Summary")
|
| 53 |
if st.sidebar.button("π Show Vendor Info"):
|
|
|
|
| 3 |
import streamlit as st
|
| 4 |
from transformers import pipeline
|
| 5 |
|
| 6 |
+
# Set environment variables for Hugging Face cache
|
| 7 |
+
os.environ['HF_HOME'] = os.path.expanduser('~/.cache/huggingface')
|
| 8 |
+
os.environ['TRANSFORMERS_CACHE'] = os.environ['HF_HOME']
|
| 9 |
|
| 10 |
+
# Streamlit configuration
|
| 11 |
st.set_page_config(page_title="SmartProcureAI", layout="wide")
|
| 12 |
|
| 13 |
+
# Load data
|
| 14 |
+
with open("sap_data.json") as f:
|
| 15 |
sap_data = json.load(f)
|
| 16 |
|
| 17 |
+
# Initialize the text generation pipeline
|
| 18 |
summarizer = pipeline("text-generation", model="gpt2", max_new_tokens=150)
|
| 19 |
|
| 20 |
+
# App title
|
| 21 |
st.title("π¦ SmartProcureAI: GenAI-Powered SAP Procurement Assistant")
|
| 22 |
|
| 23 |
+
# Sidebar inputs
|
| 24 |
st.sidebar.header("π RFQ Generator")
|
| 25 |
product_type = st.sidebar.selectbox("Select Product", [p["name"] for p in sap_data["products"]])
|
| 26 |
budget = st.sidebar.number_input("Enter Budget (INR)", value=50000)
|
| 27 |
|
| 28 |
+
# Retrieve selected product and vendor
|
| 29 |
product = next(p for p in sap_data["products"] if p["name"] == product_type)
|
| 30 |
vendor = next(v for v in sap_data["vendors"] if v["id"] == product["vendor_id"])
|
| 31 |
|
| 32 |
+
# Generate prompt
|
| 33 |
prompt = f"""
|
| 34 |
Write a professional RFQ email for the following procurement need:
|
| 35 |
- Product: {product['name']}
|
|
|
|
| 40 |
Keep it concise and formal.
|
| 41 |
"""
|
| 42 |
|
| 43 |
+
# Generate RFQ
|
| 44 |
if st.sidebar.button("π Generate RFQ"):
|
| 45 |
with st.spinner("Generating RFQ..."):
|
| 46 |
output = summarizer(prompt)[0]["generated_text"]
|
| 47 |
st.subheader("π Generated RFQ:")
|
| 48 |
st.code(output)
|
| 49 |
|
| 50 |
+
# Display vendor information
|
| 51 |
st.sidebar.markdown("---")
|
| 52 |
st.sidebar.subheader("π Vendor Summary")
|
| 53 |
if st.sidebar.button("π Show Vendor Info"):
|