Skip to content
Snippets Groups Projects
Commit 6ad820fe authored by Sangamithra Panneer Selvam's avatar Sangamithra Panneer Selvam
Browse files

RateMe metrics

parent c295417f
No related branches found
No related tags found
No related merge requests found
...@@ -2,10 +2,13 @@ from flask import Flask, request, jsonify, render_template ...@@ -2,10 +2,13 @@ from flask import Flask, request, jsonify, render_template
import os import os
from rag_utils import process_pdf from rag_utils import process_pdf
import json import json
from datetime import datetime
app = Flask(__name__) app = Flask(__name__)
user_question = [] user_question = []
readme_ratings = {}
ratings_list = []
local_directory = os.getenv("SHARED_FOLDER_PATH") local_directory = os.getenv("SHARED_FOLDER_PATH")
...@@ -134,6 +137,33 @@ def process_question(question): ...@@ -134,6 +137,33 @@ def process_question(question):
def get_user_question(): def get_user_question():
return user_question return user_question
@app.route('/rate_readme', methods=['POST'])
def rate_readme():
global path
try:
data = request.json
rating = data['rating']
feedback = data.get('feedback', '') # Get the feedback string, default to empty string if not provided
readme_ratings.setdefault(local_directory, []).append({'rating': rating, 'feedback': feedback})
print(readme_ratings)
timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
try:
ratings_filename = os.path.join(local_directory, "ratings.json")
rating_dict={"Rating": rating, "Feedback": feedback, "Timestamp": timestamp}
ratings_list.append(rating_dict)
with open(ratings_filename, 'w') as file:
json.dump(ratings_list, file, indent=4)
print(f"Rating: {rating}, Feedback: {feedback}, Timestamp: {timestamp}\n")
except Exception as e:
print("Error:", e)
return jsonify({'success': True})
except Exception as e:
print("Exception:", e)
return jsonify({'success': False, 'error': str(e)})
def app_run(): def app_run():
app.run(host="0.0.0.0", port=8062, debug=False) app.run(host="0.0.0.0", port=8062, debug=False)
...@@ -131,6 +131,52 @@ ...@@ -131,6 +131,52 @@
margin-top: 5px; margin-top: 5px;
color: #555; color: #555;
} }
.rating {
display: flex;
flex-direction: row;
justify-content: left;
align-items: left;
}
.rating input {
display: none;
}
.rating label {
cursor: pointer;
width: 25px;
height: 25px;
margin: 0 2px;
font-size: 25px;
line-height: 25px;
}
.rating label:before {
content: '★';
}
.rating input:checked ~ label {
color: #FFD700;
}
.rating {
display: flex;
flex-direction: row;
justify-content: left;
align-items: left;
direction: rtl; /* Change direction to left to right */
}
.rating input[type="radio"] {
float: left;
clear: none;
}
.rating label {
float: left;
clear: none;
}
.button { .button {
display: inline-block; display: inline-block;
padding: 10px 20px; padding: 10px 20px;
...@@ -155,6 +201,53 @@ ...@@ -155,6 +201,53 @@
} }
</style> </style>
<script> <script>
function rateReadme(rating) {
// Show the corresponding textarea for the clicked star
var feedbackTextarea = document.getElementById('feedback' + rating);
feedbackTextarea.style.display = 'block';
// Capture the user feedback
var feedback = prompt("Please provide your feedback for this rating:");
if (feedback !== null) {
feedbackTextarea.value = feedback;
} else {
// If the user cancels the prompt, hide the textarea
feedbackTextarea.style.display = 'none';
}
// Hide other textareas for stars with lower ratings
for (var i = 1; i <= 5; i++) {
if (i !== rating) {
var otherTextarea = document.getElementById('feedback' + i);
otherTextarea.style.display = 'none';
otherTextarea.value = ''; // Clear previous feedback
}
}
// Send the rating and feedback to the server
var data = {
"rating": rating,
"feedback": feedback
};
fetch('/rate_readme', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(data),
})
.then(response => response.json())
.then(data => {
console.log('Success:', data);
// Handle success if needed
})
.catch((error) => {
console.error('Error:', error);
// Handle error if needed
});
}
function handleUploadTypeChange() { function handleUploadTypeChange() {
const uploadType = document.getElementById('uploadType').value; const uploadType = document.getElementById('uploadType').value;
const pdfSection = document.getElementById('pdfUploadSection'); const pdfSection = document.getElementById('pdfUploadSection');
...@@ -397,6 +490,41 @@ ...@@ -397,6 +490,41 @@
</form> </form>
<div id="indexResponse"></div> <div id="indexResponse"></div>
</div> </div>
<!-- Rate Me -->
<div class="section">
<h3>Rate ME</h3>
<p>Assess the quality of the generated responses based on criteria such as relevance, coherence, fluency, and overall satisfaction.</p>
<div class="rating">
<input type="radio" id="star5" name="rating" value="5" onclick="rateReadme(5)">
<label for="star5"></label>
<input type="radio" id="star4" name="rating" value="4" onclick="rateReadme(4)">
<label for="star4"></label>
<input type="radio" id="star3" name="rating" value="3" onclick="rateReadme(3)">
<label for="star3"></label>
<input type="radio" id="star2" name="rating" value="2" onclick="rateReadme(2)">
<label for="star2"></label>
<input type="radio" id="star1" name="rating" value="1" onclick="rateReadme(1)">
<label for="star1"></label>
<textarea id="feedback5" name="feedback" style="display: none;"></textarea>
<textarea id="feedback4" name="feedback" style="display: none;"></textarea>
<textarea id="feedback3" name="feedback" style="display: none;"></textarea>
<textarea id="feedback2" name="feedback" style="display: none;"></textarea>
<textarea id="feedback1" name="feedback" style="display: none;"></textarea>
</div>
</div>
<!-- Visualization Section --> <!-- Visualization Section -->
<div class="section"> <div class="section">
...@@ -418,6 +546,7 @@ ...@@ -418,6 +546,7 @@
<div id="chatResponse"></div> <div id="chatResponse"></div>
</div> </div>
</div> </div>
</div> </div>
<!-- Loading and Progress Elements --> <!-- Loading and Progress Elements -->
...@@ -427,5 +556,6 @@ ...@@ -427,5 +556,6 @@
<div id="progress-bar"> <div id="progress-bar">
<div id="progress-bar-value"></div> <div id="progress-bar-value"></div>
</div> </div>
</body> </body>
</html> </html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment