Spaces:
Runtime error
Runtime error
Commit
·
70b9609
1
Parent(s):
5591b57
Update app.py
Browse files
app.py
CHANGED
@@ -1,19 +1,51 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
2 |
import bardapi
|
3 |
|
4 |
-
# Set your Secure-1PSID value to
|
5 |
-
token = '
|
6 |
|
7 |
-
|
8 |
-
|
9 |
-
response = bardapi.core.Bard(token).get_answer(input_text)
|
10 |
-
return response
|
11 |
|
12 |
-
# Create a
|
13 |
-
|
14 |
-
fn=get_answer,
|
15 |
-
inputs=gr.Textbox(lines=2, placeholder="Enter your input text"),
|
16 |
-
outputs="text")
|
17 |
|
18 |
-
#
|
19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import gradio as gr
|
2 |
+
import random
|
3 |
+
import time
|
4 |
import bardapi
|
5 |
|
6 |
+
# Set your Secure-1PSID value to token
|
7 |
+
token = 'cQjDrFOQjkhOHHHCW54Tc7IKyphnqos-A-IpmgjVa9p3_ZFFa5Ilet-heMO8Xm3TM1Y5vw.'
|
8 |
|
9 |
+
# Initialize the BARD API client
|
10 |
+
bard = bardapi.core.Bard(token)
|
|
|
|
|
11 |
|
12 |
+
# Create a chatbot instance
|
13 |
+
chatbot = gr.Chatbot()
|
|
|
|
|
|
|
14 |
|
15 |
+
# Define the function to respond to user input
|
16 |
+
def respond(message, chat_history):
|
17 |
+
# Send the user input to BARD API for a response
|
18 |
+
response = bard.get_answer(message)
|
19 |
+
bot_message = response['answer']
|
20 |
+
|
21 |
+
# Append user input and bot response to chat history
|
22 |
+
chat_history.append((message, bot_message))
|
23 |
+
|
24 |
+
# Pause for a few seconds to simulate processing time
|
25 |
+
time.sleep(2)
|
26 |
+
return "", chat_history
|
27 |
+
|
28 |
+
# Create a text input box and a send button
|
29 |
+
msg = gr.InputBox(lines=1, label="User Input")
|
30 |
+
send_button = gr.Button(text="Send")
|
31 |
+
|
32 |
+
# Create a chat output box
|
33 |
+
chat_output = gr.Textbox(readonly=True, label="Chat History")
|
34 |
+
|
35 |
+
# When the send button is clicked, trigger the response function
|
36 |
+
def on_button_click():
|
37 |
+
message = msg.value
|
38 |
+
chat_history = chat_output.value
|
39 |
+
new_chat_history, _ = respond(message, chat_history)
|
40 |
+
chat_output.update(new_chat_history)
|
41 |
+
|
42 |
+
send_button.onclick(on_button_click)
|
43 |
+
|
44 |
+
# Create a layout combining the input box, send button, and chat output box
|
45 |
+
layout = gr.Grid([msg, send_button], [chat_output], n_rows=2, n_cols=1)
|
46 |
+
|
47 |
+
# Create the interface
|
48 |
+
iface = gr.Interface(fn=None, inputs=layout, outputs="text")
|
49 |
+
|
50 |
+
# Launch the interface
|
51 |
+
iface.launch()
|