Spaces:
Runtime error
Runtime error
Update demo/demo.py
Browse files- demo/demo.py +39 -5
demo/demo.py
CHANGED
@@ -1,4 +1,27 @@
|
|
|
|
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
2 |
if mode == "Low False Positive Rate":
|
3 |
BINO.change_mode("low-fpr")
|
4 |
elif mode == "High Accuracy":
|
@@ -15,14 +38,25 @@
|
|
15 |
# return ["Loaded"] * 2
|
16 |
|
17 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
18 |
# Most likely human generated, #most likely AI written
|
19 |
|
20 |
capybara_problem = '''Dr. Capy Cosmos, a capybara unlike any other, astounded the scientific community with his groundbreaking research in astrophysics. With his keen sense of observation and unparalleled ability to interpret cosmic data, he uncovered new insights into the mysteries of black holes and the origins of the universe. As he peered through telescopes with his large, round eyes, fellow researchers often remarked that it seemed as if the stars themselves whispered their secrets directly to him. Dr. Cosmos not only became a beacon of inspiration to aspiring scientists but also proved that intellect and innovation can be found in the most unexpected of creatures.'''
|
21 |
|
22 |
-
tailwind_cdn = """
|
23 |
-
<script src="https://cdn.tailwindcss.com"></script>
|
24 |
-
"""
|
25 |
-
|
26 |
with gr.Blocks(css=css,
|
27 |
theme=gr.themes.Default(font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"])) as app:
|
28 |
with gr.Row():
|
@@ -97,4 +131,4 @@ with gr.Blocks(css=css,
|
|
97 |
# clear_button.click(lambda x: input_box., )
|
98 |
submit_button.click(run_detector, inputs=input_box, outputs=output_text)
|
99 |
clear_button.click(lambda: ("", ""), outputs=[input_box, output_text])
|
100 |
-
dropdown_mode.change(change_mode, inputs=[dropdown_mode], outputs=[dropdown_mode])
|
|
|
1 |
+
__all__ = ["app"]
|
2 |
|
3 |
+
import gradio as gr
|
4 |
+
import spaces
|
5 |
+
from binoculars import Binoculars
|
6 |
+
|
7 |
+
BINO = Binoculars(quantize=True)
|
8 |
+
TOKENIZER = BINO.tokenizer
|
9 |
+
MINIMUM_TOKENS = 64
|
10 |
+
|
11 |
+
|
12 |
+
def count_tokens(text):
|
13 |
+
return len(TOKENIZER(text).input_ids)
|
14 |
+
|
15 |
+
|
16 |
+
@spaces.GPU
|
17 |
+
def run_detector(input_str):
|
18 |
+
if count_tokens(input_str) < MINIMUM_TOKENS:
|
19 |
+
gr.Warning(f"Too short length. Need minimum {MINIMUM_TOKENS} tokens to run Binoculars.")
|
20 |
+
return ""
|
21 |
+
return f"{BINO.predict(input_str)}"
|
22 |
+
|
23 |
+
|
24 |
+
def change_mode(mode):
|
25 |
if mode == "Low False Positive Rate":
|
26 |
BINO.change_mode("low-fpr")
|
27 |
elif mode == "High Accuracy":
|
|
|
38 |
# return ["Loaded"] * 2
|
39 |
|
40 |
|
41 |
+
css = """
|
42 |
+
.green { color: black!important;line-height:1.9em; padding: 0.2em 0.2em; background: #ccffcc; border-radius:0.5rem;}
|
43 |
+
.red { color: black!important;line-height:1.9em; padding: 0.2em 0.2em; background: #ffad99; border-radius:0.5rem;}
|
44 |
+
.hyperlinks {
|
45 |
+
display: flex;
|
46 |
+
align-items: center;
|
47 |
+
align-content: center;
|
48 |
+
padding-top: 12px;
|
49 |
+
justify-content: flex-end;
|
50 |
+
margin: 0 10px; /* Adjust the margin as needed */
|
51 |
+
text-decoration: none;
|
52 |
+
color: #000; /* Set the desired text color */
|
53 |
+
}
|
54 |
+
"""
|
55 |
+
|
56 |
# Most likely human generated, #most likely AI written
|
57 |
|
58 |
capybara_problem = '''Dr. Capy Cosmos, a capybara unlike any other, astounded the scientific community with his groundbreaking research in astrophysics. With his keen sense of observation and unparalleled ability to interpret cosmic data, he uncovered new insights into the mysteries of black holes and the origins of the universe. As he peered through telescopes with his large, round eyes, fellow researchers often remarked that it seemed as if the stars themselves whispered their secrets directly to him. Dr. Cosmos not only became a beacon of inspiration to aspiring scientists but also proved that intellect and innovation can be found in the most unexpected of creatures.'''
|
59 |
|
|
|
|
|
|
|
|
|
60 |
with gr.Blocks(css=css,
|
61 |
theme=gr.themes.Default(font=[gr.themes.GoogleFont("Inconsolata"), "Arial", "sans-serif"])) as app:
|
62 |
with gr.Row():
|
|
|
131 |
# clear_button.click(lambda x: input_box., )
|
132 |
submit_button.click(run_detector, inputs=input_box, outputs=output_text)
|
133 |
clear_button.click(lambda: ("", ""), outputs=[input_box, output_text])
|
134 |
+
dropdown_mode.change(change_mode, inputs=[dropdown_mode], outputs=[dropdown_mode])
|