AliInamdar commited on
Commit
1da6fc2
Β·
verified Β·
1 Parent(s): 8461e1c

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +9 -5
src/streamlit_app.py CHANGED
@@ -5,8 +5,11 @@ import requests
5
  import re
6
  import io
7
 
8
- # πŸ” Set your Together API key securely
9
- TOGETHER_API_KEY = st.secrets["TOGETHER_API_KEY"] if "TOGETHER_API_KEY" in st.secrets else st.text_input("Enter Together API Key", type="password")
 
 
 
10
 
11
  # 🧠 Generate SQL using Together API
12
  def generate_sql_from_prompt(prompt, df):
@@ -52,7 +55,7 @@ st.markdown("Upload your **Excel file**, ask a question in natural language, and
52
 
53
  uploaded_file = st.file_uploader("πŸ“‚ Upload Excel file", type=["xlsx"])
54
 
55
- if uploaded_file and TOGETHER_API_KEY:
56
  df = pd.read_excel(uploaded_file)
57
  st.success(f"βœ… Loaded: {uploaded_file.name} with shape {df.shape}")
58
  st.dataframe(df.head(), use_container_width=True)
@@ -75,5 +78,6 @@ if uploaded_file and TOGETHER_API_KEY:
75
 
76
  except Exception as e:
77
  st.error(f"❌ Error: {e}")
78
- else:
79
- st.info("πŸ”‘ Please upload a file and provide the API key to continue.")
 
 
5
  import re
6
  import io
7
 
8
+ # πŸ” Handle Together API Key (from secrets or user input)
9
+ if "TOGETHER_API_KEY" in st.secrets:
10
+ TOGETHER_API_KEY = st.secrets["TOGETHER_API_KEY"]
11
+ else:
12
+ TOGETHER_API_KEY = st.text_input("πŸ” Enter Together API Key", type="password")
13
 
14
  # 🧠 Generate SQL using Together API
15
  def generate_sql_from_prompt(prompt, df):
 
55
 
56
  uploaded_file = st.file_uploader("πŸ“‚ Upload Excel file", type=["xlsx"])
57
 
58
+ if TOGETHER_API_KEY and uploaded_file:
59
  df = pd.read_excel(uploaded_file)
60
  st.success(f"βœ… Loaded: {uploaded_file.name} with shape {df.shape}")
61
  st.dataframe(df.head(), use_container_width=True)
 
78
 
79
  except Exception as e:
80
  st.error(f"❌ Error: {e}")
81
+
82
+ elif not TOGETHER_API_KEY:
83
+ st.warning("πŸ”‘ Please enter your Together API key to continue.")