page1
import streamlit as st
import pandas as pd
import os
import os
import importlib.util
def run_app(filepath):
spec=importlib.util.spec_from_file_location("contacts_app",filepath)
second_app=importlib.util.module_from_spec(spec)
spec.loader.exec_module(second_app)
second_app,main()
Define the path to the Excel file
excel_file = 'snippets_data.xlsx'
Function to load data from the Excel file
def load_data():
if os.path.exists(excel_file):
return pd.read_csv(excel_file)
else:
return pd.DataFrame(columns=['Title', 'Info', 'Objective', 'Details', 'Remarks'])
Function to save data to the Excel file
def save_data(df):
df.to_excel(excel_file, index=False)
Load existing data
data = load_data()
Page 1: Data Entry
def data_entry():
st.title("Snippets")
title = st.text_input("Title of the entry", max_chars=200)
info = st.text_input("Info", max_chars=100)
objective = st.text_input("Objective entry", max_chars=500)
details = st.text_area("Details entry", max_chars=10000)
remarks = st.text_input("Remarks", max_chars=1000)
if st.button("Submit"):
new_entry = pd.DataFrame({
'Title': [title],
'Info': [info],
'Objective': [objective],
'Details': [details],
'Remarks': [remarks]
})
data = load_data()
data = pd.concat([data, new_entry], ignore_index=True)
save_data(data)
st.success("Data entry saved successfully!")
Page 2: View Entries
def view_entries():
st.title("View Existing Data Entries")
if data.empty:
st.write("No entries found.")
else:
for index, row in data.iterrows():
st.markdown(f"[{row['Title']}]({row['Title']})")
if st.button(f"View {row['Title']}"):
st.write(f"**Info:** {row['Info']}")
st.write(f"**Objective:** {row['Objective']}")
st.write(f"**Details:** {row['Details']}")
st.write(f"**Remarks:** {row['Remarks']}")
Page 3: Edit Entries
def edit_entries():
st.title("Edit Data Entry")
entry_titles = data['Title'].tolist()
selected_entry = st.selectbox("Select an entry to edit", entry_titles)
if selected_entry:
entry_data = data[data['Title'] == selected_entry].iloc[0]
title = st.text_input("Title of the entry", value=entry_data['Title'], max_chars=200)
info = st.text_input("Info", value=entry_data['Info'], max_chars=100)
objective = st.text_input("Objective entry", value=entry_data['Objective'], max_chars=500)
details = st.text_area("Details entry", value=entry_data['Details'], max_chars=5000)
remarks = st.text_input("Remarks", value=entry_data['Remarks'], max_chars=1000)
if st.button("Submit"):
data.loc[data['Title'] == selected_entry, ['Title', 'Info', 'Objective', 'Details', 'Remarks']] = [title, info, objective, details, remarks]
save_data(data)
st.success("Data entry updated successfully!")
Main function to control the app
def main():
st.sidebar.title("Navigation")
page = st.sidebar.radio("SNIPPETS", ["Data Entry", "View Entries", "Edit Entries", "call_contacts"], key="key1")
page2=st.sidebar.selectbox("CONTACTS",["call_contacts"])
if page == "Data Entry":
data_entry()
elif page == "View Entries":
view_entries()
elif page == "Edit Entries":
edit_entries()
if page=="call_contacts":
run_app("page2.py")
if name == "main":
main()