awacke1 commited on
Commit
2d3f2d0
·
1 Parent(s): 709105e

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -21
app.py CHANGED
@@ -16,13 +16,6 @@ from bs4 import BeautifulSoup
16
  from collections import deque
17
  from audio_recorder_streamlit import audio_recorder
18
 
19
- openai.api_key = os.getenv('OPENAI_KEY')
20
- st.set_page_config(page_title="GPT Streamlit Document Reasoner",layout="wide")
21
-
22
- menu = ["htm", "txt", "xlsx", "csv", "md", "py"] #619
23
- choice = st.sidebar.selectbox("Output File Type:", menu)
24
- model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
25
-
26
  def generate_filename(prompt, file_type):
27
  central = pytz.timezone('US/Central')
28
  safe_date_time = datetime.now(central).strftime("%m%d_%I%M")
@@ -49,7 +42,8 @@ def transcribe_audio(openai_key, file_path, model):
49
  response = requests.post(OPENAI_API_URL, headers=headers, files=data, data={'model': model})
50
  if response.status_code == 200:
51
  st.write(response.json())
52
- response2 = chat_with_model(response.json().get('text'), '')
 
53
  st.write('Responses:')
54
  #st.write(response)
55
  st.write(response2)
@@ -108,17 +102,6 @@ def get_table_download_link(file_path):
108
 
109
 
110
 
111
- # Audio, transcribe, GPT:
112
- filename = save_and_play_audio(audio_recorder)
113
- if filename is not None:
114
- transcription = transcribe_audio(openai.api_key, filename, "whisper-1")
115
- st.write(transcription)
116
- gptOutput = chat_with_model(transcription, '') # push transcript through as prompt
117
- filename = generate_filename(transcription, choice)
118
- create_file(filename, transcription, gptOutput)
119
- st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
120
-
121
-
122
 
123
 
124
 
@@ -150,6 +133,27 @@ def read_file_content(file,max_length):
150
  else:
151
  return ""
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  def main():
154
  user_prompt = st.text_area("Enter prompts, instructions & questions:", '', height=100)
155
 
@@ -181,7 +185,8 @@ def main():
181
  else:
182
  if st.button(f"Chat about Section {i+1}"):
183
  st.write('Reasoning with your inputs...')
184
- response = chat_with_model(user_prompt, section)
 
185
  st.write('Response:')
186
  st.write(response)
187
  document_responses[i] = response
@@ -191,7 +196,8 @@ def main():
191
 
192
  if st.button('💬 Chat'):
193
  st.write('Reasoning with your inputs...')
194
- response = chat_with_model(user_prompt, ''.join(list(document_sections)))
 
195
  st.write('Response:')
196
  st.write(response)
197
 
 
16
  from collections import deque
17
  from audio_recorder_streamlit import audio_recorder
18
 
 
 
 
 
 
 
 
19
  def generate_filename(prompt, file_type):
20
  central = pytz.timezone('US/Central')
21
  safe_date_time = datetime.now(central).strftime("%m%d_%I%M")
 
42
  response = requests.post(OPENAI_API_URL, headers=headers, files=data, data={'model': model})
43
  if response.status_code == 200:
44
  st.write(response.json())
45
+
46
+ response2 = chat_with_model(response.json().get('text'), '') # *************************************
47
  st.write('Responses:')
48
  #st.write(response)
49
  st.write(response2)
 
102
 
103
 
104
 
 
 
 
 
 
 
 
 
 
 
 
105
 
106
 
107
 
 
133
  else:
134
  return ""
135
 
136
+
137
+ # Sidebar and global
138
+ openai.api_key = os.getenv('OPENAI_KEY')
139
+ st.set_page_config(page_title="GPT Streamlit Document Reasoner",layout="wide")
140
+ menu = ["htm", "txt", "xlsx", "csv", "md", "py"] #619
141
+ choice = st.sidebar.selectbox("Output File Type:", menu)
142
+ model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
143
+
144
+
145
+
146
+ # Audio, transcribe, GPT:
147
+ filename = save_and_play_audio(audio_recorder)
148
+ if filename is not None:
149
+ transcription = transcribe_audio(openai.api_key, filename, "whisper-1")
150
+ st.write(transcription)
151
+ gptOutput = chat_with_model(transcription, '') # *************************************
152
+ filename = generate_filename(transcription, choice)
153
+ create_file(filename, transcription, gptOutput)
154
+ st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
155
+
156
+
157
  def main():
158
  user_prompt = st.text_area("Enter prompts, instructions & questions:", '', height=100)
159
 
 
185
  else:
186
  if st.button(f"Chat about Section {i+1}"):
187
  st.write('Reasoning with your inputs...')
188
+ response =
189
+ (user_prompt, section) # *************************************
190
  st.write('Response:')
191
  st.write(response)
192
  document_responses[i] = response
 
196
 
197
  if st.button('💬 Chat'):
198
  st.write('Reasoning with your inputs...')
199
+ response =
200
+ (user_prompt, ''.join(list(document_sections))) # *************************************
201
  st.write('Response:')
202
  st.write(response)
203