raj-tomar001 commited on
Commit
4b7ea1a
·
verified ·
1 Parent(s): 4030206
Files changed (1) hide show
  1. demo.py +0 -111
demo.py DELETED
@@ -1,111 +0,0 @@
1
- import gradio as gr
2
- from transformers import DebertaTokenizer, DebertaForSequenceClassification
3
- from transformers import pipeline
4
-
5
- save_path_abstract = '/home/raj.tomar/Downloads/MGT/experiments/fine-tuned-deberta/'
6
- model_abstract = DebertaForSequenceClassification.from_pretrained(save_path_abstract)
7
- tokenizer_abstract = DebertaTokenizer.from_pretrained(save_path_abstract)
8
-
9
- classifier_abstract = pipeline('text-classification', model=model_abstract, tokenizer=tokenizer_abstract)
10
-
11
- save_path_essay = '/home/raj.tomar/Downloads/MGT/experiments/fine-tuned-deberta/'
12
- model_essay = DebertaForSequenceClassification.from_pretrained(save_path_essay)
13
- tokenizer_essay = DebertaTokenizer.from_pretrained(save_path_essay)
14
-
15
- classifier_essay = pipeline('text-classification', model=model_essay, tokenizer=tokenizer_essay)
16
-
17
- def update(name, uploaded_file, radio_input):
18
- if uploaded_file is not None:
19
- return f"{name}, you uploaded a file named {uploaded_file.name}."
20
- else:
21
- if radio_input == 'Scientific Abstract':
22
- data = classifier_abstract(name)[0]['label']
23
- if data == 'LABEL_0':
24
- return "human_text"
25
- if data == 'LABEL_1':
26
- return "machine_text"
27
- if data == 'LABEL_2':
28
- return "human-written | machine-polished"
29
- if data == 'LABEL_3':
30
- return "machine-generated | machine-humanized"
31
- else:
32
- if radio_input == 'Student Essay':
33
- data = classifier_essay(name)[0]['label']
34
- if data == 'LABEL_0':
35
- return "human_text"
36
- if data == 'LABEL_1':
37
- return "machine_text"
38
- if data == 'LABEL_2':
39
- return "human-written | machine-polished"
40
- if data == 'LABEL_3':
41
- return "machine-generated | machine-humanized"
42
- # return "Hold on!"
43
-
44
- with gr.Blocks() as demo:
45
- gr.Markdown(
46
- """
47
- <style>
48
- .gr-button-secondary {
49
- width: 100px;
50
- height: 30px;
51
- padding: 5px;
52
- }
53
- .gr-row {
54
- display: flex;
55
- align-items: center;
56
- gap: 10px;
57
- }
58
- .gr-block {
59
- padding: 20px;
60
- }
61
- .gr-markdown p {
62
- font-size: 16px;
63
- }
64
- </style>
65
- <span style='font-family: Arial, sans-serif; font-size: 20px;'>Was this text written by <strong>human</strong> or <strong>AI</strong>?</span>
66
- <p style='font-family: Arial, sans-serif;'>Try detecting one of our sample texts:</p>
67
- """
68
- )
69
-
70
- with gr.Row():
71
- for sample in ["Machine-Generated", "Human-Written", "Machine-Humanized", "Machine - Polished"]:
72
- gr.Button(sample, variant="outline")
73
-
74
- with gr.Row():
75
- radio_button = gr.Radio(['Scientific Abstract', 'Student Essay'], label = 'Text Type', info = 'We have specialized models that work on domain-specific text.')
76
-
77
- with gr.Row():
78
- input_text = gr.Textbox(placeholder="Paste your text here...", label="", lines=10)
79
- file_input = gr.File(label="Upload File")
80
-
81
- #file_input = gr.File(label="", visible=False) # Hide the actual file input
82
-
83
- with gr.Row():
84
- check_button = gr.Button("Check Origin", variant="primary")
85
- clear_button = gr.ClearButton([input_text, file_input, radio_button], variant='stop')
86
- #upload_button = gr.Button("Upload File", variant="secondary")
87
-
88
- out = gr.Textbox(label="OUTPUT", placeholder="", lines=2)
89
- clear_button.add(out)
90
-
91
- check_button.click(fn=update, inputs=[input_text, file_input, radio_button], outputs=out)
92
- #upload_button.click(lambda: None, inputs=[], outputs=[]).then(fn=update, inputs=[input_text, file_input], outputs=out)
93
-
94
- # Adding JavaScript to simulate file input click
95
- gr.Markdown(
96
- """
97
- <script>
98
- document.addEventListener("DOMContentLoaded", function() {
99
- const uploadButton = Array.from(document.getElementsByTagName('button')).find(el => el.innerText === "Upload File");
100
- if (uploadButton) {
101
- uploadButton.onclick = function() {
102
- document.querySelector('input[type="file"]').click();
103
- };
104
- }
105
- });
106
- </script>
107
- """
108
- )
109
-
110
- demo.launch(share=True)
111
-