vineyard03/Code-Repair-With-LLMs
0
1# event handlers2 3import gradio as gr4 5def custom_theme():6 # Gradio UI styling7 return gr.themes.Ocean(8 primary_hue=gr.themes.Color(c100="#fef9c3", c200="#fef08a", c300="#fde047", c400="#facc15", c50="#fefce8", c500="#eab308", c600="#ca8a04", c700="#a16207", c800="#854d0e", c900="#713f12", c950="#BA9B37"),9 secondary_hue="zinc",10 radius_size="lg",11 ).set(12 background_fill_primary='*neutral_900',13 background_fill_secondary='*neutral_700',14 body_background_fill='*secondary_900',15 body_text_color='*neutral_100',16 body_text_color_subdued='*neutral_400',17 border_color_accent='*neutral_900',18 button_secondary_background_fill='linear-gradient(120deg, *secondary_900 0%, *primary_400 50%, *primary_700 100%)',19 button_secondary_background_fill_hover='linear-gradient(120deg, *secondary_900 0%, *primary_400 50%, *primary_700 100%)',20 checkbox_label_background_fill_selected="linear-gradient(120deg, *secondary_900 0%, *primary_400 50%, *primary_700 100%)",21 code_background_fill='*neutral_950',22 color_accent_soft='*primary_950',23 input_background_fill='*neutral_700',24 table_odd_background_fill='*neutral_700'25 )26 27def custom_css():28 return """29 .fixed-height 30 {31 height: 300px !important;32 overflow-y: auto !important;33 }34 35 .stage-box 36 {37 text-align: center !important;38 font-weight: bold !important;39 }40 41 .title 42 { 43 text-align: center; 44 font-size: 2rem; 45 font-weight: bold; 46 }47 48 .subtitle 49 { 50 text-align: center;51 font-size: 1.2rem;52 }53 54 .big-checkboxes label 55 { 56 font-size: 1.5rem;57 display: block; 58 text-align: center;59 }60 61 .big-button 62 { 63 font-size: 1.5rem; 64 padding: 10px 20px; 65 display: block; 66 margin: 0 auto; 67 }68 69 """70 71def display_file_content(file):72 if file is None:73 return "No file uploaded yet."74 try:75 if isinstance(file, str):76 with open(file, 'r') as f:77 return f.read()78 elif hasattr(file, 'name'):79 return file.name80 elif hasattr(file, 'read'):81 return file.read().decode('utf-8')82 else:83 return str(file)84 except Exception as e:85 return f"An error occurred while reading the file: {str(e)}"86 87def process_file(file, language):88 if file is None:89 return "Skipped", "Skipped", "Skipped", "Skipped", "Please upload a file."90 91 try:92 content = display_file_content(file)93 stage1_result = "Complete"94 stage2_result = "Complete"95 stage3_result = "Complete"96 stage4_result = "Complete"97 processed_content = process_content(content, language)98 return stage1_result, stage2_result, stage3_result, stage4_result, processed_content99 except Exception as e:100 return "Error", "Error", "Error", "Error", f"An error occurred: {str(e)}"101 102def process_content(content, language):103 # This is where you would implement your actual processing logic104 # For now, we'll just return the file content with a message105 return f"Processing {language} code:\n\n{content}\n\nProcessing complete."106 