ask-me-anything / app.py
kendrickfff's picture
Update app.py
de24765 verified
raw
history blame
1.87 kB
import os
import gradio as gr
from langchain_google_genai.chat_models import ChatGoogleGenerativeAI
# Set the path to the service account key
os.environ["GOOGLE_APPLICATION_CREDENTIALS"] = "./firm-catalyst-437006-s4-407500537db5.json"
# Initialize the language model with required parameters
# Replace 'your-model-name' with the actual model you intend to use
llm = ChatGoogleGenerativeAI(model='gemini-1.5-pro')
def chat_with_gemini(message, chat_history):
# Placeholder function to simulate bot response
bot_response = "You said: " + message
chat_history.append((message, bot_response))
return chat_history, chat_history
# Create a Gradio interface
with gr.Blocks() as iface:
gr.Markdown("# Ken Chatbot")
gr.Markdown("Ask me anything!")
chatbot = gr.Chatbot(elem_id="chatbot") # Initialize the chatbot with an element ID for styling
msg = gr.Textbox(label="Type your message here...", placeholder="Enter your message and press enter to send your message...")
state = gr.State([]) # Store chat history
# Set up the interaction for when the user submits a message
msg.submit(chat_with_gemini, [msg, state], [chatbot, state]) # Update chatbot and state with new messages
msg.submit(lambda: "", None, msg) # Clear the input box after submission
# CSS for styling the chatbot messages
iface.css("""
#chatbot .message.user {
background-color: #DCF8C6;
border-radius: 15px;
padding: 8px 12px;
margin: 5px 50px 5px auto;
max-width: 70%;
text-align: right;
}
#chatbot .message.bot {
background-color: #E1E1E1;
border-radius: 15px;
padding: 8px 12px;
margin: 5px auto 5px 50px;
max-width: 70%;
text-align: left;
}
""")
# Launch the interface with debugging enabled
iface.launch(debug=True)