awacke1 commited on
Commit
5a9adc7
·
1 Parent(s): 51bd956

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -4
app.py CHANGED
@@ -7,23 +7,35 @@ import json
7
  import mistune
8
  import pytz
9
  import math
10
-
11
  from datetime import datetime
12
  from openai import ChatCompletion
13
  from xml.etree import ElementTree as ET
14
  from bs4 import BeautifulSoup
15
  from collections import deque
16
 
17
- # Rest of your code goes here...
18
  openai.api_key = os.getenv('OPENAI_KEY')
19
  st.set_page_config(
20
  page_title="GPT Streamlit Document Reasoner",
21
  layout="wide")
22
 
23
- # Rest of your code goes here...
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
24
 
25
  def divide_document(document, max_length):
26
- # Split document into sections, each of about 2000 words or 4000 characters
27
  return [document[i:i+max_length] for i in range(0, len(document), max_length)]
28
 
29
  def chat_with_model(prompt, document_section):
@@ -34,6 +46,8 @@ def chat_with_model(prompt, document_section):
34
  response = openai.ChatCompletion.create(model=model, messages=conversation)
35
  return response['choices'][0]['message']['content']
36
 
 
 
37
  def main():
38
  user_prompt = st.text_area("Your question:", '', height=120)
39
  uploaded_file = st.file_uploader("Choose a file", type=["xml", "json", "html", "htm", "md", "txt"])
 
7
  import mistune
8
  import pytz
9
  import math
 
10
  from datetime import datetime
11
  from openai import ChatCompletion
12
  from xml.etree import ElementTree as ET
13
  from bs4 import BeautifulSoup
14
  from collections import deque
15
 
 
16
  openai.api_key = os.getenv('OPENAI_KEY')
17
  st.set_page_config(
18
  page_title="GPT Streamlit Document Reasoner",
19
  layout="wide")
20
 
21
+ menu = ["txt", "htm", "md", "py"]
22
+ choice = st.sidebar.selectbox("Output file type:", menu)
23
+ choicePrefix = "Output file type is "
24
+ if choice == "txt":
25
+ st.sidebar.write(choicePrefix + "Text File.")
26
+ elif choice == "htm":
27
+ st.sidebar.write(choicePrefix + "HTML5.")
28
+ elif choice == "md":
29
+ st.sidebar.write(choicePrefix + "Markdown.")
30
+ elif choice == "py":
31
+ st.sidebar.write(choicePrefix + "Python Code.")
32
+
33
+ max_length = st.sidebar.slider("Max document length", min_value=1000, max_value=32000, value=2000, step=1000)
34
+
35
+ def truncate_document(document, length):
36
+ return document[:length]
37
 
38
  def divide_document(document, max_length):
 
39
  return [document[i:i+max_length] for i in range(0, len(document), max_length)]
40
 
41
  def chat_with_model(prompt, document_section):
 
46
  response = openai.ChatCompletion.create(model=model, messages=conversation)
47
  return response['choices'][0]['message']['content']
48
 
49
+ #... Rest of your code...
50
+
51
  def main():
52
  user_prompt = st.text_area("Your question:", '', height=120)
53
  uploaded_file = st.file_uploader("Choose a file", type=["xml", "json", "html", "htm", "md", "txt"])