File size: 5,112 Bytes
d97734e
f6d8146
 
 
 
 
 
 
 
 
d97734e
a236161
d97734e
afd1fe2
d97734e
936b250
 
f6d8146
 
 
 
 
 
 
 
 
 
 
936b250
f6d8146
 
 
 
 
 
 
 
 
 
63c0903
fa64871
899f27e
 
 
011ac7a
02185e1
f6d8146
 
 
9b7ecd8
f6d8146
 
 
 
939a105
f6d8146
 
 
 
5f71889
b2f5f8e
 
8946536
f6d8146
 
02185e1
 
 
14ba27e
f6d8146
76c593e
7c8d189
08d000a
 
f6d8146
 
 
 
 
 
 
 
 
 
 
e40a325
d97734e
 
 
939a105
d97734e
936b250
fa64871
53c66e2
 
 
 
 
 
 
 
 
d97734e
 
 
936b250
d97734e
b2f5f8e
3145bcf
d97734e
afd1fe2
 
53c66e2
afd1fe2
b9faac8
f6d8146
afd1fe2
d97734e
 
 
afd1fe2
 
 
d97734e
 
d3ee676
1569480
d97734e
8946536
bd0295f
d3ee676
afd1fe2
d97734e
936b250
f6d8146
53c66e2
 
 
 
 
f6d8146
53c66e2
 
 
 
 
 
 
 
 
 
d97734e
f6d8146
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
import gradio as gr
import spaces


# TOKENIZER = 
# MINIMUM_TOKENS = 64

# def count_tokens(text):
#     return len(TOKENIZER(text).input_ids)


# Mock function for testing layout
def run_test_power(model_name, real_text, generated_text, N=10):
    return f"Prediction: Human (Mocked for {model_name})"



# Change mode name
#def change_mode(mode):
#    if mode == "Faster Model":
#        .change_mode("t5-small")
#    elif mode == "Medium Model":
#        .change_mode("roberta-base-openai-detector")
#    elif mode == "Powerful Model":
#        .change_mode("falcon-rw-1b")
#    else:
#        gr.Error(f"Invaild mode selected.")
#    return mode



css = """
#header { text-align: center; font-size: 3em; margin-bottom: 20px; }
#output-text { font-weight: bold; font-size: 1.2em; }
.links { 
    display: flex; 
    justify-content: flex-end; 
    gap: 10px; 
    margin-right: 10px; 
    align-items: center;
}
.separator {
    margin: 0 5px;
    color: black;
}

/* Adjusting layout for Input Text and Inference Result */
.input-row {
    display: flex;
    width: 100%;
}

.input-text {
    flex: 3;  /* 4 parts of the row */
    margin-right: 1px;
}

.output-text {
    flex: 1;  /* 1 part of the row */
}

/* Set button widths to match the Select Model width */
.button {
    width: 250px;  /* Same as the select box width */
    height: 100px;  /* Button height */
}

/* Set height for the Select Model dropdown */
.select {
    height: 100px;  /* Set height to 100px */
}

/* Accordion Styling */
.accordion {
    width: 100%;  /* Set the width of the accordion to match the parent */
    max-height: 200px;  /* Set a max-height for accordion */
    overflow-y: auto;  /* Allow scrolling if the content exceeds max height */
    margin-bottom: 10px;  /* Add space below accordion */
    box-sizing: border-box;  /* Ensure padding is included in width/height */
}

/* Accordion content max-height */
.accordion-content {
    max-height: 200px;  /* Limit the height of the content */
    overflow-y: auto;  /* Add a scrollbar if content overflows */
}
"""

# Gradio App
with gr.Blocks(css=css) as app:
    with gr.Row():
        gr.HTML('<div id="header">R-detect On HuggingFace</div>')
    with gr.Row():
        gr.HTML("""
        <div class="links">
            <a href="https://openreview.net/forum?id=z9j7wctoGV" target="_blank">Paper</a>
            <span class="separator">|</span>
            <a href="https://github.com/xLearn-AU/R-Detect" target="_blank">Code</a>
            <span class="separator">|</span>
            <a href="mailto:[email protected]" target="_blank">Contact</a>
        </div>
        """)
    with gr.Row():
        input_text = gr.Textbox(
            label="Input Text",
            placeholder="Enter Text Here",
            lines=8,
            elem_classes=["input-text"],  # Applying the CSS class
            value="Basketball is a dynamic and widely popular sport that originated in 1891 when Dr. James Naismith, a physical education instructor, sought to keep his students active during the winter. He devised a game involving a ball and two peach baskets, laying the foundation for what would evolve into modern basketball. The objective is to score points by shooting the ball through the opposing team's hoop, a task complicated by the rules and the opposing team's defense. (This is a example from Chatgpt)"
        )
        output = gr.Textbox(
            label="Inference Result",
            placeholder="Made by Human or AI",
            elem_id="output-text",
            lines=8,
            elem_classes=["output-text"],
        )
    with gr.Row():
        model_name = gr.Dropdown(
            [
                "Faster Model",
                "Medium Model",
                "Powerful Model",
            ],
            label="Select Model",
            value="Medium Model",
            elem_classes=["select"],
        )
        submit_button = gr.Button("Run Detection", variant="primary", elem_classes=["button"])
        clear_button = gr.Button("Clear", variant="secondary", elem_classes=["button"])
    
    submit_button.click(run_test_power, inputs=[model_name, input_text, input_text], outputs=output)
    clear_button.click(lambda: ("", ""), inputs=[], outputs=[input_text, output])

    with gr.Accordion("Disclaimer", open=False, elem_classes=["accordion"]):
        gr.Markdown("""
        - **Disclaimer**: This tool is for demonstration purposes only. It is not a foolproof AI detector.
        - **Accuracy**: Results may vary based on input length and quality.
        """)

    with gr.Accordion("Citations", open=False, elem_classes=["accordion"]):
        gr.Markdown("""
        ```
        @inproceedings{zhangs2024MMDMP,
            title={Detecting Machine-Generated Texts by Multi-Population Aware Optimization for Maximum Mean Discrepancy},
            author={Zhang, Shuhai and Song, Yiliao and Yang, Jiahao and Li, Yuanqing and Han, Bo and Tan, Mingkui},
            booktitle = {International Conference on Learning Representations (ICLR)},
            year={2024}
        }
        ```
        """)

app.launch()