Spaces:
Running
on
Zero
Running
on
Zero
Commit
·
2940841
1
Parent(s):
f12e9a8
Added a few qol changes
Browse files
app.py
CHANGED
@@ -20,6 +20,25 @@ def update_textboxes(n_visible):
|
|
20 |
updates.append(gr.update(visible=False))
|
21 |
return n_visible, *updates
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def run_scoring(input_text, model1, model2, model3, model4, model5, model6, model7, model8, model9, model10, threshold_choice, custom_threshold):
|
24 |
"""
|
25 |
Collect all non-empty model paths, instantiate Mosaic, compute the score,
|
@@ -46,7 +65,7 @@ def run_scoring(input_text, model1, model2, model3, model4, model5, model6, mode
|
|
46 |
if final_score < threshold:
|
47 |
result_message = "This text was probably generated."
|
48 |
else:
|
49 |
-
result_message = "This text is likely human-
|
50 |
return result_message, final_score, threshold
|
51 |
|
52 |
with gr.Blocks() as demo:
|
@@ -54,29 +73,37 @@ with gr.Blocks() as demo:
|
|
54 |
with gr.Row():
|
55 |
input_text = gr.Textbox(lines=10, placeholder="Enter text here...", label="Input Text")
|
56 |
with gr.Column():
|
|
|
57 |
gr.Markdown("### Model Paths (at least 2 required)")
|
58 |
gr.Markdown("Order matters for model 1 only, the Reference model. Please use the one with the best perplexity on human texts. (The largest LLM if applicable.) GPT2 models are enough to detect easy prompts from chatgpt.")
|
59 |
# State to keep track of the number of visible textboxes (starting with 2)
|
60 |
-
n_models_state = gr.State(
|
61 |
# Create 10 textboxes. We'll name them model1, model2, ..., model10.
|
62 |
-
model1 = gr.Textbox(value="
|
63 |
-
model2 = gr.Textbox(value="
|
64 |
-
model3 = gr.Textbox(value="", label="Model 3 Path", visible=
|
65 |
-
model4 = gr.Textbox(value="", label="Model 4 Path", visible=
|
66 |
model5 = gr.Textbox(value="", label="Model 5 Path", visible=False)
|
67 |
model6 = gr.Textbox(value="", label="Model 6 Path", visible=False)
|
68 |
model7 = gr.Textbox(value="", label="Model 7 Path", visible=False)
|
69 |
model8 = gr.Textbox(value="", label="Model 8 Path", visible=False)
|
70 |
model9 = gr.Textbox(value="", label="Model 9 Path", visible=False)
|
71 |
model10 = gr.Textbox(value="", label="Model 10 Path", visible=False)
|
72 |
-
# Add
|
73 |
-
|
74 |
-
|
|
|
|
|
75 |
plus_button.click(
|
76 |
fn=update_textboxes,
|
77 |
inputs=n_models_state,
|
78 |
outputs=[n_models_state, model1, model2, model3, model4, model5, model6, model7, model8, model9, model10]
|
79 |
)
|
|
|
|
|
|
|
|
|
|
|
80 |
with gr.Row():
|
81 |
threshold_choice = gr.Radio(choices=["default", "raid", "custom"], value="default", label="Threshold Choice")
|
82 |
custom_threshold = gr.Number(value=0.0, label="Custom Threshold (if 'custom' selected)")
|
|
|
20 |
updates.append(gr.update(visible=False))
|
21 |
return n_visible, *updates
|
22 |
|
23 |
+
# Function to decrease visible textboxes
|
24 |
+
def remove_textboxes(n_visible):
|
25 |
+
"""
|
26 |
+
Given the current visible count, decrements it by 1 (down to 2)
|
27 |
+
and returns updated visibility settings for all model textboxes,
|
28 |
+
clearing the content of any hidden ones.
|
29 |
+
"""
|
30 |
+
if n_visible > 2:
|
31 |
+
n_visible -= 1
|
32 |
+
updates = []
|
33 |
+
for i in range(MAX_MODELS):
|
34 |
+
if i < n_visible:
|
35 |
+
# keep visible, preserve existing value
|
36 |
+
updates.append(gr.update(visible=True))
|
37 |
+
else:
|
38 |
+
# hide and clear content
|
39 |
+
updates.append(gr.update(visible=False, value=""))
|
40 |
+
return (n_visible, *updates)
|
41 |
+
|
42 |
def run_scoring(input_text, model1, model2, model3, model4, model5, model6, model7, model8, model9, model10, threshold_choice, custom_threshold):
|
43 |
"""
|
44 |
Collect all non-empty model paths, instantiate Mosaic, compute the score,
|
|
|
65 |
if final_score < threshold:
|
66 |
result_message = "This text was probably generated."
|
67 |
else:
|
68 |
+
result_message = "This text is likely human-written."
|
69 |
return result_message, final_score, threshold
|
70 |
|
71 |
with gr.Blocks() as demo:
|
|
|
73 |
with gr.Row():
|
74 |
input_text = gr.Textbox(lines=10, placeholder="Enter text here...", label="Input Text")
|
75 |
with gr.Column():
|
76 |
+
gr.Markdown("**⚠️ Please make sure all models have the same tokenizer or it won’t work.**")
|
77 |
gr.Markdown("### Model Paths (at least 2 required)")
|
78 |
gr.Markdown("Order matters for model 1 only, the Reference model. Please use the one with the best perplexity on human texts. (The largest LLM if applicable.) GPT2 models are enough to detect easy prompts from chatgpt.")
|
79 |
# State to keep track of the number of visible textboxes (starting with 2)
|
80 |
+
n_models_state = gr.State(4)
|
81 |
# Create 10 textboxes. We'll name them model1, model2, ..., model10.
|
82 |
+
model1 = gr.Textbox(value="Unbabel/TowerBase-13B-v0.1", label="Model 1 Path ", visible=True)
|
83 |
+
model2 = gr.Textbox(value="Unbabel/TowerBase-7B-v0.1", label="Model 2 Path", visible=True)
|
84 |
+
model3 = gr.Textbox(value="meta-llama/Llama-2-7b-chat-hf", label="Model 3 Path", visible=True)
|
85 |
+
model4 = gr.Textbox(value="meta-llama/Llama-2-7b-hf", label="Model 4 Path", visible=True)
|
86 |
model5 = gr.Textbox(value="", label="Model 5 Path", visible=False)
|
87 |
model6 = gr.Textbox(value="", label="Model 6 Path", visible=False)
|
88 |
model7 = gr.Textbox(value="", label="Model 7 Path", visible=False)
|
89 |
model8 = gr.Textbox(value="", label="Model 8 Path", visible=False)
|
90 |
model9 = gr.Textbox(value="", label="Model 9 Path", visible=False)
|
91 |
model10 = gr.Textbox(value="", label="Model 10 Path", visible=False)
|
92 |
+
# Add plus and minus buttons to reveal/hide textboxes.
|
93 |
+
with gr.Row():
|
94 |
+
plus_button = gr.Button("+", elem_id="plus_button")
|
95 |
+
minus_button = gr.Button("-", elem_id="minus_button")
|
96 |
+
# Bind click events
|
97 |
plus_button.click(
|
98 |
fn=update_textboxes,
|
99 |
inputs=n_models_state,
|
100 |
outputs=[n_models_state, model1, model2, model3, model4, model5, model6, model7, model8, model9, model10]
|
101 |
)
|
102 |
+
minus_button.click(
|
103 |
+
fn=remove_textboxes,
|
104 |
+
inputs=n_models_state,
|
105 |
+
outputs=[n_models_state, model1, model2, model3, model4, model5, model6, model7, model8, model9, model10]
|
106 |
+
)
|
107 |
with gr.Row():
|
108 |
threshold_choice = gr.Radio(choices=["default", "raid", "custom"], value="default", label="Threshold Choice")
|
109 |
custom_threshold = gr.Number(value=0.0, label="Custom Threshold (if 'custom' selected)")
|