File size: 3,399 Bytes
9adf324
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# event handlers

import gradio as gr

def custom_theme():
    # Gradio UI styling
    return gr.themes.Ocean(
        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"),
        secondary_hue="zinc",
        radius_size="lg",
    ).set(
        background_fill_primary='*neutral_900',
        background_fill_secondary='*neutral_700',
        body_background_fill='*secondary_900',
        body_text_color='*neutral_100',
        body_text_color_subdued='*neutral_400',
        border_color_accent='*neutral_900',
        button_secondary_background_fill='linear-gradient(120deg, *secondary_900 0%, *primary_400 50%, *primary_700 100%)',
        button_secondary_background_fill_hover='linear-gradient(120deg, *secondary_900 0%, *primary_400 50%, *primary_700 100%)',
        checkbox_label_background_fill_selected="linear-gradient(120deg, *secondary_900 0%, *primary_400 50%, *primary_700 100%)",
        code_background_fill='*neutral_950',
        color_accent_soft='*primary_950',
        input_background_fill='*neutral_700',
        table_odd_background_fill='*neutral_700'
    )

def custom_css():
    return """

    .fixed-height 

    {

        height: 300px !important;

        overflow-y: auto !important;

    }



    .stage-box 

    {

        text-align: center !important;

        font-weight: bold !important;

    }



    .title 

    { 

        text-align: center; 

        font-size: 2rem; 

        font-weight: bold; 

    }



    .subtitle 

    { 

        text-align: center;

        font-size: 1.2rem;

    }



    .big-checkboxes label 

    { 

        font-size: 1.5rem;

        display: block; 

        text-align: center;

    }



    .big-button 

    { 

        font-size: 1.5rem; 

        padding: 10px 20px; 

        display: block; 

        margin: 0 auto; 

    }



    """

def display_file_content(file):
    if file is None:
        return "No file uploaded yet."
    try:
        if isinstance(file, str):
            with open(file, 'r') as f:
                return f.read()
        elif hasattr(file, 'name'):
            return file.name
        elif hasattr(file, 'read'):
            return file.read().decode('utf-8')
        else:
            return str(file)
    except Exception as e:
        return f"An error occurred while reading the file: {str(e)}"

def process_file(file, language):
    if file is None:
        return "Skipped", "Skipped", "Skipped", "Skipped", "Please upload a file."
    
    try:
        content = display_file_content(file)
        stage1_result = "Complete"
        stage2_result = "Complete"
        stage3_result = "Complete"
        stage4_result = "Complete"
        processed_content = process_content(content, language)
        return stage1_result, stage2_result, stage3_result, stage4_result, processed_content
    except Exception as e:
        return "Error", "Error", "Error", "Error", f"An error occurred: {str(e)}"

def process_content(content, language):
    # This is where you would implement your actual processing logic
    # For now, we'll just return the file content with a message
    return f"Processing {language} code:\n\n{content}\n\nProcessing complete."