-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdemo.py
188 lines (169 loc) · 7.53 KB
/
demo.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
import streamlit as st
from dataclasses import dataclass
from typing import Literal
from langchain.chat_models import ChatGooglePalm
from langchain.chains import ConversationChain
from langchain.chains.conversation.memory import ConversationSummaryMemory
st.set_page_config(
page_title="ALAMAL",
page_icon="🎗️",
layout="wide",
initial_sidebar_state="collapsed",
menu_items={
'Get help' : 'https://github.com/achraf110',
'Report a bug' : 'https://github.com/achraf110',
'About':"# ALAMAL, You are not alone."
}
)
#--------------- Back end ----------
@dataclass
class Message :
origin: Literal["human","ai"]
message: str
def load_css():
with open('static/style.css',"r") as f:
css = f"<style>{f.read()}</style>"
st.markdown(css, unsafe_allow_html=True)
# Behavior after click
def on_click_callback():
human_prompt = st.session_state.human_prompt
llm_response = st.session_state.conversation.run(
human_prompt
)
st.session_state.history.append(
Message('human',human_prompt)
)
st.session_state.history.append(
Message("ai",llm_response)
)
st.session_state.human_prompt = " "
# API LOAD PALM CHATBOT
def api():
llm = ChatGooglePalm(
google_api_key=st.secrets["palm_api_key"],
temperature=0.4
)
return llm
#history show up
def initilize_session_state():
if "history" not in st.session_state:
st.session_state.history = []
if "conversation" not in st.session_state:
llm = api()
st.session_state.conversation = ConversationChain(
llm=llm)
#--------------- Front end-------------------
load_css()
initilize_session_state()
# This is the title and the initialisation of the containers
st.title("ALAMAL this is your Chatbot assistant")
chat_placeholder = st.container()
prompt_placeholder = st.form("chat-form")
# Streamlit built-in function for user interaction
with st.sidebar:
st.sidebar.image("./static/logo.png")
st.sidebar.markdown("---")
header = st.sidebar.header("ALAMAL : Support When You Need It the Most")
st.markdown("""
**ALAMAL** offers an innovative web application with an integrated AI chatbot, tailoring its
advice based on each patient's case. This platform combines exchange, reliable information,
and emotional support, thereby enhancing the healing journey for cancer patients.""")
# Contributors
st.sidebar.markdown("---")
with st.expander('Contributors'):
columns = st.columns([3,0.5,0.5])
with columns[0]:
st.write("**CHAHBI Achraf**")
with columns[1]:
st.write("""<div style="width:100%;text-align:center;">
<a href="https://www.linkedin.com/in/achraf-chahbi" style="float:center">
<img src="./app/static/LinkedIn_logo_initials.png" width="22px"></img>
</a></div>""",unsafe_allow_html=True)
with columns[2]:
st.write("""<div style="width:100%;text-align:center;">
<a href="https://www.github.com/achraf110" style="float:center">
<img src="./app/static/github-sign.png" width="22px"></img>
</a></div>""",unsafe_allow_html=True)
columns = st.columns([3,0.5,0.5])
with columns[0]:
st.write("**EL JABRI Nabil**")
with columns[1]:
st.write("""<div style="width:100%;text-align:center;">
<a href="https://www.linkedin.com/in/nabil-eljabri-77860723b/" style="float:center">
<img src="./app/static/LinkedIn_logo_initials.png" width="22px"></img>
</a></div>""",unsafe_allow_html=True)
with columns[2]:
st.write("""<div style="width:100%;text-align:center;">
<a href="https://github.com/drdarkfrancis" style="float:center">
<img src="./app/static/github-sign.png" width="22px"></img>
</a></div>""",unsafe_allow_html=True)
columns = st.columns([3,0.5,0.5])
with columns[0]:
st.write("**LAKRARSI El Batoul**")
with columns[1]:
st.write("""<div style="width:100%;text-align:center;">
<a href="https://www.linkedin.com/in/el-batoul-lakrarsi/" style="float:center">
<img src="./app/static/LinkedIn_logo_initials.png" width="22px"></img>
</a></div>""",unsafe_allow_html=True)
columns = st.columns([3,0.5,0.5])
with columns[0]:
st.write("**EL HAI Ibtissam**")
with columns[1]:
st.write("""<div style="width:100%;text-align:center;">
<a href="https://www.linkedin.com/in/ibtissam-el-hai-9417b0197" style="float:center">
<img src="./app/static/LinkedIn_logo_initials.png" width="22px"></img>
</a></div>""",unsafe_allow_html=True)
columns = st.columns([3,0.5,0.5])
with columns[0]:
st.write("**BATAHI Salma**")
with columns[1]:
st.write("""<div style="width:100%;text-align:center;">
<a href="https://www.linkedin.com/in/salma-batahi-/" style="float:center">
<img src="./app/static/LinkedIn_logo_initials.png" width="22px"></img>
</a></div>""",unsafe_allow_html=True)
columns = st.columns([3,0.5,0.5])
with columns[0]:
st.write("**ELMIMOUNI Firdaous**")
with columns[1]:
st.write("""<div style="width:100%;text-align:center;">
<a href="https://www.linkedin.com/in/firdaous-elmimouni-62b737232" style="float:center">
<img src="./app/static/LinkedIn_logo_initials.png" width="22px"></img>
</a></div>""",unsafe_allow_html=True)
# University drop down
with st.expander("University"):
st.image("./static/uni_logo.png")
with st.expander('Coordinator'):
columns = st.columns([3,1])
with columns[0]:
st.write("**Pr.BACHIRI Mustapha**")
with columns[1]:
st.write("""<div style="width:100%;text-align:center;">
<a href="https://www.researchgate.net/profile/Mustapha-Bachiri-2" style="float:center">
<img src="./app/static/researchgate.png" width="22px"></img>
</a></div>""",unsafe_allow_html=True)
with chat_placeholder: # chat display
for chat in st.session_state.history:
div = f"""
<div class="chat-row {
'' if chat.origin == "ai" else "row-reverse"}">
<img class="chat-icon" src='./app/static/{"robot.png" if chat.origin == 'ai' else 'user.png '}'
width=32 height=32>
<div class="chat-bubble
{"ai-bubble" if chat.origin == 'ai' else "human-bubble"}">{chat.message}</div>
</div>
"""
st.markdown(div,unsafe_allow_html=True)
# Prompt behavior
with prompt_placeholder:
cols = st.columns((6,1))
cols[0].text_input(
label="chat",
value="Hello ALAMAL",
label_visibility="collapsed",
key='human_prompt'
)
cols[1].form_submit_button(
label="Submit",
type='primary',
on_click=on_click_callback
)