Pijush2023 commited on
Commit
fe5f1a6
·
verified ·
1 Parent(s): c976319

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +23 -20
app.py CHANGED
@@ -62,29 +62,32 @@ rag_chain = (
62
  | StrOutputParser()
63
  )
64
 
65
- # Define the Gradio app
66
- def rag_chain_response(question):
67
- response = rag_chain.invoke(question)
68
- return response
 
 
 
 
 
 
 
69
 
 
70
  with gr.Blocks(theme="rawrsor1/Everforest") as app:
71
- with gr.Row():
72
- with gr.Column(scale=1):
73
- user_input = gr.Textbox(
74
- placeholder="Type your question here...",
75
- label="Your Question",
76
- lines=2,
77
- max_lines=2,
78
- )
79
- with gr.Column(scale=2):
80
- response_output = gr.Textbox(
81
- lines=10,
82
- max_lines=10,
83
- )
84
- with gr.Row():
85
- submit_btn = gr.Button("Submit")
86
  submit_btn.click(
87
- rag_chain_response, inputs=user_input, outputs=response_output
 
 
88
  )
89
 
 
90
  app.launch(show_error=True)
 
62
  | StrOutputParser()
63
  )
64
 
65
+ # Function to handle chatbot interaction
66
+ def rag_chain_response(messages):
67
+ # Extract the last user message
68
+ user_message = messages[-1][0]
69
+
70
+ # Generate a response using the RAG chain
71
+ response = rag_chain.invoke(user_message)
72
+
73
+ # Append response to the chat
74
+ messages.append((user_message, response))
75
+ return messages
76
 
77
+ # Define the Gradio app
78
  with gr.Blocks(theme="rawrsor1/Everforest") as app:
79
+
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], # Pass current conversation state
89
+ outputs=[chatbot] # Update conversation state
90
  )
91
 
92
+ # Launch the Gradio app
93
  app.launch(show_error=True)