File size: 6,575 Bytes
1be431a
 
 
45d10c4
 
 
 
 
1be431a
 
 
 
45d10c4
 
 
c38b78d
45d10c4
 
 
 
1be431a
fe15d80
1be431a
 
6d6d84c
 
1be431a
fd45959
1be431a
 
 
 
 
 
 
 
c38b78d
ee92837
6d6d84c
1be431a
 
 
 
 
 
 
 
 
8dcf476
45d10c4
 
d53b62d
fe15d80
1be431a
fe15d80
 
 
 
 
 
1be431a
 
 
 
3f7f887
1be431a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2da9742
1be431a
 
 
3f7f887
1be431a
 
4ffd446
 
 
fe15d80
 
 
4ffd446
fe15d80
16a43bc
 
1be431a
 
fe15d80
 
 
 
1be431a
fe15d80
 
 
6d6d84c
 
d176253
6d6d84c
 
8dcf476
d53b62d
 
 
45d10c4
d53b62d
6d6d84c
 
 
 
 
 
1be431a
 
 
 
 
fe15d80
fd45959
fe15d80
 
 
 
 
 
1be431a
 
 
 
 
d53b62d
 
1be431a
 
 
 
 
 
 
 
 
 
 
16a43bc
1be431a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
42f39c4
1be431a
 
 
 
 
 
 
 
 
d176253
 
fe15d80
d176253
16a43bc
1be431a
 
6d6d84c
 
1be431a
fd45959
1be431a
 
 
 
 
 
 
 
 
 
 
 
8dcf476
fe15d80
1be431a
 
 
 
 
 
6d6d84c
1be431a
 
 
 
 
 
 
d53b62d
 
 
 
 
 
 
1be431a
e611170
1be431a
6d6d84c
1be431a
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d176253
 
 
 
 
 
 
1be431a
 
fe15d80
45d10c4
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
import gradio as gr
import numpy as np
from datetime import date
from predictors import predict_bc_scores, predict_mc_scores
from analysis import depth_analysis
from predictors import predict_quillbot
from plagiarism import plagiarism_check, build_date
from utils import extract_text_from_pdf, len_validator

np.set_printoptions(suppress=True)


def ai_generated_test(option, input):
    if option == "Human vs AI":
        return predict_bc_scores(input), None
    else:
        return (
            predict_bc_scores(input),
            predict_mc_scores(input),
        )


# COMBINED
def main(
    ai_option,
    plag_option,
    input,
    # models,
    year_from,
    month_from,
    day_from,
    year_to,
    month_to,
    day_to,
    domains_to_skip,
):

    formatted_tokens = plagiarism_check(
        plag_option,
        input,
        year_from,
        month_from,
        day_from,
        year_to,
        month_to,
        day_to,
        domains_to_skip,
    )
    depth_analysis_plot = depth_analysis(input)
    bc_score = predict_bc_scores(input)
    mc_score = predict_mc_scores(input)
    quilscore = predict_quillbot(input)

    return (
        bc_score,
        mc_score,
        formatted_tokens,
        depth_analysis_plot,
        quilscore,
    )


# START OF GRADIO

title = "Copyright Checker"
months = {
    "January": "01",
    "February": "02",
    "March": "03",
    "April": "04",
    "May": "05",
    "June": "06",
    "July": "07",
    "August": "08",
    "September": "09",
    "October": "10",
    "November": "11",
    "December": "12",
}


