thoristhor commited on
Commit
30d5280
1 Parent(s): b6b8073

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +22 -1
app.py CHANGED
@@ -2,6 +2,8 @@ import os
2
  import gradio as gr
3
  import pinecone
4
  from gpt_index import GPTIndexMemory, GPTPineconeIndex
 
 
5
 
6
  OPENAI_API_KEY=os.environ.get("OPENAI_API_KEY")
7
  PINECONE_API_KEY=os.environ.get("PINECONE_API_KEY")
@@ -12,4 +14,23 @@ pointing_pinecone_index=pinecone.Index("sethgodin")
12
  main_index=GPTPineconeIndex([],pinecone_index=pointing_pinecone_index)
13
  memory = GPTIndexMemory(index=main_index, memory_key="chat_history", query_kwargs={"response_mode": "compact"})
14
  llm=OpenAI(temperature=0.3)
15
- agent_chain = initialize_agent([], llm, agent="conversational-react-description", memory=memory
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
  import gradio as gr
3
  import pinecone
4
  from gpt_index import GPTIndexMemory, GPTPineconeIndex
5
+ import streamlit as st
6
+ from streamlit_chat import message
7
 
8
  OPENAI_API_KEY=os.environ.get("OPENAI_API_KEY")
9
  PINECONE_API_KEY=os.environ.get("PINECONE_API_KEY")
 
14
  main_index=GPTPineconeIndex([],pinecone_index=pointing_pinecone_index)
15
  memory = GPTIndexMemory(index=main_index, memory_key="chat_history", query_kwargs={"response_mode": "compact"})
16
  llm=OpenAI(temperature=0.3)
17
+ agent_chain = initialize_agent([], llm, agent="conversational-react-description", memory=memory
18
+
19
+ if "history" not in st.session_state:
20
+ st.session_state.history = []
21
+
22
+
23
+ def generate_answer():
24
+ user_message=st.session_state.input_text
25
+ message_bot = agent_chain.run(input=user_message)
26
+ st.session_state.history.append({"message": user_message, "is_user": True})
27
+ st.session_state.history.append({"message": message_bot, "is_user": False})
28
+
29
+ st.text_input("Response", key="input_text", on_change=generate_answer)
30
+
31
+ for chat in st.session_state.history:
32
+ st_message(**chat)
33
+ st.text_input("Response", key="input_text", on_change=generate_answer)
34
+
35
+ for chat in st.session_state.history:
36
+ st_message(**chat)