mery22 commited on
Commit
68be054
·
verified ·
1 Parent(s): 7969b9a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -58
app.py CHANGED
@@ -67,7 +67,10 @@ qa = RetrievalQA.from_chain_type(
67
  chain_type_kwargs={"prompt": prompt},
68
  )
69
 
70
- # Streamlit UI setup
 
 
 
71
  st.set_page_config(page_title="Alter-IA Chat", page_icon="🤖")
72
 
73
  # Define function to handle user input and display chatbot response
@@ -75,48 +78,16 @@ def chatbot_response(user_input):
75
  response = qa.run(user_input)
76
  return response
77
 
78
- # Define function to save feedback to CSV
79
- def save_feedback(question, response, rating, comment):
80
- try:
81
- filename = 'feedback.csv'
82
- file_exists = os.path.isfile(filename)
83
-
84
- # Open CSV file and append the new feedback
85
- with open(filename, 'a', newline='', encoding='utf-8') as csvfile:
86
- fieldnames = ['question', 'response', 'rating', 'comment']
87
- writer = csv.DictWriter(csvfile, fieldnames=fieldnames)
88
- if not file_exists:
89
- writer.writeheader()
90
- writer.writerow({'question': question, 'response': response, 'rating': rating, 'comment': comment})
91
-
92
- st.success("Thank you for your feedback! It has been saved.")
93
- except Exception as e:
94
- st.error(f"Error saving feedback: {e}")
95
- st.write(f"Exception: {e}")
96
-
97
- # Use session state to store user input, bot response, rating, and comment
98
- if 'user_input' not in st.session_state:
99
- st.session_state.user_input = ""
100
-
101
- if 'bot_response' not in st.session_state:
102
- st.session_state.bot_response = ""
103
-
104
- if 'rating' not in st.session_state:
105
- st.session_state.rating = 3 # Default rating
106
-
107
- if 'comment' not in st.session_state:
108
- st.session_state.comment = ""
109
-
110
  # Create columns for logos
111
  col1, col2, col3 = st.columns([2, 3, 2])
112
 
113
  with col1:
114
- st.image("Design 3_22.png", width=150, use_column_width=True)
115
 
116
  with col3:
117
- st.image("Altereo logo 2023 original - eau et territoires durables.png", width=150, use_column_width=True)
118
 
119
- # Add CSS for styling
120
  st.markdown("""
121
  <style>
122
  .centered-text {
@@ -126,35 +97,80 @@ st.markdown("""
126
  text-align: center;
127
  color: darkorange;
128
  }
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
129
  </style>
130
  """, unsafe_allow_html=True)
131
 
132
- # Center and color text
133
  st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖 </h3>', unsafe_allow_html=True)
134
  st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique "</p>', unsafe_allow_html=True)
135
 
136
  # Input and button for user interaction
137
- st.session_state.user_input = st.text_input("You:", st.session_state.user_input)
138
-
139
- if st.button("Ask 📨"):
140
- if st.session_state.user_input.strip() != "":
141
- st.session_state.bot_response = chatbot_response(st.session_state.user_input)
142
-
143
- if st.session_state.bot_response:
144
- st.markdown("### Bot:")
145
- st.text_area("", value=st.session_state.bot_response, height=600)
146
-
147
- # Feedback Section
148
- st.markdown("### Évaluation de la réponse")
149
- st.session_state.rating = st.slider("Rating (1 to 5)", 1, 5, st.session_state.rating)
150
- st.session_state.comment = st.text_area("Your comment:", st.session_state.comment)
151
-
152
- if st.button("Submit Feedback"):
153
- if st.session_state.comment.strip() != "":
154
- save_feedback(st.session_state.user_input, st.session_state.bot_response, st.session_state.rating, st.session_state.comment)
155
- else:
156
- st.warning("⚠️ Please enter a comment.")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
157
 
158
  # Motivational quote at the bottom
159
  st.markdown("---")
160
- st.markdown("La collaboration est la clé du succès. Chaque question trouve sa réponse, chaque défi devient une opportunité.")
 
67
  chain_type_kwargs={"prompt": prompt},
68
  )
69
 
70
+ mport streamlit as st
71
+ from datetime import datetime
72
+
73
+ # Streamlit interface with improved aesthetics
74
  st.set_page_config(page_title="Alter-IA Chat", page_icon="🤖")
75
 
76
  # Define function to handle user input and display chatbot response
 
78
  response = qa.run(user_input)
79
  return response
80
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
81
  # Create columns for logos
82
  col1, col2, col3 = st.columns([2, 3, 2])
83
 
84
  with col1:
85
+ st.image("Design 3_22.png", width=150, use_column_width=True) # Adjust image path and size as needed
86
 
87
  with col3:
88
+ st.image("Altereo logo 2023 original - eau et territoires durables.png", width=150, use_column_width=True) # Adjust image path and size as needed
89
 
90
+ # CSS for styling
91
  st.markdown("""
