Ezi Ozoani commited on
Commit
a111308
·
1 Parent(s): 4795a53

first push

Browse files
Files changed (5) hide show
  1. .gitattributes +1 -0
  2. Home.py +142 -0
  3. db.sqlite3 +0 -0
  4. pages/Contribute.py +79 -0
  5. requirements.txt +0 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* 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
 
 
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
36
+ *.sqlite filter=lfs diff=lfs merge=lfs -text
Home.py ADDED
@@ -0,0 +1,142 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import datetime
3
+ import json
4
+ import uuid
5
+ import streamlit as st
6
+ from streamlit_timeline import st_timeline
7
+ from sqlalchemy.sql import text
8
+
9
+ conn = st.experimental_connection(
10
+ "db",
11
+ type="sql",
12
+ url="sqlite:///db.sqlite3",
13
+ )
14
+ with conn.session as session:
15
+ # check if the table exists
16
+ session.execute(text("""
17
+ CREATE TABLE IF NOT EXISTS files (
18
+ id VARCHAR(255),
19
+ name VARCHAR(255),
20
+ tags VARCHAR(255),
21
+ content_type VARCHAR(255),
22
+ date DATETIME DEFAULT CURRENT_TIMESTAMP,
23
+ file LONGBLOB NOT NULL,
24
+ PRIMARY KEY (id)
25
+ )
26
+ """))
27
+ # commit the changes
28
+ session.commit()
29
+
30
+ def get_files(tags: str = "", min_date: datetime.date = None, max_date: datetime.date = None):
31
+ # get the files metadata from the database and search for files with the given tag
32
+ with conn.session as session:
33
+ if tags and min_date and max_date:
34
+ result = session.execute(text("""
35
+ SELECT id, name, tags, date
36
+ FROM files
37
+ WHERE (tags LIKE :tags AND date BETWEEN :min_date AND :max_date) OR (tags LIKE :tags AND date = :min_date OR tags LIKE :tags AND date = :max_date)
38
+ """), {
39
+ 'tags': f'%{tags}%',
40
+ 'min_date': min_date,
41
+ 'max_date': max_date
42
+ })
43
+ elif tags:
44
+ result = session.execute(text("""
45
+ SELECT id, name, tags, date
46
+ FROM files
47
+ WHERE tags LIKE :tags
48
+ """), {
49
+ 'tags': f'%{tags}%'
50
+ })
51
+ elif min_date and max_date:
52
+ # get the files where date is between min_date and max_date or is equal to min_date or max_date
53
+ result = session.execute(text("""
54
+ SELECT id, name, tags, date
55
+ FROM files
56
+ WHERE (date BETWEEN :min_date AND :max_date) OR (date = :min_date OR date = :max_date)
57
+ """), {
58
+ 'min_date': min_date,
59
+ 'max_date': max_date
60
+ })
61
+ else:
62
+ result = session.execute(text("""
63
+ SELECT id, name, tags, date
64
+ FROM files
65
+ """))
66
+ return result.fetchall()
67
+
68
+ def get_file(id):
69
+ # get the file from the database
70
+ with conn.session as session:
71
+
72
+ result = session.execute(text("""
73
+ SELECT file
74
+ FROM files
75
+ WHERE id = :id
76
+ """), {
77
+ 'id': id
78
+ })
79
+ file = result.fetchone()
80
+ return file[0]
81
+
82
+ def get_timeline(tags: str = "", min_date: datetime.date = None, max_date: datetime.date = None):
83
+ # get all the files from the database and format them for the timeline
84
+ return [
85
+ {
86
+ "id": file[0],
87
+ "content": f"{file[1]} - {file[2]}",
88
+ "start": file[3],
89
+ "name": file[1],
90
+ "tags": file[2],
91
+ }
92
+ for file in get_files(
93
+ tags=tag,
94
+ min_date=min_date,
95
+ max_date=max_date
96
+ )
97
+ ]
98
+
99
+
100
+ st.title('File sharing app')
101
+
102
+ # create an app that allows users to upload files and add tags to them
103
+ # the app should allow users to search for files by tag or date range
104
+ tag = st.text_input('Enter a tag to search for files')
105
+
106
+ min_date = datetime.date(1970, 1, 1)
107
+
108
+ # max range for the date picker
109
+ max_date = st.date_input('Enter the max date to search for files', value=datetime.date.today() + datetime.timedelta(days=1), min_value=min_date, max_value=datetime.date.today() + datetime.timedelta(days=1))
110
+
111
+ # min range for the date picker
112
+ min_date = st.date_input('Enter the min date to search for files', value=datetime.date(1970, 1, 1), min_value=datetime.date(1970, 1, 1), max_value=max_date)
113
+
114
+ # create a button to submit the form
115
+ if st.button('Search'):
116
+ items = get_timeline(tags=tag, min_date=min_date, max_date=max_date)
117
+ else:
118
+ items = get_timeline()
119
+
120
+
121
+ # the first page should be a timeline that would propegate different artifacts
122
+ # then they can filter using it to search or they can upload a new file
123
+
124
+ # get all the files from the database to display on the timeline
125
+ timeline = st_timeline(items, groups=[], options={}, height="300px")
126
+ st.subheader("Selected item")
127
+ # display the selected file
128
+ if timeline:
129
+ # display a container for the file
130
+ file_container = st.container()
131
+ # display the file name
132
+ file_container.markdown(f'**{timeline["name"]}**')
133
+ # display the file tags
134
+ file_container.markdown(f'*{"*, *".join(json.loads(timeline["tags"]))}*')
135
+ # display the file date
136
+ file_container.markdown(f'_{timeline["start"]}_')
137
+ # display the file
138
+ if timeline["name"] == "text":
139
+ file_container.markdown(f"```{get_file(timeline['id'])}```")
140
+ else:
141
+ file_container.video(get_file(timeline["id"]))
142
+
db.sqlite3 ADDED
Binary file (12.3 kB). View file
 
