Pijush2023 commited on
Commit
16913a7
·
verified ·
1 Parent(s): e110d68

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -36
app.py CHANGED
@@ -65,14 +65,8 @@ rag_chain = (
65
  | StrOutputParser()
66
  )
67
 
68
- # Generate follow-up questions dynamically
69
- def generate_follow_ups(response):
70
- # Simple logic to generate follow-up questions dynamically
71
- # You can replace this with a more sophisticated model-based approach
72
- return [
73
- f"What more can you tell me about {response.split()[0]}?",
74
- f"Can you elaborate on {response.split()[-1]}?",
75
- ]
76
 
77
 
78
 
@@ -81,28 +75,13 @@ def rag_chain_response(messages, user_message):
81
  # Generate a response using the RAG chain
82
  response = rag_chain.invoke(user_message)
83
 
84
- # Generate follow-up questions based on the response
85
- follow_ups = generate_follow_ups(response)
86
-
87
  # Append the user's message and the response to the chat
88
  messages.append((user_message, response))
89
 
90
- # Return the updated chat, follow-up questions, and clear the input box
91
- return messages, follow_ups, ""
 
92
 
93
- # Function to handle follow-up clicks
94
- def follow_up_click(messages, follow_up_question):
95
- # Treat the follow-up question as the user query
96
- response = rag_chain.invoke(follow_up_question)
97
-
98
- # Generate new follow-ups based on the new response
99
- follow_ups = generate_follow_ups(response)
100
-
101
- # Append the follow-up question and response to the chat
102
- messages.append((follow_up_question, response))
103
-
104
- # Return the updated chat and follow-up questions
105
- return messages, follow_ups
106
 
107
 
108
 
@@ -113,25 +92,17 @@ with gr.Blocks(theme="rawrsor1/Everforest") as app:
113
  chatbot = gr.Chatbot([], elem_id="RADAR", bubble_full_width=False)
114
  question_input = gr.Textbox(label="Ask a Question", placeholder="Type your question here...")
115
  submit_btn = gr.Button("Submit")
116
- follow_up_btns = gr.ButtonGroup(label="Follow-Up Questions", buttons=[""] * 2)
117
 
118
  # Set up interaction for both Enter key and Submit button
119
  question_input.submit(
120
  rag_chain_response, # Function to handle input and generate response
121
  inputs=[chatbot, question_input], # Pass current conversation state and user input
122
- outputs=[chatbot, follow_up_btns, question_input] # Update chat, follow-ups, and clear input
123
  )
124
  submit_btn.click(
125
  rag_chain_response, # Function to handle input and generate response
126
  inputs=[chatbot, question_input], # Pass current conversation state and user input
127
- outputs=[chatbot, follow_up_btns, question_input] # Update chat, follow-ups, and clear input
128
- )
129
-
130
- # Handle follow-up button clicks
131
- follow_up_btns.click(
132
- follow_up_click,
133
- inputs=[chatbot, follow_up_btns],
134
- outputs=[chatbot, follow_up_btns]
135
  )
136
 
137
  # Launch the Gradio app
 
65
  | StrOutputParser()
66
  )
67
 
68
+
69
+
 
 
 
 
 
 
70
 
71
 
72
 
 
75
  # Generate a response using the RAG chain
76
  response = rag_chain.invoke(user_message)
77
 
 
 
 
78
  # Append the user's message and the response to the chat
79
  messages.append((user_message, response))
80
 
81
+ # Return the updated chat and clear the input box
82
+ return messages, ""
83
+
84
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85
 
86
 
87
 
 
92
  chatbot = gr.Chatbot([], elem_id="RADAR", bubble_full_width=False)
93
  question_input = gr.Textbox(label="Ask a Question", placeholder="Type your question here...")
94
  submit_btn = gr.Button("Submit")
 
95
 
96
  # Set up interaction for both Enter key and Submit button
97
  question_input.submit(
98
  rag_chain_response, # Function to handle input and generate response
99
  inputs=[chatbot, question_input], # Pass current conversation state and user input
100
+ outputs=[chatbot, question_input] # Update conversation state and clear the input
101
  )
102
  submit_btn.click(
103
  rag_chain_response, # Function to handle input and generate response
104
  inputs=[chatbot, question_input], # Pass current conversation state and user input
105
+ outputs=[chatbot, question_input] # Update conversation state and clear the input
 
 
 
 
 
 
 
106
  )
107
 
108
  # Launch the Gradio app