File size: 1,097 Bytes
46bef1e
e648b17
46bef1e
8274426
e648b17
6baf09a
b40d855
 
e648b17
 
 
 
 
b40d855
e648b17
 
 
b40d855
e648b17
 
 
 
b40d855
e648b17
61c9c77
 
1b555fc
71c95a6
4ac79c2
61c9c77
 
4ac79c2
7121a7c
8c633f6
294398a
 
 
 
 
5b1b306
8c633f6
294398a
26af817
71c95a6
61c9c77
4ac79c2
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
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(gr.Textbox())
    clear = gr.ClearButton([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

    chatbot.on_submit(respond,[chatbot],[chatbot])

demo.launch()