File size: 1,503 Bytes
c652bdc
70b9609
 
c652bdc
 
70b9609
 
c652bdc
70b9609
 
c652bdc
70b9609
 
c652bdc
70b9609
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
49
50
51
import gradio as gr
import random
import time
import bardapi

# Set your Secure-1PSID value to token
token = 'cQjDrFOQjkhOHHHCW54Tc7IKyphnqos-A-IpmgjVa9p3_ZFFa5Ilet-heMO8Xm3TM1Y5vw.'

# Initialize the BARD API client
bard = bardapi.core.Bard(token)

# Create a chatbot instance
chatbot = gr.Chatbot()

# Define the function to respond to user input
def respond(message, chat_history):
    # Send the user input to BARD API for a response
    response = bard.get_answer(message)
    bot_message = response['answer']

    # Append user input and bot response to chat history
    chat_history.append((message, bot_message))

    # Pause for a few seconds to simulate processing time
    time.sleep(2)
    return "", chat_history

# Create a text input box and a send button
msg = gr.InputBox(lines=1, label="User Input")
send_button = gr.Button(text="Send")

# Create a chat output box
chat_output = gr.Textbox(readonly=True, label="Chat History")

# When the send button is clicked, trigger the response function
def on_button_click():
    message = msg.value
    chat_history = chat_output.value
    new_chat_history, _ = respond(message, chat_history)
    chat_output.update(new_chat_history)

send_button.onclick(on_button_click)

# Create a layout combining the input box, send button, and chat output box
layout = gr.Grid([msg, send_button], [chat_output], n_rows=2, n_cols=1)

# Create the interface
iface = gr.Interface(fn=None, inputs=layout, outputs="text")

# Launch the interface
iface.launch()