awacke1 commited on
Commit
a88d27d
β€’
1 Parent(s): acc0c63

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -3
app.py CHANGED
@@ -4,6 +4,7 @@ import os
4
  import base64
5
  import glob
6
  import json
 
7
 
8
  from datetime import datetime
9
  from openai import ChatCompletion
@@ -71,7 +72,7 @@ def read_file_content(file):
71
  if file.type == "application/json":
72
  content = json.load(file)
73
  return str(content)
74
- elif file.type == "text/html":
75
  content = BeautifulSoup(file, "html.parser")
76
  return content.text
77
  elif file.type == "application/xml" or file.type == "text/xml":
@@ -79,7 +80,10 @@ def read_file_content(file):
79
  root = tree.getroot()
80
  #return ET.tostring(root, encoding='unicode')
81
  return CompressXML(ET.tostring(root, encoding='unicode'))
82
-
 
 
 
83
  elif file.type == "text/plain":
84
  return file.getvalue().decode()
85
  else:
@@ -92,7 +96,7 @@ def main():
92
  file_content = ""
93
 
94
  user_prompt = st.text_area("Your question:", '', height=120)
95
- uploaded_file = st.file_uploader("Choose a file", type=["xml", "json", "htm", "txt"])
96
 
97
  if user_prompt:
98
  prompts.append(user_prompt)
 
4
  import base64
5
  import glob
6
  import json
7
+ import mistune
8
 
9
  from datetime import datetime
10
  from openai import ChatCompletion
 
72
  if file.type == "application/json":
73
  content = json.load(file)
74
  return str(content)
75
+ elif file.type == "text/html" or file.type == "text/htm":
76
  content = BeautifulSoup(file, "html.parser")
77
  return content.text
78
  elif file.type == "application/xml" or file.type == "text/xml":
 
80
  root = tree.getroot()
81
  #return ET.tostring(root, encoding='unicode')
82
  return CompressXML(ET.tostring(root, encoding='unicode'))
83
+ elif file.type == "text/markdown" or file.type == "text/md":
84
+ md = mistune.create_markdown()
85
+ content = md(file.read().decode())
86
+ return content
87
  elif file.type == "text/plain":
88
  return file.getvalue().decode()
89
  else:
 
96
  file_content = ""
97
 
98
  user_prompt = st.text_area("Your question:", '', height=120)
99
+ uploaded_file = st.file_uploader("Choose a file", type=["xml", "json", "html", "htm", "md", "txt"])
100
 
101
  if user_prompt:
102
  prompts.append(user_prompt)