|
import streamlit as st |
|
import pandas as pd |
|
|
|
|
|
def create_empty_csv_files(): |
|
sem_df = pd.DataFrame(columns=["fact", "category", "source"]) |
|
sem_df.to_csv("semantic_memory.csv", index=False) |
|
epi_df = pd.DataFrame(columns=["event", "sentiment", "date"]) |
|
epi_df.to_csv("episodic_memory.csv", index=False) |
|
|
|
def load_data(): |
|
try: |
|
sem_df = pd.read_csv("semantic_memory.csv") |
|
sem_mem = sem_df.to_dict("records") |
|
except: |
|
create_empty_csv_files() |
|
sem_mem = [{"fact": "The Earth is round", "category": "science", "source": "NASA"}, |
|
{"fact": "Pizza is delicious", "category": "food", "source": "me"}] |
|
try: |
|
epi_df = pd.read_csv("episodic_memory.csv") |
|
epi_mem = epi_df.to_dict("records") |
|
except: |
|
create_empty_csv_files() |
|
epi_mem = [{"event": "I went to the beach", "sentiment": "happy", "date": "2022-02-28"}, |
|
{"event": "I had a fight with my friend", "sentiment": "sad", "date": "2022-02-25"}] |
|
return sem_mem, epi_mem |
|
|
|
def save_data(sem_mem, epi_mem): |
|
sem_df = pd.DataFrame(sem_mem) |
|
sem_df.to_csv("semantic_memory.csv", index=False) |
|
epi_df = pd.DataFrame(epi_mem) |
|
epi_df.to_csv("episodic_memory.csv", index=False) |
|
|
|
def view_semantic_memory(sem_mem): |
|
st.write("# Semantic Memory") |
|
for item in sem_mem: |
|
st.write(f"**{item['fact']}** ({item['category']}) - {item['source']}") |
|
|
|
def view_episodic_memory(epi_mem): |
|
st.write("# Episodic Memory") |
|
for item in epi_mem: |
|
st.write(f"**{item['event']}** ({item['sentiment']}) - {item['date']}") |
|
|
|
def add_fact(sem_mem, fact, category, source): |
|
sem_mem.append({"fact": fact, "category": category, "source": source}) |
|
|
|
def add_event(epi_mem, event, sentiment, date): |
|
epi_mem.append({"event": event, "sentiment": sentiment, "date": date}) |
|
|
|
def add_fact_to_semantic_memory(sem_mem, epi_mem): |
|
fact = st.text_input("Enter a fact") |
|
category = st.text_input("Enter a category") |
|
source = st.text_input("Enter a source") |
|
if st.button("Add Fact"): |
|
add_fact(sem_mem, fact, category, source) |
|
save_data(sem_mem, epi_mem) |
|
st.success("Fact added to semantic memory!") |
|
st.sidebar.success("Fact added to semantic memory!") |
|
|
|
def add_event_to_episodic_memory(epi_mem, sem_mem): |
|
event = st.text_input("Enter an event") |
|
sentiment = st.selectbox("Select a sentiment", ["happy", "sad", "neutral"]) |
|
date = st.date_input("Select a date") |
|
if st.button("Add Event"): |
|
add_event(epi_mem, event, sentiment, date) |
|
save_data(sem_mem, epi_mem) |
|
st.success("Event added to episodic memory!") |
|
st.sidebar.success("Event added to episodic memory!") |
|
|
|
def run_app(): |
|
sem_mem, epi_mem = load_data() |
|
|
|
st.title("Cognitive Agent") |
|
option = st.sidebar.selectbox("Select an option", |
|
["View Semantic Memory", "View Episodic Memory", "Add Fact to Semantic Memory", |
|
"Add Event to Episodic Memory"]) |
|
|
|
if option == "View Semantic Memory": |
|
view_semantic_memory(sem_mem) |
|
elif option == "View Episodic Memory": |
|
view_episodic_memory(epi_mem) |
|
elif option == "Add Fact to Semantic Memory": |
|
add_fact_to_semantic_memory(sem_mem, epi_mem) |
|
elif option == "Add Event to Episodic Memory": |
|
add_event_to_episodic_memory(epi_mem, sem_mem) |
|
|
|
save_data(sem_mem, epi_mem) |
|
|
|
if __name__ == '__main__': |
|
run_app() |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|