CosmoAI commited on
Commit
96b891b
·
1 Parent(s): 3966b73

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -45
app.py CHANGED
@@ -1,53 +1,36 @@
1
- import streamlit as st
 
2
  import json
3
- from pages.home import page
4
 
5
- st.set_page_config(page_title="Reminder App", page_icon=":bell:", layout="centered")
6
 
7
- login, signup = st.tabs(["Login", "Signup"])
8
 
9
 
10
- @st.cache_data
11
- def loadFile():
12
- with open("database/test.json") as json_file:
13
- return json.load(json_file)
14
-
15
 
16
- def saveFile(data):
17
- with open("database/test.json", "w") as file:
18
- json.dump(data, file, indent=4)
19
-
20
- def LoginPage():
21
- st.title("Login")
22
- username = st.text_input("Username", key="username")
23
- password = st.text_input("Password", type="password", key="password")
24
- if st.button("Login"):
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 signup:
49
- SignupPage()
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
+