Spaces:
Runtime error
Runtime error
prompt improvments to regenerating and added highlighter to polygraf ai checks
Browse files
app.py
CHANGED
@@ -8,6 +8,9 @@ import requests
|
|
8 |
from gptzero_free import GPT2PPL
|
9 |
import language_tool_python
|
10 |
import re
|
|
|
|
|
|
|
11 |
|
12 |
|
13 |
def remove_bracketed_numbers(text):
|
@@ -92,13 +95,8 @@ def regenerate_prompt(settings: Dict[str, str]) -> str:
|
|
92 |
|
93 |
Comments:
|
94 |
- {settings['user_comments']}
|
|
|
95 |
- Keep the references the same as the given text in the same format.
|
96 |
-
|
97 |
-
Additional requirements:
|
98 |
-
- Include {settings['num_examples']} relevant examples or case studies
|
99 |
-
- Incorporate data or statistics from {', '.join(settings['references'])}
|
100 |
-
- End with a {settings['conclusion_type']} conclusion
|
101 |
-
- Add a "References" section at the end with at least 3 credible sources, formatted as [1], [2], etc.
|
102 |
- Do not make any headline, title bold.
|
103 |
|
104 |
Ensure proper paragraph breaks for better readability.
|
@@ -191,13 +189,15 @@ def humanize(
|
|
191 |
|
192 |
|
193 |
ai_check_options = [
|
194 |
-
"Polygraf AI",
|
|
|
|
|
195 |
# "Sapling AI",
|
196 |
"GPTZero",
|
197 |
]
|
198 |
|
199 |
|
200 |
-
def ai_generated_test_polygraf(text: str)
|
201 |
url = "http://34.66.10.188/ai-vs-human"
|
202 |
access_key = "6mcemwsFycVVgVjMFwKXki3zJka1r7N4u$Z0Y|x$gecC$hdNtpQf-SpL0+=k;u%BZ"
|
203 |
headers = {"ACCESS_KEY": access_key}
|
@@ -217,18 +217,41 @@ def ai_generated_test_gptzero(text):
|
|
217 |
gptzero_model = GPT2PPL()
|
218 |
result = gptzero_model(text)
|
219 |
print(result)
|
220 |
-
return result
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
221 |
|
222 |
|
223 |
-
def ai_check(text: str, option: str)
|
224 |
-
if option
|
225 |
-
return
|
226 |
elif option == "Sapling AI":
|
227 |
return ai_generated_test_sapling(text)
|
228 |
elif option == "GPTZero":
|
229 |
return ai_generated_test_gptzero(text)
|
230 |
else:
|
231 |
-
return
|
232 |
|
233 |
|
234 |
def update_visibility_api(model: str):
|
@@ -468,6 +491,7 @@ def create_interface():
|
|
468 |
ai_check_btn = gr.Button("AI Check")
|
469 |
ai_check_result = gr.Label(label="AI Check Result")
|
470 |
|
|
|
471 |
humanize_btn = gr.Button("Humanize")
|
472 |
# humanized_output = gr.Textbox(label="Humanized Article", lines=20, elem_classes=["custom-textbox"])
|
473 |
humanized_output = gr.Markdown(label="Humanized Article", value="\n\n\n\n", height="24em", render=True)
|
@@ -479,6 +503,13 @@ def create_interface():
|
|
479 |
else:
|
480 |
return gr.update(visible=False)
|
481 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
482 |
output_article.change(become_visible, inputs=output_article, outputs=ai_comments)
|
483 |
ai_comments.change(become_visible, inputs=output_article, outputs=regenerate_btn)
|
484 |
|
@@ -527,6 +558,7 @@ def create_interface():
|
|
527 |
],
|
528 |
outputs=[output_article],
|
529 |
)
|
|
|
530 |
regenerate_btn.click(
|
531 |
fn=generate_and_format,
|
532 |
inputs=[
|
@@ -553,7 +585,7 @@ def create_interface():
|
|
553 |
ai_check_btn.click(
|
554 |
fn=ai_check,
|
555 |
inputs=[output_article, ai_detector_dropdown],
|
556 |
-
outputs=[ai_check_result],
|
557 |
)
|
558 |
|
559 |
humanize_btn.click(
|
|
|
8 |
from gptzero_free import GPT2PPL
|
9 |
import language_tool_python
|
10 |
import re
|
11 |
+
from gradio_client import Client
|
12 |
+
|
13 |
+
highlighter_client = Client("polygraf-ai/highlighter_test")
|
14 |
|
15 |
|
16 |
def remove_bracketed_numbers(text):
|
|
|
95 |
|
96 |
Comments:
|
97 |
- {settings['user_comments']}
|
98 |
+
- The originial content should not be changed. Make minor modifications based on user comments above.
|
99 |
- Keep the references the same as the given text in the same format.
|
|
|
|
|
|
|
|
|
|
|
|
|
100 |
- Do not make any headline, title bold.
|
101 |
|
102 |
Ensure proper paragraph breaks for better readability.
|
|
|
189 |
|
190 |
|
191 |
ai_check_options = [
|
192 |
+
"Polygraf AI Base",
|
193 |
+
"Polygraf AI 2 Sentence Block",
|
194 |
+
"Polygraf AI 3 Sentence Block",
|
195 |
# "Sapling AI",
|
196 |
"GPTZero",
|
197 |
]
|
198 |
|
199 |
|
200 |
+
def ai_generated_test_polygraf(text: str):
|
201 |
url = "http://34.66.10.188/ai-vs-human"
|
202 |
access_key = "6mcemwsFycVVgVjMFwKXki3zJka1r7N4u$Z0Y|x$gecC$hdNtpQf-SpL0+=k;u%BZ"
|
203 |
headers = {"ACCESS_KEY": access_key}
|
|
|
217 |
gptzero_model = GPT2PPL()
|
218 |
result = gptzero_model(text)
|
219 |
print(result)
|
220 |
+
return result, None
|
221 |
+
|
222 |
+
|
223 |
+
def highlighter_polygraf(text, model="Polygraf AI Base"):
|
224 |
+
if model == "Polygraf AI Base":
|
225 |
+
result = highlighter_client.predict(text=text, model="BC Original", api_name="/process_text")
|
226 |
+
ai_score = result[0]["confidences"][0]["confidence"]
|
227 |
+
ai_res = {"AI": ai_score, "HUMAN": 1 - ai_score}
|
228 |
+
return ai_res, result[1]
|
229 |
+
elif model == "Polygraf AI 2 Sentence Block":
|
230 |
+
result = highlighter_client.predict(text=text, model="BC 2 Sentences", api_name="/process_text")
|
231 |
+
ai_score = result[0]["confidences"][0]["confidence"]
|
232 |
+
ai_res = {"AI": ai_score, "HUMAN": 1 - ai_score}
|
233 |
+
return ai_res, result[1]
|
234 |
+
elif model == "Polygraf AI 3 Sentence Block":
|
235 |
+
result = highlighter_client.predict(text=text, model="BC 3 Sentences", api_name="/process_text")
|
236 |
+
ai_score = result[0]["confidences"][0]["confidence"]
|
237 |
+
ai_res = {"AI": ai_score, "HUMAN": 1 - ai_score}
|
238 |
+
return ai_res, result[1]
|
239 |
+
else:
|
240 |
+
result = highlighter_client.predict(text=text, model="BC Original", api_name="/process_text")
|
241 |
+
ai_score = result[0]["confidences"][0]["confidence"]
|
242 |
+
ai_res = {"AI": ai_score, "HUMAN": 1 - ai_score}
|
243 |
+
return ai_res, result[1]
|
244 |
|
245 |
|
246 |
+
def ai_check(text: str, option: str):
|
247 |
+
if option.startswith("Polygraf AI"):
|
248 |
+
return highlighter_polygraf(text, option)
|
249 |
elif option == "Sapling AI":
|
250 |
return ai_generated_test_sapling(text)
|
251 |
elif option == "GPTZero":
|
252 |
return ai_generated_test_gptzero(text)
|
253 |
else:
|
254 |
+
return highlighter_polygraf(text, option)
|
255 |
|
256 |
|
257 |
def update_visibility_api(model: str):
|
|
|
491 |
ai_check_btn = gr.Button("AI Check")
|
492 |
ai_check_result = gr.Label(label="AI Check Result")
|
493 |
|
494 |
+
highlighted_text = gr.HTML(label="Sentence Breakdown", visible=False)
|
495 |
humanize_btn = gr.Button("Humanize")
|
496 |
# humanized_output = gr.Textbox(label="Humanized Article", lines=20, elem_classes=["custom-textbox"])
|
497 |
humanized_output = gr.Markdown(label="Humanized Article", value="\n\n\n\n", height="24em", render=True)
|
|
|
503 |
else:
|
504 |
return gr.update(visible=False)
|
505 |
|
506 |
+
def highlight_visible(text):
|
507 |
+
if text.startswith("Polygraf"):
|
508 |
+
return gr.update(visible=True)
|
509 |
+
else:
|
510 |
+
return gr.update(visible=False)
|
511 |
+
|
512 |
+
ai_detector_dropdown.change(highlight_visible, inputs=ai_detector_dropdown, outputs=highlighted_text)
|
513 |
output_article.change(become_visible, inputs=output_article, outputs=ai_comments)
|
514 |
ai_comments.change(become_visible, inputs=output_article, outputs=regenerate_btn)
|
515 |
|
|
|
558 |
],
|
559 |
outputs=[output_article],
|
560 |
)
|
561 |
+
|
562 |
regenerate_btn.click(
|
563 |
fn=generate_and_format,
|
564 |
inputs=[
|
|
|
585 |
ai_check_btn.click(
|
586 |
fn=ai_check,
|
587 |
inputs=[output_article, ai_detector_dropdown],
|
588 |
+
outputs=[ai_check_result, highlighted_text],
|
589 |
)
|
590 |
|
591 |
humanize_btn.click(
|