-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
117 lines (107 loc) · 3.74 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
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
import streamlit as st
from rag import *
faiss_path = 'faiss_index.pkl'
load_dotenv()
# create db if not exists
if not os.path.exists(faiss_path):
data_path = './datasets/txt_files'
create_db(data_path, faiss_path)
# Interface Streamlit
st.set_page_config(page_title="Chatbot Sportif Expert", page_icon="⚽", layout="wide")
st.markdown(
"""
<style>
body {
background-color: #1e1e1e;
color: white;
}
.chat-container {
background-color: #2a2a2a;
padding: 20px;
border-radius: 10px;
height: 500px;
overflow-y: auto;
display: flex;
flex-direction: column-reverse;
}
.stTextInput {
border-radius: 10px;
border: 1px solid #ccc;
width: 100%;
}
.stButton>button {
border-radius: 10px;
background-color: #007BFF;
color: white;
padding: 10px 20px;
font-size: 16px;
}
.user-message {
background-color: #007BFF;
color: white;
padding: 10px;
border-radius: 10px;
margin-bottom: 10px;
text-align: right;
}
.assistant-message {
background-color: #444;
color: white;
padding: 10px;
border-radius: 10px;
margin-bottom: 10px;
text-align: left;
}
.chat-history {
flex-grow: 1;
overflow-y: auto;
display: flex;
flex-direction: column-reverse;
height: 400px;
padding-bottom: 60px;
}
.fixed-input {
position: fixed;
bottom: 0;
left: 0;
width: 100%;
background-color: #2a2a2a;
padding: 10px;
z-index: 10;
}
</style>
""",
unsafe_allow_html=True
)
st.title("🏆 Chatbot Sportif Expert")
st.write("Posez vos questions sur l'analyse tactique, les performances des joueurs et obtenez des recommandations personnalisées !")
chat_container = st.container()
if "messages" not in st.session_state:
st.session_state.messages = []
with chat_container:
st.markdown("### Discussion en cours")
chat_history = st.container()
with chat_history:
for message in reversed(st.session_state.messages): # Keep order consistent
if message["role"] == "user":
st.markdown(f'<div class="user-message">🙋 {message["content"]}</div>', unsafe_allow_html=True)
else:
st.markdown(f'<div class="assistant-message">⚽ {message["content"]}</div>', unsafe_allow_html=True)
# Barre d'entrée en bas
st.markdown('<div class="fixed-input">', unsafe_allow_html=True)
user_input = st.text_input("Tapez votre message ici...", key="user_input")
send_button = st.button("Envoyer")
st.markdown('</div>', unsafe_allow_html=True)
if send_button and user_input:
st.session_state.messages.insert(0, {"role": "user", "content": user_input}) # Add new messages at the beginning
with chat_history:
st.markdown(f'<div class="user-message">🙋 {user_input}</div>', unsafe_allow_html=True)
response = query_rag(user_input, faiss_path)
response = truncate_from_keyword(response, 'Answer:')
print(response)
st.session_state.messages.insert(0, {"role": "assistant", "content": response})
with chat_history:
st.markdown(f'<div class="assistant-message">⚽ {response}</div>', unsafe_allow_html=True)
# Infos Chatbot
st.sidebar.markdown("### ℹ️ Infos du Chatbot")
st.sidebar.info("💡 Ce chatbot analyse les performances sportives et fournit des conseils basés sur des analyses tactiques avancées.")