pages/Contribute.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import base64
2
+ import json
3
+ import uuid
4
+ import streamlit as st
5
+ import datetime
6
+ from sqlalchemy.sql import text
7
+
8
+ # connect to sqlite database
9
+ conn = st.experimental_connection(
10
+ "db",
11
+ type="sql",
12
+ url="sqlite:///db.sqlite3",
13
+ )
14
+ with conn.session as session:
15
+ # check if the table exists
16
+ session.execute(text("""
17
+ CREATE TABLE IF NOT EXISTS files (
18
+ id VARCHAR(255),
19
+ name VARCHAR(255),
20
+ tags VARCHAR(255),
21
+ content_type VARCHAR(255),
22
+ date DATETIME DEFAULT CURRENT_TIMESTAMP,
23
+ file LONGBLOB NOT NULL,
24
+ PRIMARY KEY (id)
25
+ )
26
+ """))
27
+ # commit the changes
28
+ session.commit()
29
+
30
+
31
+ def save_file(uploaded_file, tags, date, content_type):
32
+ with conn.session as session:
33
+
34
+ # save the file to the database
35
+ session.execute(text("""
36
+ INSERT INTO files (id, name, tags, content_type, date, file)
37
+ VALUES (:id, :name, :tags, :content_type, :date, :file)
38
+ """), {
39
+ 'id': str(uuid.uuid4()),
40
+ 'name': uploaded_file.name if not isinstance(uploaded_file, str) else 'text',
41
+ 'tags': json.dumps(tags),
42
+ "content_type": content_type,
43
+ 'date': date,
44
+ 'file': uploaded_file.read() if not isinstance(uploaded_file, str) else uploaded_file
45
+ })
46
+ # commit the changes
47
+ session.commit()
48
+
49
+
50
+
51
+ # the upload page should have a form that allows them to upload a file
52
+ # and add tags to it
53
+
54
+ st.title('Upload a video or text')
55
+
56
+ # ask the user if they want to upload a file or text
57
+ upload_type = st.radio('Do you want to upload a file or text?', ['Video', 'Text'])
58
+
59
+ if upload_type == 'Video':
60
+ # create a form to upload a file
61
+ uploaded_file = st.file_uploader("Choose a file file", type=['mp4', 'mov', 'avi', 'wmv', 'flv', 'mkv'])
62
+ else:
63
+ # create a form to write text
64
+ uploaded_file = st.text_area('Enter text')
65
+ # create a form to add tags to the file
66
+ tags = st.text_input('Enter tags for the file (separated by commas)')
67
+
68
+ tags = [tag.strip() for tag in tags.split(',') if tag.strip() != '']
69
+
70
+ # ask the user if this is a short content file or a long content file
71
+ content_type = st.radio('Is this a short content file or a long content file?', ['Short content', 'Long content'])
72
+
73
+ date = datetime.datetime.now()
74
+
75
+ # create a button to submit the form
76
+ if st.button('Upload'):
77
+ # save the file to the database
78
+ save_file(uploaded_file, tags, date, content_type)
79
+ st.success('Uploaded successfully')
requirements.txt ADDED
Binary file (2.1 kB). View file