Spaces:
Build error
Build error
bard api
Browse files
app.py
CHANGED
|
@@ -14,6 +14,7 @@ os.environ['_BARD_API_KEY']="YgjksaVw8UQahn8uKwL3Zve_98YtnUIePVY16j7d8Z3y-tXYrUI
|
|
| 14 |
|
| 15 |
|
| 16 |
|
|
|
|
| 17 |
def huggChat(data):
|
| 18 |
# start a new huggingchat connection
|
| 19 |
chatbot = hugchat.ChatBot(cookie_path="cookies.json")
|
|
@@ -30,8 +31,26 @@ def huggChat(data):
|
|
| 30 |
return 'Hello Sir'
|
| 31 |
|
| 32 |
def bardChat(data):
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
|
| 34 |
-
print(
|
| 35 |
|
| 36 |
def query(payload):
|
| 37 |
response = requests.post(API_URL, headers=headers, json=payload)
|
|
|
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
+
|
| 18 |
def huggChat(data):
|
| 19 |
# start a new huggingchat connection
|
| 20 |
chatbot = hugchat.ChatBot(cookie_path="cookies.json")
|
|
|
|
| 31 |
return 'Hello Sir'
|
| 32 |
|
| 33 |
def bardChat(data):
|
| 34 |
+
# Create a session object using the requests library
|
| 35 |
+
session = requests.Session()
|
| 36 |
+
|
| 37 |
+
# Set the headers for the session
|
| 38 |
+
session.headers = {
|
| 39 |
+
"Host": "bard.google.com",
|
| 40 |
+
"X-Same-Domain": "1",
|
| 41 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
|
| 42 |
+
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
| 43 |
+
"Origin": "https://bard.google.com",
|
| 44 |
+
"Referer": "https://bard.google.com/",
|
| 45 |
+
}
|
| 46 |
+
|
| 47 |
+
# Set the "__Secure-1PSID" cookie with the Bard API key
|
| 48 |
+
session.cookies.set("__Secure-1PSID", os.getenv("_BARD_API_KEY"))
|
| 49 |
+
|
| 50 |
+
# Create a Bard object with the session and a timeout of 30 seconds
|
| 51 |
+
bard = Bard(session=session, timeout=30)
|
| 52 |
|
| 53 |
+
print(bard.get_answer(data)['content'])
|
| 54 |
|
| 55 |
def query(payload):
|
| 56 |
response = requests.post(API_URL, headers=headers, json=payload)
|