import os from collections import defaultdict from database import save_response, read_responses import gradio as gr import pandas as pd import random css = """ .rtl { text-align: right; } .usr-inst{ text-align:center; border: solid 1px; border-radius: 5px; padding: 10px; } .svelte-1kzox3m{ justify-content: end; } .svelte-sfqy0y{ border:none; } .svelte-90oupt{ padding-top: 0px; } #component-4{ border: 1px solid; padding: 5px; border-radius: 5px; } """ file_path = 'instructions/merged.json' df = pd.read_json(file_path, orient='records', lines=False) # that keeps track of how many times each question has been used question_count = {index: 0 for index in df.index} model_rankings = defaultdict(lambda: {'1st': 0, '2nd': 0, '3rd': 0}) curr_order = ['CIDAR', 'CHAT', 'ALPAGASUS'] def get_rank_suffix(rank): if 11 <= rank <= 13: return 'th' else: suffixes = {1: 'st', 2: 'nd', 3: 'rd'} return suffixes.get(rank % 10, 'th') def process_rankings(user_rankings): print("Processing Rankings:", user_rankings) # Debugging print save_response(user_rankings) print(read_responses()) return def get_questions_and_answers(): available_questions = [index for index, count in question_count.items() if count < 3] index = random.sample(available_questions, min(1, len(available_questions)))[0] question_count[index] += 1 question = df.loc[index, 'instruction'] answers_with_models = [ (df.loc[index, 'cidar_output'], 'CIDAR'), (df.loc[index, 'chat_output'], 'CHAT'), (df.loc[index, 'alpagasus_output'], 'ALPAGASUS') ] random.shuffle(answers_with_models) # Shuffle answers with their IDs curr_order = [model for _, model in answers_with_models] return (question, answers_with_models) def reload_components(): question, answers = get_questions_and_answers() user_instructions_txt = " في الصفحة التالية ستجد طلب له ثلاث إجابات مختلفة. من فضلك اختر مدي توافق كل إجابة مع الثقافة العربية." radios = [] user_instructions = gr.Markdown(rtl=True, value= f'