Update app.py
Browse files
app.py
CHANGED
|
@@ -27,6 +27,7 @@ from langchain.chat_models import ChatOpenAI
|
|
| 27 |
from langchain.memory import ConversationBufferMemory
|
| 28 |
from langchain.chains import ConversationalRetrievalChain
|
| 29 |
from templates import css, bot_template, user_template
|
|
|
|
| 30 |
|
| 31 |
# page config and sidebar declares up front allow all other functions to see global class variables
|
| 32 |
st.set_page_config(page_title="GPT Streamlit Document Reasoner", layout="wide")
|
|
@@ -196,6 +197,36 @@ def read_file_content(file,max_length):
|
|
| 196 |
return file.getvalue().decode()
|
| 197 |
else:
|
| 198 |
return ""
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 199 |
|
| 200 |
def chat_with_model(prompt, document_section, model_choice='gpt-3.5-turbo'):
|
| 201 |
model = model_choice
|
|
@@ -237,6 +268,7 @@ def chat_with_model(prompt, document_section, model_choice='gpt-3.5-turbo'):
|
|
| 237 |
full_reply_content = ''.join([m.get('content', '') for m in collected_messages])
|
| 238 |
st.write("Elapsed time:")
|
| 239 |
st.write(time.time() - start_time)
|
|
|
|
| 240 |
return full_reply_content
|
| 241 |
|
| 242 |
def chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):
|
|
|
|
| 27 |
from langchain.memory import ConversationBufferMemory
|
| 28 |
from langchain.chains import ConversationalRetrievalChain
|
| 29 |
from templates import css, bot_template, user_template
|
| 30 |
+
import streamlit.components.v1 as components # Import Streamlit Components for HTML5
|
| 31 |
|
| 32 |
# page config and sidebar declares up front allow all other functions to see global class variables
|
| 33 |
st.set_page_config(page_title="GPT Streamlit Document Reasoner", layout="wide")
|
|
|
|
| 197 |
return file.getvalue().decode()
|
| 198 |
else:
|
| 199 |
return ""
|
| 200 |
+
|
| 201 |
+
def readitaloud(result):
|
| 202 |
+
documentHTML5='''
|
| 203 |
+
<!DOCTYPE html>
|
| 204 |
+
<html>
|
| 205 |
+
<head>
|
| 206 |
+
<title>Read It Aloud</title>
|
| 207 |
+
<script type="text/javascript">
|
| 208 |
+
function readAloud() {
|
| 209 |
+
const text = document.getElementById("textArea").value;
|
| 210 |
+
const speech = new SpeechSynthesisUtterance(text);
|
| 211 |
+
window.speechSynthesis.speak(speech);
|
| 212 |
+
}
|
| 213 |
+
</script>
|
| 214 |
+
</head>
|
| 215 |
+
<body>
|
| 216 |
+
<h1>๐ Read It Aloud</h1>
|
| 217 |
+
<textarea id="textArea" rows="10" cols="80">
|
| 218 |
+
'''
|
| 219 |
+
documentHTML5 = documentHTML5 + result
|
| 220 |
+
documentHTML5 = documentHTML5 + '''
|
| 221 |
+
</textarea>
|
| 222 |
+
<br>
|
| 223 |
+
<button onclick="readAloud()">๐ Read Aloud</button>
|
| 224 |
+
</body>
|
| 225 |
+
</html>
|
| 226 |
+
'''
|
| 227 |
+
|
| 228 |
+
components.html(documentHTML5, width=1280, height=1024)
|
| 229 |
+
#return result
|
| 230 |
|
| 231 |
def chat_with_model(prompt, document_section, model_choice='gpt-3.5-turbo'):
|
| 232 |
model = model_choice
|
|
|
|
| 268 |
full_reply_content = ''.join([m.get('content', '') for m in collected_messages])
|
| 269 |
st.write("Elapsed time:")
|
| 270 |
st.write(time.time() - start_time)
|
| 271 |
+
readitaloud(full_reply_content)
|
| 272 |
return full_reply_content
|
| 273 |
|
| 274 |
def chat_with_file_contents(prompt, file_content, model_choice='gpt-3.5-turbo'):
|