awacke1 commited on
Commit
4e5098f
β€’
1 Parent(s): a06050e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -16
app.py CHANGED
@@ -4,7 +4,6 @@ import os
4
  import base64
5
  import glob
6
  import json
7
- import re
8
  from xml.etree import ElementTree as ET
9
  from datetime import datetime
10
  from dotenv import load_dotenv
@@ -39,12 +38,6 @@ def get_table_download_link(file_path):
39
  href = f'<a href="data:file/htm;base64,{b64}" target="_blank" download="{os.path.basename(file_path)}">{os.path.basename(file_path)}</a>'
40
  return href
41
 
42
- def CompressXML_Old(xml_text):
43
- words = xml_text.split()
44
- english_words = [word for word in words if re.fullmatch(r'[A-Za-z ]*', word)]
45
- compressed_text = ' '.join(english_words)
46
- return compressed_text
47
-
48
  def CompressXML(xml_text):
49
  tree = ET.ElementTree(ET.fromstring(xml_text))
50
  for elem in tree.iter():
@@ -59,15 +52,10 @@ def read_file_content(file):
59
  elif file.type == "text/html":
60
  content = BeautifulSoup(file, "html.parser")
61
  return content.text
62
- elif file.type == "application/xmlold" or file.type == "text/xmlold":
63
- tree = ElementTree.parse(file)
64
- root = tree.getroot()
65
- return ElementTree.tostring(root, encoding='unicode')
66
  elif file.type == "application/xml" or file.type == "text/xml":
67
- tree = ElementTree.parse(file)
68
- root = tree.getroot()
69
- xml_text = ElementTree.tostring(root, encoding='unicode')
70
- return CompressXML(xml_text)
71
  elif file.type == "text/plain":
72
  return file.getvalue().decode()
73
  else:
@@ -86,6 +74,7 @@ def main():
86
 
87
  if uploaded_file is not None:
88
  file_content = read_file_content(uploaded_file)
 
89
  prompts.append(file_content)
90
 
91
  if st.button('Chat'):
@@ -104,7 +93,6 @@ def main():
104
  st.sidebar.markdown(get_table_download_link(file), unsafe_allow_html=True)
105
  if st.sidebar.button(f"Delete {file}"):
106
  os.remove(file)
107
- st.experimental_rerun()
108
 
109
  if __name__ == "__main__":
110
  main()
 
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
 
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 CompressXML(xml_text):
42
  tree = ET.ElementTree(ET.fromstring(xml_text))
43
  for elem in tree.iter():
 
52
  elif file.type == "text/html":
53
  content = BeautifulSoup(file, "html.parser")
54
  return content.text
 
 
 
 
55
  elif file.type == "application/xml" or file.type == "text/xml":
56
+ xml_text = file.getvalue().decode()
57
+ compressed_text = CompressXML(xml_text)
58
+ return compressed_text
 
59
  elif file.type == "text/plain":
60
  return file.getvalue().decode()
61
  else:
 
74
 
75
  if uploaded_file is not None:
76
  file_content = read_file_content(uploaded_file)
77
+ st.markdown(f"**Content Added to Prompt:**\n{file_content}")
78
  prompts.append(file_content)
79
 
80
  if st.button('Chat'):
 
93
  st.sidebar.markdown(get_table_download_link(file), unsafe_allow_html=True)
94
  if st.sidebar.button(f"Delete {file}"):
95
  os.remove(file)
 
96
 
97
  if __name__ == "__main__":
98
  main()