Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -22,16 +22,6 @@ def generate_filename(prompt, file_type):
|
|
| 22 |
safe_prompt = "".join(x for x in prompt if x.isalnum())[:45]
|
| 23 |
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
| 24 |
|
| 25 |
-
def chat_with_model(prompt, document_section):
|
| 26 |
-
model = model_choice
|
| 27 |
-
conversation = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
|
| 28 |
-
conversation.append({'role': 'user', 'content': prompt})
|
| 29 |
-
if len(document_section)>0:
|
| 30 |
-
conversation.append({'role': 'assistant', 'content': document_section})
|
| 31 |
-
response = openai.ChatCompletion.create(model=model, messages=conversation)
|
| 32 |
-
#return response
|
| 33 |
-
return response['choices'][0]['message']['content']
|
| 34 |
-
|
| 35 |
def transcribe_audio(openai_key, file_path, model):
|
| 36 |
OPENAI_API_URL = "https://api.openai.com/v1/audio/transcriptions"
|
| 37 |
headers = {
|
|
@@ -131,6 +121,16 @@ def read_file_content(file,max_length):
|
|
| 131 |
return ""
|
| 132 |
|
| 133 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
def chat_with_file_contents(prompt, file_content):
|
| 136 |
conversation = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
|
|
@@ -140,26 +140,26 @@ def chat_with_file_contents(prompt, file_content):
|
|
| 140 |
response = openai.ChatCompletion.create(model=model_choice, messages=conversation)
|
| 141 |
return response['choices'][0]['message']['content']
|
| 142 |
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
|
|
|
| 160 |
|
| 161 |
|
| 162 |
-
def main():
|
| 163 |
user_prompt = st.text_area("Enter prompts, instructions & questions:", '', height=100)
|
| 164 |
|
| 165 |
collength, colupload = st.columns([2,3]) # adjust the ratio as needed
|
|
|
|
| 22 |
safe_prompt = "".join(x for x in prompt if x.isalnum())[:45]
|
| 23 |
return f"{safe_date_time}_{safe_prompt}.{file_type}"
|
| 24 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
def transcribe_audio(openai_key, file_path, model):
|
| 26 |
OPENAI_API_URL = "https://api.openai.com/v1/audio/transcriptions"
|
| 27 |
headers = {
|
|
|
|
| 121 |
return ""
|
| 122 |
|
| 123 |
|
| 124 |
+
def chat_with_model(prompt, document_section):
|
| 125 |
+
model = model_choice
|
| 126 |
+
conversation = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
|
| 127 |
+
conversation.append({'role': 'user', 'content': prompt})
|
| 128 |
+
if len(document_section)>0:
|
| 129 |
+
conversation.append({'role': 'assistant', 'content': document_section})
|
| 130 |
+
response = openai.ChatCompletion.create(model=model, messages=conversation)
|
| 131 |
+
#return response
|
| 132 |
+
return response['choices'][0]['message']['content']
|
| 133 |
+
|
| 134 |
|
| 135 |
def chat_with_file_contents(prompt, file_content):
|
| 136 |
conversation = [{'role': 'system', 'content': 'You are a helpful assistant.'}]
|
|
|
|
| 140 |
response = openai.ChatCompletion.create(model=model_choice, messages=conversation)
|
| 141 |
return response['choices'][0]['message']['content']
|
| 142 |
|
| 143 |
+
|
| 144 |
+
def main():
|
| 145 |
+
# Sidebar and global
|
| 146 |
+
openai.api_key = os.getenv('OPENAI_KEY')
|
| 147 |
+
st.set_page_config(page_title="GPT Streamlit Document Reasoner",layout="wide")
|
| 148 |
+
menu = ["htm", "txt", "xlsx", "csv", "md", "py"] #619
|
| 149 |
+
choice = st.sidebar.selectbox("Output File Type:", menu)
|
| 150 |
+
model_choice = st.sidebar.radio("Select Model:", ('gpt-3.5-turbo', 'gpt-3.5-turbo-0301'))
|
| 151 |
+
|
| 152 |
+
# Audio, transcribe, GPT:
|
| 153 |
+
filename = save_and_play_audio(audio_recorder)
|
| 154 |
+
if filename is not None:
|
| 155 |
+
transcription = transcribe_audio(openai.api_key, filename, "whisper-1")
|
| 156 |
+
st.write(transcription)
|
| 157 |
+
gptOutput = chat_with_model(transcription, '') # *************************************
|
| 158 |
+
filename = generate_filename(transcription, choice)
|
| 159 |
+
create_file(filename, transcription, gptOutput)
|
| 160 |
+
st.sidebar.markdown(get_table_download_link(filename), unsafe_allow_html=True)
|
| 161 |
|
| 162 |
|
|
|
|
| 163 |
user_prompt = st.text_area("Enter prompts, instructions & questions:", '', height=100)
|
| 164 |
|
| 165 |
collength, colupload = st.columns([2,3]) # adjust the ratio as needed
|