Spaces:
Runtime error
Runtime error
MatheusHRV
commited on
Commit
•
7d68626
1
Parent(s):
96afccc
Update app.py
Browse files
app.py
CHANGED
@@ -1,55 +1,43 @@
|
|
1 |
|
2 |
import streamlit as st
|
|
|
3 |
|
|
|
|
|
4 |
|
5 |
-
|
6 |
-
|
7 |
-
|
8 |
-
HumanMessage,
|
9 |
-
SystemMessage
|
10 |
-
)
|
11 |
-
|
12 |
-
# From here down is all the StreamLit UI
|
13 |
-
st.set_page_config(page_title="LangChain Demo", page_icon=":robot:")
|
14 |
-
st.header("IPE Chatbot")
|
15 |
-
|
16 |
-
|
17 |
-
|
18 |
-
if "sessionMessages" not in st.session_state:
|
19 |
-
st.session_state.sessionMessages = [
|
20 |
-
SystemMessage(content="You are customer support chatbot from a website.")
|
21 |
-
]
|
22 |
-
|
23 |
|
|
|
|
|
|
|
24 |
|
|
|
25 |
def load_answer(question):
|
|
|
|
|
|
|
|
|
26 |
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
st.session_state.sessionMessages.append(AIMessage(content=assistant_answer.content))
|
32 |
-
|
33 |
-
return assistant_answer.content
|
34 |
|
|
|
|
|
35 |
|
36 |
-
|
37 |
-
|
38 |
-
return input_text
|
39 |
-
|
40 |
-
|
41 |
-
chat = ChatOpenAI(temperature=0)
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
user_input=get_text()
|
47 |
-
submit = st.button('Generate')
|
48 |
|
|
|
49 |
if submit:
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
|
|
|
|
|
|
|
1 |
|
2 |
import streamlit as st
|
3 |
+
from transformers import Conversation, pipeline
|
4 |
|
5 |
+
# Initialize the chat pipeline with the dolphin-2.6-mistral-7b model
|
6 |
+
chat_pipeline = pipeline("conversational", model="google/flan-t5-base")
|
7 |
|
8 |
+
# Set page configuration for the Streamlit app
|
9 |
+
st.set_page_config(page_title="Dolphin Chatbot", page_icon=":robot_face:")
|
10 |
+
st.header("Dolphin 2.6 Mistral 7B Chatbot")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
# Initialize the conversation object
|
13 |
+
if "conversation" not in st.session_state:
|
14 |
+
st.session_state.conversation = Conversation()
|
15 |
|
16 |
+
# Function to get user input and generate a response
|
17 |
def load_answer(question):
|
18 |
+
st.session_state.conversation.add_user_input(question)
|
19 |
+
responses = chat_pipeline(st.session_state.conversation)
|
20 |
+
# The latest response is the last element in the list
|
21 |
+
return responses.generations[-1].text
|
22 |
|
23 |
+
# Function to display the input bar and detect user input
|
24 |
+
def get_input():
|
25 |
+
return st.text_input("You:", key="input")
|
|
|
|
|
|
|
|
|
26 |
|
27 |
+
# Display input bar and wait for user input
|
28 |
+
user_input = get_input()
|
29 |
|
30 |
+
# Button to generate the response
|
31 |
+
submit = st.button('Generate')
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
32 |
|
33 |
+
# Actions to take when the 'Generate' button is clicked
|
34 |
if submit:
|
35 |
+
if user_input:
|
36 |
+
# Get the assistant's response
|
37 |
+
response = load_answer(user_input)
|
38 |
+
# Display the response
|
39 |
+
st.subheader("Answer:")
|
40 |
+
st.write(response)
|
41 |
+
else:
|
42 |
+
# If no user input, prompt the user to enter a question
|
43 |
+
st.warning("Please enter a question for the chatbot.")
|