Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -79,6 +79,7 @@ def truncate_document(document, length):
|
|
79 |
return document[:length]
|
80 |
def divide_document(document, max_length):
|
81 |
return [document[i:i+max_length] for i in range(0, len(document), max_length)]
|
|
|
82 |
def get_table_download_link(file_path):
|
83 |
with open(file_path, 'r') as file:
|
84 |
data = file.read()
|
@@ -102,11 +103,6 @@ def get_table_download_link(file_path):
|
|
102 |
href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
|
103 |
return href
|
104 |
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
def CompressXML(xml_text):
|
111 |
root = ET.fromstring(xml_text)
|
112 |
for elem in list(root.iter()):
|
@@ -216,31 +212,31 @@ def main():
|
|
216 |
all_files = glob.glob("*.*")
|
217 |
all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 20] # exclude files with short names
|
218 |
all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
|
219 |
-
|
|
|
220 |
for file in all_files:
|
221 |
-
|
|
|
222 |
with col1:
|
223 |
-
|
224 |
st.markdown(get_table_download_link(file), unsafe_allow_html=True)
|
225 |
-
|
226 |
if st.button("π", key="read_"+file): # search emoji button
|
227 |
-
|
228 |
-
|
229 |
-
file_content_area = st.text_area("File Contents:", file_contents, height=100)
|
230 |
-
if st.button('π¬ Chat with file content'):
|
231 |
-
st.write('Reasoning with your inputs...')
|
232 |
-
response = chat_with_file_contents(user_prompt, file_contents)
|
233 |
-
st.write('Response:')
|
234 |
-
st.write(response)
|
235 |
-
|
236 |
-
filename = generate_filename(user_prompt, choice)
|
237 |
-
create_file(filename, user_prompt, response)
|
238 |
-
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
239 |
-
|
240 |
with col3:
|
241 |
if st.button("π", key="delete_"+file):
|
242 |
os.remove(file)
|
243 |
st.experimental_rerun()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
244 |
|
245 |
if __name__ == "__main__":
|
246 |
main()
|
|
|
79 |
return document[:length]
|
80 |
def divide_document(document, max_length):
|
81 |
return [document[i:i+max_length] for i in range(0, len(document), max_length)]
|
82 |
+
|
83 |
def get_table_download_link(file_path):
|
84 |
with open(file_path, 'r') as file:
|
85 |
data = file.read()
|
|
|
103 |
href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
|
104 |
return href
|
105 |
|
|
|
|
|
|
|
|
|
|
|
106 |
def CompressXML(xml_text):
|
107 |
root = ET.fromstring(xml_text)
|
108 |
for elem in list(root.iter()):
|
|
|
212 |
all_files = glob.glob("*.*")
|
213 |
all_files = [file for file in all_files if len(os.path.splitext(file)[0]) >= 20] # exclude files with short names
|
214 |
all_files.sort(key=lambda x: (os.path.splitext(x)[1], x), reverse=True) # sort by file type and file name in descending order
|
215 |
+
|
216 |
+
# sidebar of files
|
217 |
for file in all_files:
|
218 |
+
file_contents=''
|
219 |
+
col1, col2, col3 = st.sidebar.columns([5,1,1]) # adjust the ratio as needed
|
220 |
with col1:
|
|
|
221 |
st.markdown(get_table_download_link(file), unsafe_allow_html=True)
|
222 |
+
with col2:
|
223 |
if st.button("π", key="read_"+file): # search emoji button
|
224 |
+
with open(file, 'r') as f:
|
225 |
+
file_contents = f.read()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
226 |
with col3:
|
227 |
if st.button("π", key="delete_"+file):
|
228 |
os.remove(file)
|
229 |
st.experimental_rerun()
|
230 |
+
if len(file_contents) > 0:
|
231 |
+
file_content_area = st.text_area("File Contents:", file_contents, height=100)
|
232 |
+
if st.button('π¬ Chat with file content'):
|
233 |
+
st.write('Reasoning with your inputs...')
|
234 |
+
response = chat_with_file_contents(file_content_area)
|
235 |
+
st.write('Response:')
|
236 |
+
st.write(response)
|
237 |
+
filename = generate_filename(file_content_area, choice)
|
238 |
+
create_file(filename, file_content_area, response)
|
239 |
+
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
240 |
|
241 |
if __name__ == "__main__":
|
242 |
main()
|