Pijush2023 commited on
Commit
43badf5
·
verified ·
1 Parent(s): d663512

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -13
app.py CHANGED
@@ -62,33 +62,31 @@ rag_chain = (
62
  | StrOutputParser()
63
  )
64
 
65
- def rag_chain_response(messages):
66
- if not messages: # If messages list is empty
67
- return [("System", "Hi! How can I assist you today?")] # Provide a default greeting
68
-
69
- # Extract the last user message
70
- user_message = messages[-1][0]
71
-
72
  # Generate a response using the RAG chain
73
  response = rag_chain.invoke(user_message)
74
 
75
- # Append response to the chat
76
  messages.append((user_message, response))
77
- return messages
 
 
78
 
79
 
 
80
  with gr.Blocks(theme="rawrsor1/Everforest") as app:
81
  gr.Markdown("## Welcome to Annie's Chatbot - Your Friendly Guide to Birmingham!")
82
 
83
- chatbot = gr.Chatbot([("System", "Hi! How can I assist you today?")], elem_id="RADAR", bubble_full_width=False)
84
  question_input = gr.Textbox(label="Ask a Question", placeholder="Type your question here...")
85
  submit_btn = gr.Button("Submit")
86
 
87
  # Set up interaction
88
  submit_btn.click(
89
- rag_chain_response, # Function to handle input and generate response
90
- inputs=[chatbot], # Pass current conversation state
91
- outputs=[chatbot] # Update conversation state
92
  )
93
 
94
  # Launch the Gradio app
 
62
  | StrOutputParser()
63
  )
64
 
65
+ # Function to handle chatbot interaction
66
+ def rag_chain_response(messages, user_message):
 
 
 
 
 
67
  # Generate a response using the RAG chain
68
  response = rag_chain.invoke(user_message)
69
 
70
+ # Append the user's message and the response to the chat
71
  messages.append((user_message, response))
72
+
73
+ # Return the updated chat and clear the input box
74
+ return messages, ""
75
 
76
 
77
+ # Define the Gradio app
78
  with gr.Blocks(theme="rawrsor1/Everforest") as app:
79
  gr.Markdown("## Welcome to Annie's Chatbot - Your Friendly Guide to Birmingham!")
80
 
81
+ chatbot = gr.Chatbot([], elem_id="RADAR", bubble_full_width=False)
82
  question_input = gr.Textbox(label="Ask a Question", placeholder="Type your question here...")
83
  submit_btn = gr.Button("Submit")
84
 
85
  # Set up interaction
86
  submit_btn.click(
87
+ rag_chain_response, # Function to handle input and generate response
88
+ inputs=[chatbot, question_input], # Pass current conversation state and user input
89
+ outputs=[chatbot, question_input] # Update conversation state and clear the input
90
  )
91
 
92
  # Launch the Gradio app