awacke1 commited on
Commit
2e67686
β€’
1 Parent(s): d3f3e34

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -35
app.py CHANGED
@@ -11,49 +11,32 @@ from datetime import datetime
11
  from openai import ChatCompletion
12
  from xml.etree import ElementTree as ET
13
  from bs4 import BeautifulSoup
14
- #from streamlit.theme import Theme
15
 
16
  openai.api_key = os.getenv('OPENAI_KEY')
17
- #st.set_page_config(page_title='GPT Streamlit Document Reasoner', layout='wide')
18
-
19
  st.set_page_config(
20
  page_title="GPT Streamlit Document Reasoner",
21
- layout="wide",
22
- # theme=Theme(
23
- # primary_color="#F63366",
24
- # secondary_background_color="#F0F2F6",
25
- # text_color="#262730",
26
- # font="sans serif",
27
- # ),
28
- )
29
  st.title("Chat with AI")
30
 
31
- # Create a sidebar with menus
32
- # st.sidebar.title("Menu")
33
- # menu = ["Option 1", "Option 2", "Option 3"]
34
- # choice = st.sidebar.selectbox("Choose an option", menu)
35
-
36
- # if choice == "Option 1":
37
- # st.sidebar.write("You selected Option 1")
38
- #elif choice == "Option 2":
39
- # st.sidebar.write("You selected Option 2")
40
- #elif choice == "Option 3":
41
- # st.sidebar.write("You selected Option 3")
42
-
43
- # Create a slider in the sidebar
44
- max_length = st.sidebar.slider(
45
- "Max document length", min_value=3000, max_value=24000, value=3000, step=1000
46
- )
47
 
48
  # Truncate document
49
  def truncate_document(document, length):
50
  return document[:length]
51
 
52
- # Assume you have a document called my_document
53
- # my_document = 'your long string here'
54
- # truncated_document = truncate_document(my_document, max_length)
55
- # st.write(f"Truncated document: {truncated_document}")
56
-
57
  def chat_with_model(prompts):
58
  model = "gpt-3.5-turbo"
59
  #model = "gpt-4-32k" # 32k tokens between prompt and inference tokens
@@ -108,7 +91,6 @@ def CompressXML(xml_text):
108
  #return ET.tostring(root, encoding='unicode', method="xml")
109
  return ET.tostring(root, encoding='unicode', method="xml")[:max_length]
110
 
111
-
112
  def read_file_content(file):
113
  if file.type == "application/json":
114
  content = json.load(file)
@@ -131,10 +113,8 @@ def read_file_content(file):
131
  return ""
132
 
133
  def main():
134
-
135
  prompts = ['']
136
  file_content = ""
137
-
138
  user_prompt = st.text_area("Your question:", '', height=120)
139
  uploaded_file = st.file_uploader("Choose a file", type=["xml", "json", "html", "htm", "md", "txt"])
140
 
 
11
  from openai import ChatCompletion
12
  from xml.etree import ElementTree as ET
13
  from bs4 import BeautifulSoup
 
14
 
15
  openai.api_key = os.getenv('OPENAI_KEY')
 
 
16
  st.set_page_config(
17
  page_title="GPT Streamlit Document Reasoner",
18
+ layout="wide")
 
 
 
 
 
 
 
19
  st.title("Chat with AI")
20
 
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.")
28
+ elif choice == "htm":
29
+ st.sidebar.write(choicePrefix + "HTML5.")
30
+ elif choice == "md":
31
+ st.sidebar.write(choicePrefix + "Markdown.")
32
+
33
+ # sidebar slider for file input length to include in inference blocks
34
+ max_length = st.sidebar.slider("Max document length", min_value=1000, max_value=32000, value=3000, step=1000)
 
 
35
 
36
  # Truncate document
37
  def truncate_document(document, length):
38
  return document[:length]
39
 
 
 
 
 
 
40
  def chat_with_model(prompts):
41
  model = "gpt-3.5-turbo"
42
  #model = "gpt-4-32k" # 32k tokens between prompt and inference tokens
 
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):
95
  if file.type == "application/json":
96
  content = json.load(file)
 
113
  return ""
114
 
115
  def main():
 
116
  prompts = ['']
117
  file_content = ""
 
118
  user_prompt = st.text_area("Your question:", '', height=120)
119
  uploaded_file = st.file_uploader("Choose a file", type=["xml", "json", "html", "htm", "md", "txt"])
120