Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -1,8 +1,6 @@
|
|
1 |
-
import streamlit as st
|
2 |
-
from streamlit_chat import message
|
3 |
-
from streamlit.components.v1 import html
|
4 |
from dataclasses import dataclass
|
5 |
from typing import Literal
|
|
|
6 |
import os
|
7 |
from llamaapi import LlamaAPI
|
8 |
from langchain_experimental.llms import ChatLlamaAPI
|
@@ -11,6 +9,7 @@ import pinecone
|
|
11 |
from langchain.vectorstores import Pinecone
|
12 |
from langchain.prompts import PromptTemplate
|
13 |
from langchain.chains import RetrievalQA
|
|
|
14 |
from langchain_groq import ChatGroq
|
15 |
from langchain.chains import ConversationalRetrievalChain
|
16 |
from langchain.memory import ChatMessageHistory, ConversationBufferMemory
|
@@ -64,6 +63,7 @@ def initialize_session_state():
|
|
64 |
|
65 |
PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
|
66 |
|
|
|
67 |
message_history = ChatMessageHistory()
|
68 |
memory = ConversationBufferMemory(
|
69 |
memory_key="chat_history",
|
@@ -85,11 +85,17 @@ def initialize_session_state():
|
|
85 |
|
86 |
def on_click_callback():
|
87 |
human_prompt = st.session_state.human_prompt
|
88 |
-
st.session_state.human_prompt
|
89 |
-
response = st.session_state.conversation(
|
|
|
|
|
90 |
llm_response = response['answer']
|
91 |
-
st.session_state.history.append(
|
92 |
-
|
|
|
|
|
|
|
|
|
93 |
|
94 |
|
95 |
initialize_session_state()
|
@@ -118,38 +124,23 @@ st.markdown(
|
|
118 |
"""
|
119 |
)
|
120 |
|
121 |
-
|
122 |
-
|
123 |
-
|
124 |
-
|
125 |
-
st.session_state.
|
126 |
-
|
127 |
-
|
128 |
-
|
129 |
-
|
130 |
-
|
131 |
-
|
132 |
-
|
133 |
-
|
134 |
-
|
135 |
-
|
136 |
-
|
137 |
-
|
138 |
-
|
139 |
-
|
140 |
-
|
141 |
-
st.session_state.past.append(user_input)
|
142 |
-
response = st.session_state.conversation(user_input)
|
143 |
-
llm_response = response['answer']
|
144 |
-
st.session_state.generated.append({"type": "normal", "data": f"The message from Bot\nWith new line\n{user_input}"})
|
145 |
-
st.session_state.history.append(Message("π€ Human", user_input))
|
146 |
-
st.session_state.history.append(Message("π¨π»ββοΈ Ai", llm_response))
|
147 |
-
|
148 |
-
def on_btn_click():
|
149 |
-
del st.session_state.past[:]
|
150 |
-
del st.session_state.generated[:]
|
151 |
-
del st.session_state.history[:]
|
152 |
-
|
153 |
-
with st.container():
|
154 |
-
st.text_input("User Input:", on_change=on_input_change, key="user_input")
|
155 |
-
st.button("Clear message", on_click=on_btn_click)
|
|
|
|
|
|
|
|
|
1 |
from dataclasses import dataclass
|
2 |
from typing import Literal
|
3 |
+
import streamlit as st
|
4 |
import os
|
5 |
from llamaapi import LlamaAPI
|
6 |
from langchain_experimental.llms import ChatLlamaAPI
|
|
|
9 |
from langchain.vectorstores import Pinecone
|
10 |
from langchain.prompts import PromptTemplate
|
11 |
from langchain.chains import RetrievalQA
|
12 |
+
import streamlit.components.v1 as components
|
13 |
from langchain_groq import ChatGroq
|
14 |
from langchain.chains import ConversationalRetrievalChain
|
15 |
from langchain.memory import ChatMessageHistory, ConversationBufferMemory
|
|
|
63 |
|
64 |
PROMPT = PromptTemplate(template=prompt_template, input_variables=["context", "question"])
|
65 |
|
66 |
+
#chain_type_kwargs = {"prompt": PROMPT}
|
67 |
message_history = ChatMessageHistory()
|
68 |
memory = ConversationBufferMemory(
|
69 |
memory_key="chat_history",
|
|
|
85 |
|
86 |
def on_click_callback():
|
87 |
human_prompt = st.session_state.human_prompt
|
88 |
+
st.session_state.human_prompt=""
|
89 |
+
response = st.session_state.conversation(
|
90 |
+
human_prompt
|
91 |
+
)
|
92 |
llm_response = response['answer']
|
93 |
+
st.session_state.history.append(
|
94 |
+
Message("π€ Human", human_prompt)
|
95 |
+
)
|
96 |
+
st.session_state.history.append(
|
97 |
+
Message("π¨π»ββοΈ Ai", llm_response)
|
98 |
+
)
|
99 |
|
100 |
|
101 |
initialize_session_state()
|
|
|
124 |
"""
|
125 |
)
|
126 |
|
127 |
+
chat_placeholder = st.container()
|
128 |
+
prompt_placeholder = st.form("chat-form")
|
129 |
+
|
130 |
+
with chat_placeholder:
|
131 |
+
for chat in st.session_state.history:
|
132 |
+
st.markdown(f"{chat.origin} : {chat.message}")
|
133 |
+
|
134 |
+
with prompt_placeholder:
|
135 |
+
st.markdown("**Chat**")
|
136 |
+
cols = st.columns((6, 1))
|
137 |
+
cols[0].text_input(
|
138 |
+
"Chat",
|
139 |
+
label_visibility="collapsed",
|
140 |
+
key="human_prompt",
|
141 |
+
)
|
142 |
+
cols[1].form_submit_button(
|
143 |
+
"Submit",
|
144 |
+
type="primary",
|
145 |
+
on_click=on_click_callback,
|
146 |
+
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|