File size: 1,418 Bytes
96b891b
 
20633a7
541f4f3
96b891b
9eff97e
cadd469
9eff97e
541f4f3
9eff97e
 
541f4f3
96b891b
 
 
541f4f3
96b891b
 
 
 
 
 
 
 
 
541f4f3
96b891b
 
 
 
 
 
 
cadd469
 
 
 
 
541f4f3
cf2c4fc
 
cadd469
 
96b891b
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
import requests
import os
import streamlit as st
import json
from bardapi import Bard
# from dotenv import load_dotenv

# load_dotenv()

bardKey = "aQjBGndz_p9qdmaTSfmedlQODTMCa8iPeurM5mlJbzBzLISxmHRjXS-SIhbK_WsL3WIFUA."
# os.environ.get('token')

def bardChat(data):
    # Create a session object using the requests library
    session = requests.Session()
    
    # Set the headers for the session
    session.headers = {
                "Host": "bard.google.com",
                "X-Same-Domain": "1",
                "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
                "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
                "Origin": "https://bard.google.com",
                "Referer": "https://bard.google.com/",
            }
    
    # Set the "__Secure-1PSID" cookie with the Bard API key
    session.cookies.set("__Secure-1PSID", bardKey) 
    
    # Create a Bard object with the session and a timeout of 30 seconds
    bard = Bard(token=bardKey, session=session, timeout=30)
    answer = bard.get_answer(data)['content']
    print(answer)
    reply = {
        'message':answer,
        'action':'null'
    }
    return reply

uinput = st.chat_input("Enter your message")
with st.chat_message("assistant"):
    bardanswer = bardChat(uinput)
    st.markdown(bardanswer['message'])