Spaces:
Running
Running
James McCool
Refactor Dockerfile to remove the Bearer token curl request and update Streamlit app to retrieve MongoDB URI from environment variables instead of secrets. This change enhances security and simplifies the connection process.
12ff34e
import numpy as np | |
import pandas as pd | |
import streamlit as st | |
import pymongo | |
import os | |
st.set_page_config(layout="wide") | |
def init_conn(): | |
uri = os.getenv('mongo_uri') | |
client = pymongo.MongoClient(uri, retryWrites=True, serverSelectionTimeoutMS=500000) | |
db = client["MLB_Database"] | |
return db | |
db = init_conn() | |
def init_baselines(): | |
collection = db["HR_Table"] | |
cursor = collection.find() | |
raw_display = pd.DataFrame(cursor) | |
raw_display.rename(columns={"Names": "Player"}, inplace = True) | |
raw_frame = raw_display.drop_duplicates(subset='Player') | |
return raw_frame | |
hr_frame = init_baselines() | |
st.title("HR Finder Table") | |
st.dataframe(hr_frame, use_container_width = True, hide_index = True) |