Spaces:
Runtime error
Runtime error
Commit
•
a0cb146
0
Parent(s):
Duplicate from AIZero2HeroBootcamp/Memory
Browse filesCo-authored-by: Aaron C Wacker <[email protected]>
- .gitattributes +35 -0
- README.md +13 -0
- app.py +102 -0
.gitattributes
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
28 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
---
|
2 |
+
title: Memory
|
3 |
+
emoji: 📚
|
4 |
+
colorFrom: pink
|
5 |
+
colorTo: indigo
|
6 |
+
sdk: streamlit
|
7 |
+
sdk_version: 1.21.0
|
8 |
+
app_file: app.py
|
9 |
+
pinned: false
|
10 |
+
duplicated_from: AIZero2HeroBootcamp/Memory
|
11 |
+
---
|
12 |
+
|
13 |
+
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
ADDED
@@ -0,0 +1,102 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
import pandas as pd
|
3 |
+
|
4 |
+
# Define functions
|
5 |
+
def create_empty_csv_files():
|
6 |
+
sem_df = pd.DataFrame(columns=["fact", "category", "source"])
|
7 |
+
sem_df.to_csv("semantic_memory.csv", index=False)
|
8 |
+
epi_df = pd.DataFrame(columns=["event", "sentiment", "date"])
|
9 |
+
epi_df.to_csv("episodic_memory.csv", index=False)
|
10 |
+
|
11 |
+
def load_data():
|
12 |
+
try:
|
13 |
+
sem_df = pd.read_csv("semantic_memory.csv")
|
14 |
+
sem_mem = sem_df.to_dict("records")
|
15 |
+
except:
|
16 |
+
create_empty_csv_files()
|
17 |
+
sem_mem = [{"fact": "The Earth is round", "category": "science", "source": "NASA"},
|
18 |
+
{"fact": "Pizza is delicious", "category": "food", "source": "me"}]
|
19 |
+
try:
|
20 |
+
epi_df = pd.read_csv("episodic_memory.csv")
|
21 |
+
epi_mem = epi_df.to_dict("records")
|
22 |
+
except:
|
23 |
+
create_empty_csv_files()
|
24 |
+
epi_mem = [{"event": "I went to the beach", "sentiment": "happy", "date": "2022-02-28"},
|
25 |
+
{"event": "I had a fight with my friend", "sentiment": "sad", "date": "2022-02-25"}]
|
26 |
+
return sem_mem, epi_mem
|
27 |
+
|
28 |
+
def save_data(sem_mem, epi_mem):
|
29 |
+
sem_df = pd.DataFrame(sem_mem)
|
30 |
+
sem_df.to_csv("semantic_memory.csv", index=False)
|
31 |
+
epi_df = pd.DataFrame(epi_mem)
|
32 |
+
epi_df.to_csv("episodic_memory.csv", index=False)
|
33 |
+
|
34 |
+
def view_semantic_memory(sem_mem):
|
35 |
+
st.write("# Semantic Memory")
|
36 |
+
for item in sem_mem:
|
37 |
+
st.write(f"**{item['fact']}** ({item['category']}) - {item['source']}")
|
38 |
+
|
39 |
+
def view_episodic_memory(epi_mem):
|
40 |
+
st.write("# Episodic Memory")
|
41 |
+
for item in epi_mem:
|
42 |
+
st.write(f"**{item['event']}** ({item['sentiment']}) - {item['date']}")
|
43 |
+
|
44 |
+
def add_fact(sem_mem, fact, category, source):
|
45 |
+
sem_mem.append({"fact": fact, "category": category, "source": source})
|
46 |
+
|
47 |
+
def add_event(epi_mem, event, sentiment, date):
|
48 |
+
epi_mem.append({"event": event, "sentiment": sentiment, "date": date})
|
49 |
+
|
50 |
+
def add_fact_to_semantic_memory(sem_mem, epi_mem):
|
51 |
+
fact = st.text_input("Enter a fact")
|
52 |
+
category = st.text_input("Enter a category")
|
53 |
+
source = st.text_input("Enter a source")
|
54 |
+
if st.button("Add Fact"):
|
55 |
+
add_fact(sem_mem, fact, category, source)
|
56 |
+
save_data(sem_mem, epi_mem)
|
57 |
+
st.success("Fact added to semantic memory!")
|
58 |
+
st.sidebar.success("Fact added to semantic memory!")
|
59 |
+
|
60 |
+
def add_event_to_episodic_memory(epi_mem, sem_mem):
|
61 |
+
event = st.text_input("Enter an event")
|
62 |
+
sentiment = st.selectbox("Select a sentiment", ["happy", "sad", "neutral"])
|
63 |
+
date = st.date_input("Select a date")
|
64 |
+
if st.button("Add Event"):
|
65 |
+
add_event(epi_mem, event, sentiment, date)
|
66 |
+
save_data(sem_mem, epi_mem)
|
67 |
+
st.success("Event added to episodic memory!")
|
68 |
+
st.sidebar.success("Event added to episodic memory!")
|
69 |
+
|
70 |
+
def run_app():
|
71 |
+
sem_mem, epi_mem = load_data()
|
72 |
+
|
73 |
+
st.title("Cognitive Agent")
|
74 |
+
option = st.sidebar.selectbox("Select an option",
|
75 |
+
["View Semantic Memory", "View Episodic Memory", "Add Fact to Semantic Memory",
|
76 |
+
"Add Event to Episodic Memory"])
|
77 |
+
|
78 |
+
if option == "View Semantic Memory":
|
79 |
+
view_semantic_memory(sem_mem)
|
80 |
+
elif option == "View Episodic Memory":
|
81 |
+
view_episodic_memory(epi_mem)
|
82 |
+
elif option == "Add Fact to Semantic Memory":
|
83 |
+
add_fact_to_semantic_memory(sem_mem, epi_mem)
|
84 |
+
elif option == "Add Event to Episodic Memory":
|
85 |
+
add_event_to_episodic_memory(epi_mem, sem_mem)
|
86 |
+
|
87 |
+
save_data(sem_mem, epi_mem)
|
88 |
+
|
89 |
+
if __name__ == '__main__':
|
90 |
+
run_app()
|
91 |
+
|
92 |
+
|
93 |
+
|
94 |
+
|
95 |
+
# AW: Restructure the code listing into four functions. shorten the code by eliminating comments and unnecessary whitespace and empty lines.
|
96 |
+
# AI: This revised code splits the app into four functions: load_data, save_data, add_fact, and add_event. The run_app function handles the logic of the Streamlit app and calls these other functions as necessary. The code has been shortened by removing unnecessary whitespace and comments, but retains its functionality.
|
97 |
+
|
98 |
+
|
99 |
+
# This program uses Streamlit to create a web app that allows the user to view and add to both semantic and episodic memory. The semantic memory is stored as a list of dictionaries, where each dictionary represents a fact and includes the fact itself, the category it belongs to, and the source of the fact. The episodic memory is also stored as a list of dictionaries, where each dictionary represents an event and includes the event itself, the sentiment associated with the event, and the date the event occurred.
|
100 |
+
# The program allows the user to view both types of memory by selecting an option from the sidebar. If the user selects "View Semantic Memory", the program displays all of the facts stored in semantic memory. If the user selects "View Episodic Memory", the program displays all of the events stored in episodic memory.
|
101 |
+
# The program also allows the user to add new facts to semantic memory or new events to episodic memory by selecting an option from the sidebar and filling out a form with the relevant information. When the user clicks the "Add Fact" or "Add Event" button, the new fact or event is added to the appropriate list of dictionaries and saved to a CSV file. The program then displays a success message indicating that the fact or event was added to memory.
|
102 |
+
# Overall, this program demonstrates how semantic and episodic memory can be modeled using Python list dictionaries, and how these types of memory can be used to track both facts and observations, as well as sentiments associated with past experiences.
|