-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathapp.py
66 lines (44 loc) · 1.42 KB
/
app.py
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
import streamlit as st
from hugchat import hugchat
from hugchat.login import Login
from dotenv import load_dotenv
import os
load_dotenv()
# Access the environment variables
#email = os.getenv('EMAIL')
#passwd = os.getenv('PASSWORD')
email = st.secrets["email"]
passwd = st.secrets["passwd"]
sign = Login(email, passwd)
cookies = sign.login()
# Save cookies to usercookies/<email>.json
#sign.saveCookies()
sign.saveCookiesToDir()
st.set_page_config(page_title="Book Recommendation Bot - An LLM-powered Streamlit bot")
# header
st.header("Hugging Chat - Book Recommendation Bot")
st.divider()
moods = st.multiselect(
'Select the mood',
['Happy', 'Sad', 'Suspenseful', 'Scary', 'Romantic',
'Adventure', 'Mystical', 'Funny', 'Inspirational',
'Dramatic', 'Thoughtful', 'Thrilling',
'Mysterious', 'Whimsical', 'Dark', "random"])
st.write("")
num_of_recom = st.selectbox(
'Select number of recommendations',
('5', '10', '15'))
st.write("")
selected_moods = ' '.join(moods)
query = "Suggest " + num_of_recom + "books based on the mood " + selected_moods + ". Just give a list of books, no details."
def recom(query):
chatbot = hugchat.ChatBot(cookies=cookies.get_dict())
response = chatbot.query(query)
return response
gen = st.button("Generate")
if gen:
try:
bot_response = recom(query)
st.text(bot_response)
except:
st.subheader("Please Try Again")