Update app.py
Browse files
app.py
CHANGED
@@ -1,53 +1,36 @@
|
|
1 |
-
import
|
|
|
2 |
import json
|
3 |
-
from
|
4 |
|
5 |
-
|
6 |
|
7 |
-
login, signup = st.tabs(["Login", "Signup"])
|
8 |
|
9 |
|
10 |
-
|
11 |
-
|
12 |
-
|
13 |
-
return json.load(json_file)
|
14 |
-
|
15 |
|
16 |
-
|
17 |
-
|
18 |
-
|
19 |
-
|
20 |
-
|
21 |
-
|
22 |
-
|
23 |
-
|
24 |
-
|
25 |
-
data = loadFile()
|
26 |
-
for user in data["users"]:
|
27 |
-
if username == user["username"] and password == user["password"]:
|
28 |
-
st.success("Logged in as {}".format(username))
|
29 |
-
st.balloons()
|
30 |
-
home.page()
|
31 |
-
else:
|
32 |
-
st.error("Incorrect username or password")
|
33 |
-
|
34 |
-
def SignupPage():
|
35 |
-
st.title("Signup")
|
36 |
-
username = st.text_input("Username", key="svusername")
|
37 |
-
email = st.text_input("Email", key="svemail")
|
38 |
-
password = st.text_input("Password", type="password", key="svpassword")
|
39 |
-
if st.button("Signup"):
|
40 |
-
data = loadFile()
|
41 |
-
data["users"].append({"username": username, "password": password, "email": email})
|
42 |
-
saveFile(data)
|
43 |
-
st.success("Successfully signed up as {}".format(username))
|
44 |
-
|
45 |
-
with login:
|
46 |
-
LoginPage()
|
47 |
|
48 |
-
with
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
|
|
|
|
|
|
|
|
53 |
|
|
|
|
|
|
|
|
1 |
+
import requests
|
2 |
+
import os
|
3 |
import json
|
4 |
+
from bardapi import Bard
|
5 |
|
6 |
+
bardKey = os.environ.get('_BARD_API_KEY')
|
7 |
|
|
|
8 |
|
9 |
|
10 |
+
def bardChat(data):
|
11 |
+
# Create a session object using the requests library
|
12 |
+
session = requests.Session()
|
|
|
|
|
13 |
|
14 |
+
# Set the headers for the session
|
15 |
+
session.headers = {
|
16 |
+
"Host": "bard.google.com",
|
17 |
+
"X-Same-Domain": "1",
|
18 |
+
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
|
19 |
+
"Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
|
20 |
+
"Origin": "https://bard.google.com",
|
21 |
+
"Referer": "https://bard.google.com/",
|
22 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
|
24 |
+
# Set the "__Secure-1PSID" cookie with the Bard API key
|
25 |
+
session.cookies.set("__Secure-1PSID", bardKey)
|
26 |
+
|
27 |
+
# Create a Bard object with the session and a timeout of 30 seconds
|
28 |
+
bard = Bard(token=bardKey, session=session, timeout=30)
|
29 |
+
answer = bard.get_answer(data)['content']
|
30 |
+
print(answer)
|
31 |
+
|
32 |
+
return json.dumps({'message':answer,'action':'null'})
|
33 |
|
34 |
+
uinput = input("You: ")
|
35 |
+
print(f"Uoy: {bardChat(uinput)}")
|
36 |
+
|