Spaces:
Runtime error
Runtime error
Update demo.py
Browse files
demo.py
CHANGED
|
@@ -1,22 +1,21 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
|
|
|
|
|
|
| 3 |
|
| 4 |
-
|
| 5 |
-
# TOKENIZER =
|
| 6 |
-
# MINIMUM_TOKENS = 64
|
| 7 |
-
|
| 8 |
-
# def count_tokens(text):
|
| 9 |
-
# return len(TOKENIZER(text).input_ids)
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
# Mock function for testing layout
|
| 13 |
-
def run_test_power(model_name, real_text, generated_text, N=10):
|
| 14 |
-
return f"Prediction: Human (Mocked for {model_name})"
|
| 15 |
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
|
|
|
| 18 |
# Change mode name
|
| 19 |
-
#def change_mode(mode):
|
| 20 |
# if mode == "Faster Model":
|
| 21 |
# .change_mode("t5-small")
|
| 22 |
# elif mode == "Medium Model":
|
|
@@ -28,15 +27,14 @@ def run_test_power(model_name, real_text, generated_text, N=10):
|
|
| 28 |
# return mode
|
| 29 |
|
| 30 |
|
| 31 |
-
|
| 32 |
css = """
|
| 33 |
#header { text-align: center; font-size: 3em; margin-bottom: 20px; }
|
| 34 |
#output-text { font-weight: bold; font-size: 1.2em; }
|
| 35 |
-
.links {
|
| 36 |
-
display: flex;
|
| 37 |
-
justify-content: flex-end;
|
| 38 |
-
gap: 10px;
|
| 39 |
-
margin-right: 10px;
|
| 40 |
align-items: center;
|
| 41 |
}
|
| 42 |
.separator {
|
|
@@ -91,7 +89,8 @@ with gr.Blocks(css=css) as app:
|
|
| 91 |
with gr.Row():
|
| 92 |
gr.HTML('<div id="header">R-detect On HuggingFace</div>')
|
| 93 |
with gr.Row():
|
| 94 |
-
gr.HTML(
|
|
|
|
| 95 |
<div class="links">
|
| 96 |
<a href="https://openreview.net/forum?id=z9j7wctoGV" target="_blank">Paper</a>
|
| 97 |
<span class="separator">|</span>
|
|
@@ -99,14 +98,14 @@ with gr.Blocks(css=css) as app:
|
|
| 99 |
<span class="separator">|</span>
|
| 100 |
<a href="mailto:[email protected]" target="_blank">Contact</a>
|
| 101 |
</div>
|
| 102 |
-
"""
|
|
|
|
| 103 |
with gr.Row():
|
| 104 |
input_text = gr.Textbox(
|
| 105 |
label="Input Text",
|
| 106 |
placeholder="Enter Text Here",
|
| 107 |
lines=8,
|
| 108 |
elem_classes=["input-text"], # Applying the CSS class
|
| 109 |
-
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)"
|
| 110 |
)
|
| 111 |
output = gr.Textbox(
|
| 112 |
label="Inference Result",
|
|
@@ -116,30 +115,36 @@ with gr.Blocks(css=css) as app:
|
|
| 116 |
elem_classes=["output-text"],
|
| 117 |
)
|
| 118 |
with gr.Row():
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 128 |
)
|
| 129 |
-
submit_button = gr.Button("Run Detection", variant="primary", elem_classes=["button"])
|
| 130 |
clear_button = gr.Button("Clear", variant="secondary", elem_classes=["button"])
|
| 131 |
-
|
| 132 |
-
submit_button.click(
|
| 133 |
clear_button.click(lambda: ("", ""), inputs=[], outputs=[input_text, output])
|
| 134 |
|
| 135 |
with gr.Accordion("Disclaimer", open=False, elem_classes=["accordion"]):
|
| 136 |
-
gr.Markdown(
|
|
|
|
| 137 |
- **Disclaimer**: This tool is for demonstration purposes only. It is not a foolproof AI detector.
|
| 138 |
- **Accuracy**: Results may vary based on input length and quality.
|
| 139 |
-
"""
|
|
|
|
| 140 |
|
| 141 |
with gr.Accordion("Citations", open=False, elem_classes=["accordion"]):
|
| 142 |
-
gr.Markdown(
|
|
|
|
| 143 |
```
|
| 144 |
@inproceedings{zhangs2024MMDMP,
|
| 145 |
title={Detecting Machine-Generated Texts by Multi-Population Aware Optimization for Maximum Mean Discrepancy},
|
|
@@ -148,6 +153,7 @@ with gr.Blocks(css=css) as app:
|
|
| 148 |
year={2024}
|
| 149 |
}
|
| 150 |
```
|
| 151 |
-
"""
|
|
|
|
| 152 |
|
| 153 |
-
app.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from relative_tester import relative_tester
|
| 3 |
+
# from two_sample_tester import two_sample_tester
|
| 4 |
+
from utils import init_random_seeds
|
| 5 |
|
| 6 |
+
init_random_seeds()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
|
| 8 |
|
| 9 |
+
def run_test(input_text):
|
| 10 |
+
if not input_text:
|
| 11 |
+
return "Now that you've built a demo, you'll probably want to share it with others. Gradio demos can be shared in two ways: using a temporary share link or permanent hosting on Spaces."
|
| 12 |
+
# return two_sample_tester.test(input_text.strip())
|
| 13 |
+
return relative_tester.test(input_text.strip())
|
| 14 |
+
return f"Prediction: Human (Mocked for {input_text})"
|
| 15 |
|
| 16 |
+
# TODO: Add model selection in the future
|
| 17 |
# Change mode name
|
| 18 |
+
# def change_mode(mode):
|
| 19 |
# if mode == "Faster Model":
|
| 20 |
# .change_mode("t5-small")
|
| 21 |
# elif mode == "Medium Model":
|
|
|
|
| 27 |
# return mode
|
| 28 |
|
| 29 |
|
|
|
|
| 30 |
css = """
|
| 31 |
#header { text-align: center; font-size: 3em; margin-bottom: 20px; }
|
| 32 |
#output-text { font-weight: bold; font-size: 1.2em; }
|
| 33 |
+
.links {
|
| 34 |
+
display: flex;
|
| 35 |
+
justify-content: flex-end;
|
| 36 |
+
gap: 10px;
|
| 37 |
+
margin-right: 10px;
|
| 38 |
align-items: center;
|
| 39 |
}
|
| 40 |
.separator {
|
|
|
|
| 89 |
with gr.Row():
|
| 90 |
gr.HTML('<div id="header">R-detect On HuggingFace</div>')
|
| 91 |
with gr.Row():
|
| 92 |
+
gr.HTML(
|
| 93 |
+
"""
|
| 94 |
<div class="links">
|
| 95 |
<a href="https://openreview.net/forum?id=z9j7wctoGV" target="_blank">Paper</a>
|
| 96 |
<span class="separator">|</span>
|
|
|
|
| 98 |
<span class="separator">|</span>
|
| 99 |
<a href="mailto:[email protected]" target="_blank">Contact</a>
|
| 100 |
</div>
|
| 101 |
+
"""
|
| 102 |
+
)
|
| 103 |
with gr.Row():
|
| 104 |
input_text = gr.Textbox(
|
| 105 |
label="Input Text",
|
| 106 |
placeholder="Enter Text Here",
|
| 107 |
lines=8,
|
| 108 |
elem_classes=["input-text"], # Applying the CSS class
|
|
|
|
| 109 |
)
|
| 110 |
output = gr.Textbox(
|
| 111 |
label="Inference Result",
|
|
|
|
| 115 |
elem_classes=["output-text"],
|
| 116 |
)
|
| 117 |
with gr.Row():
|
| 118 |
+
# TODO: Add model selection in the future
|
| 119 |
+
# model_name = gr.Dropdown(
|
| 120 |
+
# [
|
| 121 |
+
# "Faster Model",
|
| 122 |
+
# "Medium Model",
|
| 123 |
+
# "Powerful Model",
|
| 124 |
+
# ],
|
| 125 |
+
# label="Select Model",
|
| 126 |
+
# value="Medium Model",
|
| 127 |
+
# elem_classes=["select"],
|
| 128 |
+
# )
|
| 129 |
+
submit_button = gr.Button(
|
| 130 |
+
"Run Detection", variant="primary", elem_classes=["button"]
|
| 131 |
)
|
|
|
|
| 132 |
clear_button = gr.Button("Clear", variant="secondary", elem_classes=["button"])
|
| 133 |
+
|
| 134 |
+
submit_button.click(run_test, inputs=[input_text], outputs=output)
|
| 135 |
clear_button.click(lambda: ("", ""), inputs=[], outputs=[input_text, output])
|
| 136 |
|
| 137 |
with gr.Accordion("Disclaimer", open=False, elem_classes=["accordion"]):
|
| 138 |
+
gr.Markdown(
|
| 139 |
+
"""
|
| 140 |
- **Disclaimer**: This tool is for demonstration purposes only. It is not a foolproof AI detector.
|
| 141 |
- **Accuracy**: Results may vary based on input length and quality.
|
| 142 |
+
"""
|
| 143 |
+
)
|
| 144 |
|
| 145 |
with gr.Accordion("Citations", open=False, elem_classes=["accordion"]):
|
| 146 |
+
gr.Markdown(
|
| 147 |
+
"""
|
| 148 |
```
|
| 149 |
@inproceedings{zhangs2024MMDMP,
|
| 150 |
title={Detecting Machine-Generated Texts by Multi-Population Aware Optimization for Maximum Mean Discrepancy},
|
|
|
|
| 153 |
year={2024}
|
| 154 |
}
|
| 155 |
```
|
| 156 |
+
"""
|
| 157 |
+
)
|
| 158 |
|
| 159 |
+
app.launch()
|