Illia56 commited on
Commit
56681c6
Β·
1 Parent(s): 46de908

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -0
app.py ADDED
@@ -0,0 +1,55 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ from bardapi import Bard
3
+ import os
4
+ import requests
5
+
6
+
7
+ session = requests.Session()
8
+ session.headers = {
9
+ "Host": "bard.google.com",
10
+ "X-Same-Domain": "1",
11
+ "User-Agent": "Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.114 Safari/537.36",
12
+ "Content-Type": "application/x-www-form-urlencoded;charset=UTF-8",
13
+ "Origin": "https://bard.google.com",
14
+ "Referer": "https://bard.google.com/",
15
+ }
16
+ session.cookies.set("__Secure-1PSID", os.getenv("_BARD_API_KEY"))
17
+
18
+ bard = Bard(token=token, session=session)
19
+
20
+ TITLE = "Palm 2🌴 Chatbot"
21
+ DESCRIPTION = """
22
+ """
23
+
24
+
25
+
26
+ # Prediction function
27
+ def predict(message):
28
+ with st.status("Requesting Palm-2🌴..."):
29
+ st.write("Requesting API...")
30
+ response = bard.get_answer(message)
31
+ st.write("Done...")
32
+ for i in response['links']:
33
+ st.image(i)
34
+ st.write("Checking images...")
35
+ return response['content']
36
+
37
+ # Streamlit UI
38
+ st.title(TITLE)
39
+ st.write(DESCRIPTION)
40
+
41
+
42
+
43
+ # React to user input
44
+ if prompt := st.chat_input("Ask Palm 2 anything..."):
45
+ # Display user message in chat message container
46
+ st.chat_message("human",avatar = "πŸ§‘β€πŸ’»").markdown(prompt)
47
+ # Add user message to chat history
48
+ st.session_state.messages.append({"role": "human", "content": prompt})
49
+
50
+ response = predict(prompt)
51
+ # Display assistant response in chat message container
52
+ with st.chat_message("assistant", avatar='🌴'):
53
+ st.markdown(response)
54
+ # Add assistant response to chat history
55
+ st.session_state.messages.append({"role": "assistant", "content": response})