MatheusHRV commited on
Commit
267fb75
1 Parent(s): 9d6da97

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +26 -14
app.py CHANGED
@@ -1,30 +1,42 @@
1
  import streamlit as st
2
  from transformers import Conversation, pipeline
3
 
 
 
 
 
4
  st.set_page_config(page_title="Dolphin Chatbot", page_icon=":robot_face:")
5
  st.header("Dolphin 2.6 Mistral 7B Chatbot")
6
 
7
- # Initialize the conversation pipeline with dolphin-2.6-mistral-7b model
8
- conversational_pipeline = pipeline('conversational', model='cognitivecomputations/dolphin-2.6-mistral-7b')
9
-
10
  if "conversation" not in st.session_state:
11
  st.session_state.conversation = Conversation()
12
 
 
13
  def load_answer(question):
14
- new_user_input = Conversation(text=question)
15
  st.session_state.conversation.add_user_input(question)
16
- assistant_answer = conversational_pipeline(st.session_state.conversation)
17
- st.session_state.conversation = assistant_answer
18
- return assistant_answer.text
 
 
 
 
19
 
20
- def get_text():
21
- input_text = st.text_input("You: ", key="input_text")
22
- return input_text
23
 
24
- user_input = get_text()
25
  submit = st.button('Generate')
26
 
 
27
  if submit:
28
- response = load_answer(user_input)
29
- st.subheader("Answer:")
30
- st.write(response)
 
 
 
 
 
 
 
1
  import streamlit as st
2
  from transformers import Conversation, pipeline
3
 
4
+ # Initialize the chat pipeline with the dolphin-2.6-mistral-7b model
5
+ chat_pipeline = pipeline("conversational", model="cognitivecomputations/dolphin-2.6-mistral-7b")
6
+
7
+ # Set page configuration for the Streamlit app
8
  st.set_page_config(page_title="Dolphin Chatbot", page_icon=":robot_face:")
9
  st.header("Dolphin 2.6 Mistral 7B Chatbot")
10
 
11
+ # Initialize the conversation object
 
 
12
  if "conversation" not in st.session_state:
13
  st.session_state.conversation = Conversation()
14
 
15
+ # Function to get user input and generate a response
16
  def load_answer(question):
 
17
  st.session_state.conversation.add_user_input(question)
18
+ responses = chat_pipeline(st.session_state.conversation)
19
+ # The latest response is the last element in the list
20
+ return responses.generations[-1].text
21
+
22
+ # Function to display the input bar and detect user input
23
+ def get_input():
24
+ return st.text_input("You:", key="input")
25
 
26
+ # Display input bar and wait for user input
27
+ user_input = get_input()
 
28
 
29
+ # Button to generate the response
30
  submit = st.button('Generate')
31
 
32
+ # Actions to take when the 'Generate' button is clicked
33
  if submit:
34
+ if user_input:
35
+ # Get the assistant's response
36
+ response = load_answer(user_input)
37
+ # Display the response
38
+ st.subheader("Answer:")
39
+ st.write(response)
40
+ else:
41
+ # If no user input, prompt the user to enter a question
42
+ st.warning("Please enter a question for the chatbot.")