with gr.Blocks() as demo:
    today = date.today()
    # dd/mm/YY
    d1 = today.strftime("%d/%B/%Y")
    d1 = d1.split("/")

    model_list = ["OpenAI GPT", "Mistral", "CLAUDE", "Gemini", "LLAMA2"]
    domain_list = ["com", "org", "net", "int", "edu", "gov", "mil"]
    gr.Markdown(
        """
    # Copyright Checker 
    """
    )
    with gr.Row():
        input_text = gr.Textbox(label="Input text", lines=6, placeholder="")
        file_input = gr.File(label="Upload PDF")
        file_input.change(
            fn=extract_text_from_pdf, inputs=file_input, outputs=input_text
        )

    char_count = gr.Textbox(label="Minumum Character Limit Check")
    input_text.change(fn=len_validator, inputs=input_text, outputs=char_count)

    with gr.Row():
        with gr.Column():
            ai_option = gr.Radio(
                ["Human vs AI", "Human vs AI Source Models"],
                label="Choose an option please.",
            )
        with gr.Column():
            plag_option = gr.Radio(
                ["Standard", "Advanced"], label="Choose an option please."
            )

    with gr.Row():
        with gr.Column():
            only_ai_btn = gr.Button("AI Check")

        with gr.Column():
            only_plagiarism_btn = gr.Button("Source Check")

    with gr.Row():
        quillbot_check = gr.Button("Humanized Text Check")

    with gr.Row():
        depth_analysis_btn = gr.Button("Detailed Writing Analysis")

    with gr.Row():
        full_check_btn = gr.Button("Full Check")

    gr.Markdown(
        """
        ## Output
        """
    )

    # models = gr.Dropdown(
    # model_list,
    # value=model_list,
    # multiselect=True,
    # label="Models to test against",
    # )

    with gr.Row():
        with gr.Column():
            bcLabel = gr.Label(label="Source")
        with gr.Column():
            mcLabel = gr.Label(label="Creator")
    with gr.Row():
        QLabel = gr.Label(label="Humanized")
    with gr.Group():
        with gr.Row():
            month_from = gr.Dropdown(
                choices=months,
                label="From Month",
                value="January",
                interactive=True,
            )
            day_from = gr.Textbox(label="From Day", value="01")
            year_from = gr.Textbox(label="From Year", value="2000")
            # from_date_button = gr.Button("Submit")

        with gr.Row():
            month_to = gr.Dropdown(
                choices=months,
                label="To Month",
                value=d1[1],
                interactive=True,
            )
            day_to = gr.Textbox(label="To Day", value=d1[0])
            year_to = gr.Textbox(label="To Year", value=d1[2])
            # to_date_button = gr.Button("Submit")
        with gr.Row():
            domains_to_skip = gr.Dropdown(
                domain_list,
                multiselect=True,
                label="Domain To Skip",
            )

    with gr.Row():
        with gr.Column():
            sentenceBreakdown = gr.HighlightedText(
                label="Source Detection Sentence Breakdown",
                combine_adjacent=True,
                color_map={
                    "[1]": "red",
                    "[2]": "orange",
                    "[3]": "yellow",
                    "[4]": "green",
                },
            )

    with gr.Row():
        with gr.Column():
            writing_analysis_plot = gr.Plot(label="Writing Analysis Plot")

    full_check_btn.click(
        fn=main,
        inputs=[
            ai_option,
            plag_option,
            input_text,
            # models,
            year_from,
            month_from,
            day_from,
            year_to,
            month_to,
            day_to,
            domains_to_skip,
        ],
        outputs=[
            bcLabel,
            mcLabel,
            sentenceBreakdown,
            writing_analysis_plot,
            QLabel,
        ],
        api_name="main",
    )

    only_ai_btn.click(
        fn=ai_generated_test,
        inputs=[ai_option, input_text],
        outputs=[
            bcLabel,
            mcLabel,
        ],
        api_name="ai_check",
    )

    quillbot_check.click(
        fn=predict_quillbot,
        inputs=[input_text],
        outputs=[QLabel],
        api_name="quillbot_check",
    )

    only_plagiarism_btn.click(
        fn=plagiarism_check,
        inputs=[
            plag_option,
            input_text,
            year_from,
            month_from,
            day_from,
            year_to,
            month_to,
            day_to,
            domains_to_skip,
        ],
        outputs=[
            sentenceBreakdown,
        ],
        api_name="plagiarism_check",
    )

    depth_analysis_btn.click(
        fn=depth_analysis,
        inputs=[input_text],
        outputs=[writing_analysis_plot],
        api_name="depth_analysis",
    )

    date_from = ""
    date_to = ""

demo.launch(share=True, auth=("polygraf-admin", "test@aisd"))