awacke1 commited on
Commit
443263b
β€’
1 Parent(s): f1cfab3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -20
app.py CHANGED
@@ -4,7 +4,7 @@ import os
4
  import base64
5
  import glob
6
  import json
7
- from xml.etree import ElementTree as ET
8
  from datetime import datetime
9
  from dotenv import load_dotenv
10
  from openai import ChatCompletion
@@ -38,20 +38,6 @@ def get_table_download_link(file_path):
38
  href = f'<a href="data:file/htm;base64,{b64}" target="_blank" download="{os.path.basename(file_path)}">{os.path.basename(file_path)}</a>'
39
  return href
40
 
41
- def add_parent_info(elem, parent=None):
42
- for child in elem:
43
- child.parent = parent
44
- add_parent_info(child, parent=elem)
45
-
46
- def CompressXML(xml_text):
47
- root = ET.fromstring(xml_text)
48
- add_parent_info(root)
49
- for elem in list(root.iter()):
50
- if isinstance(elem.tag, str) and 'Comment' in elem.tag:
51
- elem.parent.remove(elem)
52
- return ET.tostring(root, encoding='unicode', method="xml")
53
-
54
-
55
  def read_file_content(file):
56
  if file.type == "application/json":
57
  content = json.load(file)
@@ -60,9 +46,9 @@ def read_file_content(file):
60
  content = BeautifulSoup(file, "html.parser")
61
  return content.text
62
  elif file.type == "application/xml" or file.type == "text/xml":
63
- xml_text = file.getvalue().decode()
64
- compressed_text = CompressXML(xml_text)
65
- return compressed_text
66
  elif file.type == "text/plain":
67
  return file.getvalue().decode()
68
  else:
@@ -81,7 +67,6 @@ def main():
81
 
82
  if uploaded_file is not None:
83
  file_content = read_file_content(uploaded_file)
84
- st.markdown(f"**Content Added to Prompt:**\n{file_content}")
85
  prompts.append(file_content)
86
 
87
  if st.button('Chat'):
@@ -100,7 +85,7 @@ def main():
100
  st.sidebar.markdown(get_table_download_link(file), unsafe_allow_html=True)
101
  if st.sidebar.button(f"Delete {file}"):
102
  os.remove(file)
 
103
 
104
  if __name__ == "__main__":
105
  main()
106
-
 
4
  import base64
5
  import glob
6
  import json
7
+ from xml.etree import ElementTree
8
  from datetime import datetime
9
  from dotenv import load_dotenv
10
  from openai import ChatCompletion
 
38
  href = f'<a href="data:file/htm;base64,{b64}" target="_blank" download="{os.path.basename(file_path)}">{os.path.basename(file_path)}</a>'
39
  return href
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
  def read_file_content(file):
42
  if file.type == "application/json":
43
  content = json.load(file)
 
46
  content = BeautifulSoup(file, "html.parser")
47
  return content.text
48
  elif file.type == "application/xml" or file.type == "text/xml":
49
+ tree = ElementTree.parse(file)
50
+ root = tree.getroot()
51
+ return ElementTree.tostring(root, encoding='unicode')
52
  elif file.type == "text/plain":
53
  return file.getvalue().decode()
54
  else:
 
67
 
68
  if uploaded_file is not None:
69
  file_content = read_file_content(uploaded_file)
 
70
  prompts.append(file_content)
71
 
72
  if st.button('Chat'):
 
85
  st.sidebar.markdown(get_table_download_link(file), unsafe_allow_html=True)
86
  if st.sidebar.button(f"Delete {file}"):
87
  os.remove(file)
88
+ st.experimental_rerun()
89
 
90
  if __name__ == "__main__":
91
  main()