AmandaHattaway commited on
Commit
153a255
Β·
verified Β·
1 Parent(s): cc3beaa

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +10 -37
src/streamlit_app.py CHANGED
@@ -12,69 +12,42 @@ st.set_page_config(
12
 
13
  @st.cache_resource
14
  def get_snowflake_connection():
15
- """Create and cache Snowflake connection using private key"""
16
  try:
17
  # Get credentials from environment variables (Hugging Face secrets)
18
  user = os.environ.get("SNOWFLAKE_USER")
 
19
  account = os.environ.get("SNOWFLAKE_ACCOUNT")
20
  warehouse = os.environ.get("SNOWFLAKE_WAREHOUSE")
21
- #private_key_string = os.environ.get("SNOWFLAKE_PRIVATE_KEY")
22
- private_key_passphrase = os.environ.get("SNOWFLAKE_PASSPHRASE")
23
 
24
  # Debug: Show what we found (without exposing sensitive data)
25
  st.write("πŸ” Debug Info:")
26
  st.write(f"- User found: {'βœ…' if user else '❌'}")
 
27
  st.write(f"- Account found: {'βœ…' if account else '❌'}")
28
  st.write(f"- Warehouse found: {'βœ…' if warehouse else '❌'}")
29
- st.write(f"- Private key found: {'βœ…' if private_key_string else '❌'}")
30
 
31
- if not all([user, account, warehouse, private_key_string]):
32
  missing = []
33
  if not user: missing.append("SNOWFLAKE_USER")
 
34
  if not account: missing.append("SNOWFLAKE_ACCOUNT")
35
  if not warehouse: missing.append("SNOWFLAKE_WAREHOUSE")
36
- if not private_key_string: missing.append("SNOWFLAKE_PRIVATE_KEY")
37
 
38
  st.error(f"❌ Missing environment variables: {', '.join(missing)}")
39
  st.info("πŸ’‘ Please add these as Repository Secrets in your Hugging Face Space settings.")
40
  return None
41
 
42
- # Import crypto libraries for private key handling
43
- from cryptography.hazmat.primitives import serialization
44
- from cryptography.hazmat.primitives.serialization import load_pem_private_key
45
-
46
- # Convert the private key string to bytes and load it
47
- private_key_bytes = private_key_string.encode('utf-8')
48
-
49
- # Load the private key (with or without passphrase)
50
- if private_key_passphrase:
51
- private_key = load_pem_private_key(
52
- private_key_bytes,
53
- password=private_key_passphrase.encode('utf-8')
54
- )
55
- else:
56
- private_key = load_pem_private_key(
57
- private_key_bytes,
58
- password=None
59
- )
60
-
61
- # Serialize the private key to DER format for Snowflake
62
- private_key_der = private_key.private_bytes(
63
- encoding=serialization.Encoding.DER,
64
- format=serialization.PrivateFormat.PKCS8,
65
- encryption_algorithm=serialization.NoEncryption()
66
- )
67
-
68
  st.write("πŸ”‘ Attempting Snowflake connection...")
69
 
70
- # Connect using private key authentication
71
  conn = snowflake.connector.connect(
72
  user=user,
 
73
  account=account,
74
  warehouse=warehouse,
75
  database="sennos_interview_prep",
76
- schema="public",
77
- private_key=private_key_der
78
  )
79
 
80
  st.success("βœ… Successfully connected to Snowflake!")
@@ -83,10 +56,10 @@ def get_snowflake_connection():
83
  except Exception as e:
84
  st.error(f"❌ Failed to connect to Snowflake: {str(e)}")
85
  st.write("**Possible issues:**")
86
- st.write("- Check that your private key is correctly formatted")
87
  st.write("- Verify your Snowflake account identifier")
88
  st.write("- Ensure the user has proper permissions")
89
- st.write("- Check if the warehouse is running")
90
  return None
91
 
92
  def make_prediction(batch_id, temp_mean, temp_std, ph_mean, ph_std,
 
12
 
13
  @st.cache_resource
14
  def get_snowflake_connection():
15
+ """Create and cache Snowflake connection using password"""
16
  try:
17
  # Get credentials from environment variables (Hugging Face secrets)
18
  user = os.environ.get("SNOWFLAKE_USER")
19
+ password = os.environ.get("SNOWFLAKE_PASSWORD")
20
  account = os.environ.get("SNOWFLAKE_ACCOUNT")
21
  warehouse = os.environ.get("SNOWFLAKE_WAREHOUSE")
 
 
22
 
23
  # Debug: Show what we found (without exposing sensitive data)
24
  st.write("πŸ” Debug Info:")
25
  st.write(f"- User found: {'βœ…' if user else '❌'}")
26
+ st.write(f"- Password found: {'βœ…' if password else '❌'}")
27
  st.write(f"- Account found: {'βœ…' if account else '❌'}")
28
  st.write(f"- Warehouse found: {'βœ…' if warehouse else '❌'}")
 
29
 
30
+ if not all([user, password, account, warehouse]):
31
  missing = []
32
  if not user: missing.append("SNOWFLAKE_USER")
33
+ if not password: missing.append("SNOWFLAKE_PASSWORD")
34
  if not account: missing.append("SNOWFLAKE_ACCOUNT")
35
  if not warehouse: missing.append("SNOWFLAKE_WAREHOUSE")
 
36
 
37
  st.error(f"❌ Missing environment variables: {', '.join(missing)}")
38
  st.info("πŸ’‘ Please add these as Repository Secrets in your Hugging Face Space settings.")
39
  return None
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  st.write("πŸ”‘ Attempting Snowflake connection...")
42
 
43
+ # Connect using password authentication
44
  conn = snowflake.connector.connect(
45
  user=user,
46
+ password=password,
47
  account=account,
48
  warehouse=warehouse,
49
  database="sennos_interview_prep",
50
+ schema="public"
 
51
  )
52
 
53
  st.success("βœ… Successfully connected to Snowflake!")
 
56
  except Exception as e:
57
  st.error(f"❌ Failed to connect to Snowflake: {str(e)}")
58
  st.write("**Possible issues:**")
59
+ st.write("- Check that your password is correct")
60
  st.write("- Verify your Snowflake account identifier")
61
  st.write("- Ensure the user has proper permissions")
62
+ st.write("- Check if the warehouse exists and is accessible")
63
  return None
64
 
65
  def make_prediction(batch_id, temp_mean, temp_std, ph_mean, ph_std,