awacke1 commited on
Commit
49e8bc7
β€’
1 Parent(s): 809b6f3

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -7
app.py CHANGED
@@ -21,7 +21,7 @@ st.title("GPT Chat with Optional File Context - Talk to your data!")
21
  # Output options sidebar menu
22
  st.sidebar.title("Output Options")
23
  menu = ["txt", "htm", "md"]
24
- choice = st.sidebar.selectbox("Choose an output file type to save your prompt and results", menu)
25
  choicePrefix = "Output and download file set to "
26
  if choice == "txt":
27
  st.sidebar.write(choicePrefix + "Text file.")
@@ -83,12 +83,11 @@ def get_table_download_link(file_path):
83
  href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
84
  return href
85
 
86
- def CompressXML(xml_text):
87
  root = ET.fromstring(xml_text)
88
  for elem in list(root.iter()):
89
  if isinstance(elem.tag, str) and 'Comment' in elem.tag:
90
  elem.parent.remove(elem)
91
- #return ET.tostring(root, encoding='unicode', method="xml")
92
  return ET.tostring(root, encoding='unicode', method="xml")[:max_length]
93
 
94
  def read_file_content(file):
@@ -102,7 +101,7 @@ def read_file_content(file):
102
  tree = ET.parse(file)
103
  root = tree.getroot()
104
  #return ET.tostring(root, encoding='unicode')
105
- return CompressXML(ET.tostring(root, encoding='unicode'))
106
  elif file.type == "text/markdown" or file.type == "text/md":
107
  md = mistune.create_markdown()
108
  content = md(file.read().decode())
@@ -136,13 +135,12 @@ def main():
136
  st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
137
 
138
  if len(file_content) > 0:
139
- st.markdown(f"**Content Added to Prompt:**\n{file_content}")
140
 
141
  htm_files = glob.glob("*.txt")
142
  for file in htm_files:
143
  st.sidebar.markdown(get_table_download_link(file), unsafe_allow_html=True)
144
- if st.sidebar.button(f"πŸ—‘Delete {file}"):
145
- #if st.sidebar.button("πŸ—‘ Delete"):
146
  os.remove(file)
147
  st.experimental_rerun()
148
 
 
21
  # Output options sidebar menu
22
  st.sidebar.title("Output Options")
23
  menu = ["txt", "htm", "md"]
24
+ choice = st.sidebar.selectbox("Choose output file type to save results", menu)
25
  choicePrefix = "Output and download file set to "
26
  if choice == "txt":
27
  st.sidebar.write(choicePrefix + "Text file.")
 
83
  href = f'<a href="data:{mime_type};base64,{b64}" target="_blank" download="{file_name}">{file_name}</a>'
84
  return href
85
 
86
+ def CompressXML(xml_text, max_length):
87
  root = ET.fromstring(xml_text)
88
  for elem in list(root.iter()):
89
  if isinstance(elem.tag, str) and 'Comment' in elem.tag:
90
  elem.parent.remove(elem)
 
91
  return ET.tostring(root, encoding='unicode', method="xml")[:max_length]
92
 
93
  def read_file_content(file):
 
101
  tree = ET.parse(file)
102
  root = tree.getroot()
103
  #return ET.tostring(root, encoding='unicode')
104
+ return CompressXML(ET.tostring(root, encoding='unicode',max_length))
105
  elif file.type == "text/markdown" or file.type == "text/md":
106
  md = mistune.create_markdown()
107
  content = md(file.read().decode())
 
135
  st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
136
 
137
  if len(file_content) > 0:
138
+ st.markdown(f"**File Content Added:**\n{file_content}")
139
 
140
  htm_files = glob.glob("*.txt")
141
  for file in htm_files:
142
  st.sidebar.markdown(get_table_download_link(file), unsafe_allow_html=True)
143
+ if st.sidebar.button(f"πŸ—‘ Delete {file}"):
 
144
  os.remove(file)
145
  st.experimental_rerun()
146