Spaces:
Runtime error
Runtime error
Commit ·
b6dfad6
1
Parent(s): 6e74c0b
Upload app.py
Browse files
app.py
CHANGED
|
@@ -37,54 +37,54 @@ def chat(temperature, model_name):
|
|
| 37 |
tmp_file.write(uploaded_file.getvalue())
|
| 38 |
tmp_file_path = tmp_file.name
|
| 39 |
|
| 40 |
-
|
| 41 |
-
|
| 42 |
|
| 43 |
-
|
| 44 |
-
|
| 45 |
|
| 46 |
-
|
| 47 |
-
|
| 48 |
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
|
|
|
|
|
|
| 53 |
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
if 'history' not in st.session_state:
|
| 57 |
-
st.session_state['history'] = []
|
| 58 |
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
if 'past' not in st.session_state:
|
| 63 |
-
st.session_state['past'] = ["Hey ! 👋"]
|
| 64 |
-
|
| 65 |
-
#container for the chat history
|
| 66 |
-
response_container = st.container()
|
| 67 |
-
#container for the user's text input
|
| 68 |
-
container = st.container()
|
| 69 |
|
| 70 |
-
|
| 71 |
-
|
| 72 |
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
st.
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
message(st.session_state["generated"][i], key=str(i), avatar_style="thumbs")
|
| 87 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 88 |
# Main App
|
| 89 |
st.markdown(
|
| 90 |
"""
|
|
|
|
| 37 |
tmp_file.write(uploaded_file.getvalue())
|
| 38 |
tmp_file_path = tmp_file.name
|
| 39 |
|
| 40 |
+
loader = CSVLoader(file_path=tmp_file_path, encoding="utf-8")
|
| 41 |
+
data = loader.load()
|
| 42 |
|
| 43 |
+
embeddings = OpenAIEmbeddings()
|
| 44 |
+
vectors = FAISS.from_documents(data, embeddings)
|
| 45 |
|
| 46 |
+
chain = ConversationalRetrievalChain.from_llm(llm = ChatOpenAI(temperature=0.0,model_name='gpt-3.5-turbo', openai_api_key=user_api_key),
|
| 47 |
+
retriever=vectors.as_retriever())
|
| 48 |
|
| 49 |
+
def conversational_chat(query):
|
| 50 |
+
|
| 51 |
+
result = chain({"question": query, "chat_history": st.session_state['history']})
|
| 52 |
+
st.session_state['history'].append((query, result["answer"]))
|
| 53 |
+
|
| 54 |
+
return result["answer"]
|
| 55 |
|
| 56 |
+
if 'history' not in st.session_state:
|
| 57 |
+
st.session_state['history'] = []
|
|
|
|
|
|
|
| 58 |
|
| 59 |
+
if 'generated' not in st.session_state:
|
| 60 |
+
st.session_state['generated'] = ["Hello ! Ask me anything about " + uploaded_file.name + " 🤗"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
if 'past' not in st.session_state:
|
| 63 |
+
st.session_state['past'] = ["Hey ! 👋"]
|
| 64 |
|
| 65 |
+
#container for the chat history
|
| 66 |
+
response_container = st.container()
|
| 67 |
+
#container for the user's text input
|
| 68 |
+
container = st.container()
|
| 69 |
+
|
| 70 |
+
with container:
|
| 71 |
+
with st.form(key='my_form', clear_on_submit=True):
|
| 72 |
+
|
| 73 |
+
user_input = st.text_input("Query:", placeholder="Talk about your csv data here (:", key='input')
|
| 74 |
+
submit_button = st.form_submit_button(label='Send')
|
| 75 |
+
|
| 76 |
+
if submit_button and user_input:
|
| 77 |
+
output = conversational_chat(user_input)
|
|
|
|
| 78 |
|
| 79 |
+
st.session_state['past'].append(user_input)
|
| 80 |
+
st.session_state['generated'].append(output)
|
| 81 |
+
|
| 82 |
+
if st.session_state['generated']:
|
| 83 |
+
with response_container:
|
| 84 |
+
for i in range(len(st.session_state['generated'])):
|
| 85 |
+
message(st.session_state["past"][i], is_user=True, key=str(i) + '_user', avatar_style="big-smile")
|
| 86 |
+
message(st.session_state["generated"][i], key=str(i), avatar_style="thumbs")
|
| 87 |
+
|
| 88 |
# Main App
|
| 89 |
st.markdown(
|
| 90 |
"""
|