AashitaK commited on
Commit
88d9524
·
verified ·
1 Parent(s): d04f423

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +20 -20
app.py CHANGED
@@ -18,6 +18,25 @@ if not vector_store_id:
18
  # Initialize the ResponseManager with the vector store ID
19
  response_manager = ResponseManager(vector_store_id)
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  # Set parameters for the response generation
22
  model = "gpt-4o-mini" # Set the model to be used for response generation
23
  temperature=0 # Set the temperature for response generation
@@ -47,25 +66,6 @@ if not all([chatbot_title, chatbot_description,
47
  chatbot_submit_button, chatbot_reset_button]):
48
  raise ValueError("One or more configuration parameters are missing or empty.")
49
 
50
- # Define the chatbot function to handle user queries and generate responses
51
- def chatbot(query: str) -> str:
52
- """
53
- Function to handle the chatbot interaction.
54
- :param query: The user query to respond to.
55
- :return: The response text from the chatbot.
56
- """
57
- try:
58
- if query.strip():
59
- response = response_manager.create_response(query, model, temperature, max_output_tokens, max_num_results)
60
- if not response:
61
- return "Sorry, I couldn't generate a response at this time. Please try again later."
62
- # Return the response from the AI model
63
- return response
64
- else:
65
- return "Please enter a valid query."
66
- except Exception as e:
67
- return str(e)
68
-
69
  # Define the reset function
70
  def reset_output():
71
  return chatbot_output_placeholder
@@ -104,7 +104,7 @@ with gr.Blocks() as demo:
104
  reset.click(fn=reset_output, inputs=None, outputs=output)
105
 
106
  # Enable "Enter" key to submit
107
- user_input.submit(fn=chatbot, inputs=user_input, outputs=output)
108
 
109
  if __name__ == "__main__":
110
  demo.launch()
 
18
  # Initialize the ResponseManager with the vector store ID
19
  response_manager = ResponseManager(vector_store_id)
20
 
21
+ # Define the chatbot function to handle user queries and generate responses
22
+ def chat_interaction(query: str) -> str:
23
+ """
24
+ Function to handle the chatbot interaction.
25
+ :param query: The user query to respond to.
26
+ :return: The response text from the chatbot.
27
+ """
28
+ try:
29
+ if query.strip():
30
+ response = response_manager.create_response(query, model, temperature, max_output_tokens, max_num_results)
31
+ if not response:
32
+ return "Sorry, I couldn't generate a response at this time. Please try again later."
33
+ # Return the response from the AI model
34
+ return response
35
+ else:
36
+ return "Please enter a valid query."
37
+ except Exception as e:
38
+ return str(e)
39
+
40
  # Set parameters for the response generation
41
  model = "gpt-4o-mini" # Set the model to be used for response generation
42
  temperature=0 # Set the temperature for response generation
 
66
  chatbot_submit_button, chatbot_reset_button]):
67
  raise ValueError("One or more configuration parameters are missing or empty.")
68
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
69
  # Define the reset function
70
  def reset_output():
71
  return chatbot_output_placeholder
 
104
  reset.click(fn=reset_output, inputs=None, outputs=output)
105
 
106
  # Enable "Enter" key to submit
107
+ user_input.submit(fn=chat_interaction, inputs=user_input, outputs=output)
108
 
109
  if __name__ == "__main__":
110
  demo.launch()