bot / app.py
Antoine245's picture
Update app.py
8a83c76
raw
history blame
1.11 kB
import gradio as gr
import os
import time
import google.generativeai as palm
palm.configure(api_key=os.environ.get("palm_key"))
defaults = {
'model': 'models/chat-bison-001',
'temperature': 0.25,
'candidate_count': 1,
'top_k': 40,
'top_p': 0.95,
}
context = "You're a computer failure assistant"
examples = [
[
"Hey my computer is broken",
"Hey, what is the issue with your computer?"
]
]
user_input = ['']
chat_history = ['']
with gr.Blocks() as demo:
chatbot = gr.Chatbot()
msg = gr.Textbox()
clear = gr.ClearButton([msg, chatbot])
def respond(message, chat_history):
chat_history.append(message) # Initialize chat history
bot_message = palm.chat(
context=context,
examples=examples,
messages=chat_history
)
bot_message = bot_message.last # Get the last response
chat_history.append(bot_message) # Append the bot's message to the chat history
time.sleep(2)
return chat_history, ""
msg.submit(respond,[msg,chatbot],[chatbot,msg])
demo.launch()