92
  <style>
93
  .centered-text {
 
97
  text-align: center;
98
  color: darkorange;
99
  }
100
+ .star-rating {
101
+ display: flex;
102
+ flex-direction: row-reverse;
103
+ justify-content: center;
104
+ cursor: pointer;
105
+ }
106
+ .star-rating input[type="radio"] {
107
+ display: none;
108
+ }
109
+ .star-rating label {
110
+ font-size: 2em;
111
+ color: #ddd;
112
+ padding: 0 5px;
113
+ transition: color 0.3s;
114
+ }
115
+ .star-rating input[type="radio"]:checked ~ label {
116
+ color: gold;
117
+ }
118
+ .star-rating input[type="radio"]:hover ~ label {
119
+ color: gold;
120
+ }
121
  </style>
122
  """, unsafe_allow_html=True)
123
 
 
124
  st.markdown('<h3 class="centered-text">🤖 AlteriaChat 🤖 </h3>', unsafe_allow_html=True)
125
  st.markdown('<p class="centered-orange-text">"Votre Réponse à Chaque Défi Méthodologique "</p>', unsafe_allow_html=True)
126
 
127
  # Input and button for user interaction
128
+ user_input = st.text_input("You:", "")
129
+ submit_button = st.button("Ask 📨")
130
+
131
+ if submit_button:
132
+ if user_input.strip() != "":
133
+ bot_response = chatbot_response(user_input)
134
+ st.markdown("### Bot:")
135
+ st.text_area("", value=bot_response, height=300)
136
+
137
+ # Add rating and comment section
138
+ st.markdown("---")
139
+ st.markdown("#### Rate the Response:")
140
+
141
+ # Custom star rating HTML
142
+ rating_html = """
143
+ <div class="star-rating">
144
+ <input type="radio" id="5-stars" name="rating" value="5"><label for="5-stars">★</label>
145
+ <input type="radio" id="4-stars" name="rating" value="4"><label for="4-stars">★</label>
146
+ <input type="radio" id="3-stars" name="rating" value="3" checked><label for="3-stars">★</label>
147
+ <input type="radio" id="2-stars" name="rating" value="2"><label for="2-stars">★</label>
148
+ <input type="radio" id="1-star" name="rating" value="1"><label for="1-star">★</label>
149
+ </div>
150
+ """
151
+ st.markdown(rating_html, unsafe_allow_html=True)
152
+
153
+ # Get the selected rating via JavaScript
154
+ rating = st.text_input("Selected Rating:", value="3", key="rating_input", label_visibility="hidden")
155
+
156
+ comment = st.text_area("Your Comment:")
157
+
158
+ # Submit feedback
159
+ feedback_button = st.button("Submit Feedback")
160
+
161
+ if feedback_button:
162
+ if comment.strip() == "":
163
+ st.warning("⚠ Please provide a comment.")
164
+ else:
165
+ st.success("Thank you for your feedback!")
166
+
167
+ # Store feedback (you can replace this part with code to save to a database or file)
168
+ with open("feedback.txt", "a") as f:
169
+ f.write(f"{datetime.now()} | Rating: {rating} | Comment: {comment}\n")
170
+
171
+ else:
172
+ st.warning("⚠ Please enter a message.")
173
 
174
  # Motivational quote at the bottom
175
  st.markdown("---")
176
+ st.markdown("La collaboration est la clé du succès. Chaque question trouve sa réponse, chaque défi devient une opportunité.")