mery22 commited on
Commit
6812dc5
1 Parent(s): 9691e77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -15
app.py CHANGED
@@ -70,16 +70,25 @@ qa = RetrievalQA.from_chain_type(
70
  chain_type_kwargs={"prompt": prompt},
71
  )
72
  import streamlit as st
 
 
 
 
 
 
 
 
 
 
73
 
74
  # Streamlit interface with improved aesthetics
75
  st.set_page_config(page_title="Alter-IA Chat", page_icon="🤖")
76
 
77
  # Define function to handle user input and display chatbot response
78
  def chatbot_response(user_input):
79
- response = qa.run(user_input)
80
  return response
81
 
82
-
83
  # Create columns for logos
84
  col1, col2, col3 = st.columns([2, 3, 2])
85
 
@@ -88,21 +97,13 @@ with col1:
88
 
89
  with col3:
90
  st.image("Altereo logo 2023 original - eau et territoires durables.png", width=150, use_column_width=True) # Adjust image path and size as needed
91
- # Streamlit components
92
- # Ajouter un peu de CSS pour centrer le texte
93
- # Ajouter un peu de CSS pour centrer le texte et le colorer en orange foncé
94
  st.markdown("""
95
  <style>
96
  .centered-text {
97
  text-align: center;
98
  }
99
- </style>
100
- """, unsafe_allow_html=True)
101
-
102
- # Utiliser la classe CSS pour centrer et colorer le texte
103
- st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖 </h3>', unsafe_allow_html=True)
104
- st.markdown("""
105
- <style>
106
  .centered-orange-text {
107
  text-align: center;
108
  color: darkorange;
@@ -110,9 +111,10 @@ st.markdown("""
110
  </style>
111
  """, unsafe_allow_html=True)
112
 
113
- # Centrer le texte principal
114
- # Centrer et colorer en orange foncé le texte spécifique
115
  st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique "</p>', unsafe_allow_html=True)
 
116
  # Input and button for user interaction
117
  user_input = st.text_input("You:", "")
118
  submit_button = st.button("Ask 📨")
@@ -122,10 +124,40 @@ if submit_button:
122
  if user_input.strip() != "":
123
  bot_response = chatbot_response(user_input)
124
  st.markdown("### Bot:")
125
- st.text_area("", value=bot_response, height=600)
126
  else:
127
  st.warning("⚠️ Please enter a message.")
128
 
129
  # Motivational quote at the bottom
130
  st.markdown("---")
131
  st.markdown("*La collaboration est la clé du succès. Chaque question trouve sa réponse, chaque défi devient une opportunité.*")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
70
  chain_type_kwargs={"prompt": prompt},
71
  )
72
  import streamlit as st
73
+ import pandas as pd
74
+ import os
75
+
76
+ # Ensure the star rating component is available
77
+ try:
78
+ from streamlit_star_rating import st_star_rating
79
+ except ImportError:
80
+ st.write("Installing required package: streamlit-star-rating")
81
+ !pip install streamlit-star-rating
82
+ from streamlit_star_rating import st_star_rating
83
 
84
  # Streamlit interface with improved aesthetics
85
  st.set_page_config(page_title="Alter-IA Chat", page_icon="🤖")
86
 
87
  # Define function to handle user input and display chatbot response
88
  def chatbot_response(user_input):
89
+ response = "This is a dummy response." # Replace with actual chatbot logic
90
  return response
91
 
 
92
  # Create columns for logos
93
  col1, col2, col3 = st.columns([2, 3, 2])
94
 
 
97
 
98
  with col3:
99
  st.image("Altereo logo 2023 original - eau et territoires durables.png", width=150, use_column_width=True) # Adjust image path and size as needed
100
+
101
+ # Add custom CSS for centered and colored text
 
102
  st.markdown("""
103
  <style>
104
  .centered-text {
105
  text-align: center;
106
  }
 
 
 
 
 
 
 
107
  .centered-orange-text {
108
  text-align: center;
109
  color: darkorange;
 
111
  </style>
112
  """, unsafe_allow_html=True)
113
 
114
+ # Display title and subtitle
115
+ st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖 </h3>', unsafe_allow_html=True)
116
  st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique "</p>', unsafe_allow_html=True)
117
+
118
  # Input and button for user interaction
119
  user_input = st.text_input("You:", "")
120
  submit_button = st.button("Ask 📨")
 
124
  if user_input.strip() != "":
125
  bot_response = chatbot_response(user_input)
126
  st.markdown("### Bot:")
127
+ st.text_area("", value=bot_response, height=200)
128
  else:
129
  st.warning("⚠️ Please enter a message.")
130
 
131
  # Motivational quote at the bottom
132
  st.markdown("---")
133
  st.markdown("*La collaboration est la clé du succès. Chaque question trouve sa réponse, chaque défi devient une opportunité.*")
134
+
135
+ # Star rating system
136
+ st.markdown("### Évaluez notre service :")
137
+ rating = st_star_rating('Rate the response', 5, 0)
138
+
139
+ # Save rating to a file
140
+ ratings_file = "user_ratings.csv"
141
+
142
+ if rating > 0:
143
+ if not os.path.exists(ratings_file):
144
+ # Create a new file with headers if it doesn't exist
145
+ df = pd.DataFrame(columns=["User Input", "Bot Response", "Rating"])
146
+ df.to_csv(ratings_file, index=False)
147
+
148
+ # Append new rating to the file
149
+ new_rating = {"User Input": user_input, "Bot Response": bot_response, "Rating": rating}
150
+ df = pd.read_csv(ratings_file)
151
+ df = df.append(new_rating, ignore_index=True)
152
+ df.to_csv(ratings_file, index=False)
153
+ st.success("Thank you for your feedback!")
154
+
155
+ # Display the contents of the ratings file
156
+ st.markdown("### User Ratings:")
157
+ if os.path.exists(ratings_file):
158
+ df = pd.read_csv(ratings_file)
159
+ st.write(df)
160
+ else:
161
+ st.write("No ratings yet.")
162
+
163
+