kendrickfff commited on
Commit
4e4c8dd
·
verified ·
1 Parent(s): 6f9707c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +7 -11
app.py CHANGED
@@ -6,13 +6,13 @@ from langchain_google_genai.chat_models import ChatGoogleGenerativeAI
6
  os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./firm-catalyst-437006-s4-407500537db5.json"
7
 
8
  # Chat function
9
- def chat_with_gemini(user_input, chat_history=[]):
10
  try:
11
  # Append the user input to the chat history
12
  chat_history.append(("User", user_input))
13
 
14
- # Get response from the model
15
- response = llm.predict(user_input) # Assuming 'predict' is the correct method
16
 
17
  # Append the bot's response to the chat history
18
  chat_history.append(("Bot", response))
@@ -29,17 +29,13 @@ with gr.Blocks() as iface:
29
  gr.Markdown("# Chatbot with Gemini 1.5")
30
  gr.Markdown("Ask me anything!")
31
 
32
- chatbot = gr.Chatbot()
33
- msg = gr.Textbox(label="Type your message here...")
34
  state = gr.State([]) # Store chat history
35
 
36
- # Define the interaction between components
37
- def send_message(user_input, chat_history):
38
- return chat_with_gemini(user_input, chat_history)
39
-
40
  # Set up the interaction for when the user submits a message
41
- msg.submit(send_message, [msg, state], [chatbot, state])
42
- msg.submit(lambda: "", None, msg) # Clear input box after submission
43
 
44
  # Launch the interface with debugging enabled
45
  iface.launch(debug=True)
 
6
  os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./firm-catalyst-437006-s4-407500537db5.json"
7
 
8
  # Chat function
9
+ def chat_with_gemini(user_input, chat_history):
10
  try:
11
  # Append the user input to the chat history
12
  chat_history.append(("User", user_input))
13
 
14
+ # Get response from the model (assuming 'predict' is the correct method)
15
+ response = llm.predict(user_input)
16
 
17
  # Append the bot's response to the chat history
18
  chat_history.append(("Bot", response))
 
29
  gr.Markdown("# Chatbot with Gemini 1.5")
30
  gr.Markdown("Ask me anything!")
31
 
32
+ chatbot = gr.Chatbot() # Initialize the chatbot
33
+ msg = gr.Textbox(label="Type your message here...", placeholder="Enter your message...") # Text input for user messages
34
  state = gr.State([]) # Store chat history
35
 
 
 
 
 
36
  # Set up the interaction for when the user submits a message
37
+ msg.submit(chat_with_gemini, [msg, state], [chatbot]) # Update chatbot with new messages
38
+ msg.submit(lambda: "", None, msg) # Clear the input box after submission
39
 
40
  # Launch the interface with debugging enabled
41
  iface.launch(debug=True)