Spaces:
Running
Running
Update demo.py
Browse files
demo.py
CHANGED
@@ -1,17 +1,34 @@
|
|
1 |
import gradio as gr
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
|
3 |
# Mock function for testing layout
|
4 |
def run_test_power(model_name, real_text, generated_text, N=10):
|
5 |
return "Prediction: Human (Mocked)"
|
6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
7 |
css = """
|
8 |
-
#header { text-align: center; font-size:
|
9 |
#output-text { font-weight: bold; font-size: 1.2em; }
|
10 |
-
.links {
|
11 |
-
display: flex;
|
12 |
-
justify-content: flex-end;
|
13 |
-
gap: 10px;
|
14 |
-
margin-right: 10px;
|
15 |
align-items: center;
|
16 |
}
|
17 |
.separator {
|
@@ -23,7 +40,7 @@ css = """
|
|
23 |
# Gradio App
|
24 |
with gr.Blocks(css=css) as app:
|
25 |
with gr.Row():
|
26 |
-
gr.HTML('<div id="header">
|
27 |
with gr.Row():
|
28 |
gr.HTML(
|
29 |
"""
|
@@ -39,7 +56,7 @@ with gr.Blocks(css=css) as app:
|
|
39 |
with gr.Row():
|
40 |
input_text = gr.Textbox(
|
41 |
label="Input Text",
|
42 |
-
placeholder="Enter
|
43 |
lines=8,
|
44 |
)
|
45 |
with gr.Row():
|
@@ -59,19 +76,20 @@ with gr.Blocks(css=css) as app:
|
|
59 |
label="Select Model",
|
60 |
value="gpt2-medium",
|
61 |
)
|
62 |
-
with gr.Row():
|
63 |
submit_button = gr.Button("Run Detection", variant="primary")
|
64 |
clear_button = gr.Button("Clear", variant="secondary")
|
65 |
with gr.Row():
|
66 |
output = gr.Textbox(
|
67 |
-
label="
|
68 |
-
placeholder="
|
69 |
elem_id="output-text",
|
70 |
)
|
71 |
submit_button.click(
|
72 |
run_test_power, inputs=[model_name, input_text, input_text], outputs=output
|
73 |
)
|
74 |
clear_button.click(lambda: ("", ""), inputs=[], outputs=[input_text, output])
|
|
|
|
|
75 |
with gr.Accordion("Disclaimer", open=False):
|
76 |
gr.Markdown(
|
77 |
"""
|
|
|
1 |
import gradio as gr
|
2 |
+
import spaces
|
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 "Prediction: Human (Mocked)"
|
15 |
|
16 |
+
|
17 |
+
|
18 |
+
# Change mode name
|
19 |
+
# def change_mode(mode):
|
20 |
+
# if mode == ""
|
21 |
+
|
22 |
+
|
23 |
+
|
24 |
css = """
|
25 |
+
#header { text-align: center; font-size: 1.5em; margin-bottom: 20px; }
|
26 |
#output-text { font-weight: bold; font-size: 1.2em; }
|
27 |
+
.links {
|
28 |
+
display: flex;
|
29 |
+
justify-content: flex-end;
|
30 |
+
gap: 10px;
|
31 |
+
margin-right: 10px;
|
32 |
align-items: center;
|
33 |
}
|
34 |
.separator {
|
|
|
40 |
# Gradio App
|
41 |
with gr.Blocks(css=css) as app:
|
42 |
with gr.Row():
|
43 |
+
gr.HTML('<div id="header">R-detect On HuggingFace</div>')
|
44 |
with gr.Row():
|
45 |
gr.HTML(
|
46 |
"""
|
|
|
56 |
with gr.Row():
|
57 |
input_text = gr.Textbox(
|
58 |
label="Input Text",
|
59 |
+
placeholder="Enter Text Here",
|
60 |
lines=8,
|
61 |
)
|
62 |
with gr.Row():
|
|
|
76 |
label="Select Model",
|
77 |
value="gpt2-medium",
|
78 |
)
|
|
|
79 |
submit_button = gr.Button("Run Detection", variant="primary")
|
80 |
clear_button = gr.Button("Clear", variant="secondary")
|
81 |
with gr.Row():
|
82 |
output = gr.Textbox(
|
83 |
+
label="Inference Result",
|
84 |
+
placeholder="Maked by Human or AI",
|
85 |
elem_id="output-text",
|
86 |
)
|
87 |
submit_button.click(
|
88 |
run_test_power, inputs=[model_name, input_text, input_text], outputs=output
|
89 |
)
|
90 |
clear_button.click(lambda: ("", ""), inputs=[], outputs=[input_text, output])
|
91 |
+
# model_name.change(change_mode, inputs=[model_name], outputs=[model_name])
|
92 |
+
|
93 |
with gr.Accordion("Disclaimer", open=False):
|
94 |
gr.Markdown(
|
95 |
"""
|