Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,22 +1,78 @@
|
|
| 1 |
-
import
|
| 2 |
import time
|
| 3 |
-
import
|
| 4 |
import streamlit as st
|
|
|
|
| 5 |
|
| 6 |
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
import time
|
| 3 |
+
import json
|
| 4 |
import streamlit as st
|
| 5 |
+
from google_api_deploy import read_google_doc, write_google_doc_add, authenticate_google_drive, write_google_doc
|
| 6 |
|
| 7 |
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
service = authenticate_google_drive()
|
| 11 |
+
|
| 12 |
+
# Streamlit page configuration
|
| 13 |
+
st.set_page_config(
|
| 14 |
+
page_title="AMGPT",
|
| 15 |
+
page_icon="🦙",
|
| 16 |
+
layout="centered",
|
| 17 |
+
initial_sidebar_state="auto",
|
| 18 |
+
menu_items=None
|
| 19 |
+
)
|
| 20 |
+
st.title("AMGPT, powered by LlamaIndex 💬🦙")
|
| 21 |
+
st.info("Please hit the refresh button just once before prompting")
|
| 22 |
+
|
| 23 |
+
# Initialize chat messages history
|
| 24 |
+
if "messages" not in st.session_state.keys():
|
| 25 |
+
st.session_state.messages = [
|
| 26 |
+
{"role": "assistant", "content": "Ask me a question!!!"}
|
| 27 |
+
]
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
if st.sidebar.button("New Chat"):
|
| 31 |
+
st.session_state.messages = [{"role": "assistant", "content": "Ask me a question!!!"}]
|
| 32 |
+
write_google_doc(service, "1PMgaUKuPXYrbvYiqx7lwIG47P_wzxMN7VmSxg1RMIKs", "")#prompt
|
| 33 |
+
write_google_doc(service, "1Na3EF7vWj9x_yzVxs3w450zgWtIdZZHU0xOYV-9WPk4", "")#promptandquery
|
| 34 |
+
write_google_doc(service, "1Wpscos9GJ04_T6eLWHbYq2f6HuZD3OJvyoqW_pE2Yoc", "")#query
|
| 35 |
+
|
| 36 |
+
|
| 37 |
+
# Prompt for user input and save to chat history
|
| 38 |
+
if prompt := st.chat_input("Your question"):
|
| 39 |
+
with st.spinner("Thinking..."):
|
| 40 |
+
write_google_doc_add(service, "1Na3EF7vWj9x_yzVxs3w450zgWtIdZZHU0xOYV-9WPk4", prompt)#promptandquery
|
| 41 |
+
write_google_doc_add(service, "1PMgaUKuPXYrbvYiqx7lwIG47P_wzxMN7VmSxg1RMIKs", prompt)#prompt
|
| 42 |
+
st.session_state.messages.append({"role": "user", "content": prompt})
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
for message in st.session_state.messages[1:]:
|
| 46 |
+
with st.chat_message(message["role"]):
|
| 47 |
+
st.write(message["content"])
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
|
| 51 |
+
|
| 52 |
+
if st.session_state.messages[-1]["role"] != "assistant":
|
| 53 |
+
with st.chat_message("assistant"):
|
| 54 |
+
time.sleep(40)
|
| 55 |
+
response = read_google_doc(service, "1Wpscos9GJ04_T6eLWHbYq2f6HuZD3OJvyoqW_pE2Yoc")#reading query
|
| 56 |
+
st.write(response)
|
| 57 |
+
message = {"role": "assistant", "content": response}
|
| 58 |
+
# Add response to message history
|
| 59 |
+
st.session_state.messages.append(message)
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
# # Generate a new response if the last message is not from the assistant
|
| 64 |
+
# if st.session_state.messages[-1]["role"] != "assistant":
|
| 65 |
+
# with st.chat_message("assistant"):
|
| 66 |
+
# history = [msg["content"] for msg in st.session_state.messages]
|
| 67 |
+
# total_history = " ".join(history) + " " + st.session_state["additional_string"]
|
| 68 |
+
# #response = st.session_state.chat_engine.chat(st.session_state.messages[-1]["content"])
|
| 69 |
+
# response = st.session_state.chat_engine.chat(total_history)
|
| 70 |
+
# if response.response == "Empty Response":
|
| 71 |
+
# response = st.session_state.llm.complete(total_history)
|
| 72 |
+
# st.write(response.text)
|
| 73 |
+
# message = {"role": "assistant", "content": response.text}
|
| 74 |
+
# else:
|
| 75 |
+
# st.write(response.response)
|
| 76 |
+
# message = {"role": "assistant", "content": response.response}
|
| 77 |
+
# st.session_state.messages.append(message)
|
| 78 |
+
|