Skip to content

Commit

Permalink
fix: db key that enable title change. tested locally
Browse files Browse the repository at this point in the history
  • Loading branch information
ghostleek committed Nov 9, 2024
1 parent 15f57d6 commit 5367fbd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
20 changes: 18 additions & 2 deletions app/db/database_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,22 @@ def initialize_db():
ON CONFLICT (id) DO NOTHING;
""")

# Initialize app_title table
cur.execute("""
CREATE TABLE IF NOT EXISTS app_title (
id SERIAL PRIMARY KEY,
description TEXT
);
""")

# Ensure there is always one row in app_title to update
cur.execute("""
INSERT INTO app_title (id, description)
VALUES (1, 'CherGPT')
ON CONFLICT (id) DO NOTHING;
""")


conn.commit()
except Exception as e:
logging.error(f"Error initializing database: {e}")
Expand Down Expand Up @@ -97,7 +113,7 @@ def get_app_title():

try:
with conn.cursor() as cur:
cur.execute("SELECT title FROM app_title WHERE id = 1;")
cur.execute("SELECT description FROM app_title WHERE id = 1;")
description = cur.fetchone()
if description:
return description[0]
Expand All @@ -106,7 +122,7 @@ def get_app_title():

except Exception as e:
logging.error(f"Error fetching app title: {e}")
return "CherGPT."
return "CherGPT"
finally:
if conn:
conn.close()
Expand Down
2 changes: 1 addition & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from app.instructions.instructions_handler import get_latest_instructions
import uuid

app_title = get_app_title() or "CherGPT"
app_title = get_app_title()
app_description = get_app_description() or "Chatbot to support teaching and learning"
st.title(app_title)
# Initialize session state for admin
Expand Down
9 changes: 5 additions & 4 deletions sidebar.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
import streamlit as st
from app.chatlog.chatlog_handler import compile_summaries, delete_all_chatlogs, export_chat_logs_to_csv, drop_chatlog_table, fetch_and_batch_chatlogs, generate_summary_for_each_group
from app.instructions.instructions_handler import get_latest_instructions, update_instructions
from app.db.database_connection import drop_instructions_table, get_app_description, update_app_description
from app.db.database_connection import drop_instructions_table, get_app_description, update_app_description, get_app_title, update_app_title
custominstructions_area_height = 300
app_title = get_app_title()
app_description = get_app_description()

def load_summaries():
# Placeholder function call - replace with actual function logic
batches = fetch_and_batch_chatlogs()
group_summaries = generate_summary_for_each_group(batches)
group_summaries = generate_summary_for_each_group(batches)
final_summary_output = compile_summaries(group_summaries)
return final_summary_output

Expand All @@ -32,13 +33,13 @@ def setup_sidebar():
if st.button("Update title", key="save_app_title"):
# Update the app description in the database
update_app_title(editable_title)
st.success("App description updated successfully")
st.success("App title updated successfully")
# Check if the user is an admin to provide editing capability
# Provide a text area for admins to edit the app description
with st.expander("⚙️ Edit description"):
editable_description = st.text_area("This amends text below title", value=app_description, key="app_description")
# Button to save the updated app description
if st.button("Update description", key="save_app_title"):
if st.button("Update description", key="save_app_description"):
# Update the app description in the database
update_app_description(editable_description)
st.success("App description updated successfully")
Expand Down

0 comments on commit 5367fbd

Please sign in to comment.