lol040604lol commited on
Commit
d8b7e97
Β·
verified Β·
1 Parent(s): 2ef1de3

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. 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
- # βœ… Set custom cache directory to avoid permission errors
7
- os.environ['HF_HOME'] = './hf_cache'
8
- os.environ['TRANSFORMERS_CACHE'] = './hf_cache'
9
 
10
- # βœ… Streamlit config
11
  st.set_page_config(page_title="SmartProcureAI", layout="wide")
12
 
13
- # βœ… Load local JSON data
14
- with open("src/sap_data.json") as f:
15
  sap_data = json.load(f)
16
 
17
- # βœ… Load lightweight GPT-2 model using the safe cache
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 input form
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
- # βœ… Fetch 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
- # βœ… Prompt template
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
- # βœ… 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
- # βœ… Vendor info
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"):