Spaces:
Runtime error
Runtime error
| 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_message = [''] | |
| history = [''] | |
| with gr.Blocks() as demo: | |
| chatbot = gr.Chatbot() | |
| msg = gr.Textbox() | |
| clear = gr.ClearButton([msg, chatbot]) | |
| def user(user_message, history): | |
| return gr.update(value="", interactive=False), history + [[user_message,None]] | |
| def bot(history): | |
| # Remove the second element of the last element of the list | |
| # del history[-1][1] | |
| bot_message = palm.chat( | |
| context=context, | |
| examples=examples, | |
| messages=history[-1][0] | |
| ) | |
| history[-1][1] = "" | |
| for character in bot_message.last: | |
| history[-1][1] += character | |
| time.sleep(0.005) | |
| yield history | |
| response = msg.submit(user, [msg, chatbot], [msg, chatbot], queue=False).then( | |
| bot, chatbot, chatbot | |
| ) | |
| response.then(lambda: gr.update(interactive=True), None, [msg], queue=False) | |
| demo.queue() | |
| demo.launch() |