Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
|
@@ -16,66 +16,57 @@ except ImportError:
|
|
| 16 |
new_openai = False
|
| 17 |
|
| 18 |
def analyze_text(text):
|
| 19 |
-
"""
|
| 20 |
if len(text.strip()) < 50:
|
| 21 |
return "β οΈ Please provide at least 50 characters for accurate analysis."
|
| 22 |
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
You are Dr. Lexica, a forensic linguistics expert specializing in AI/human text differentiation. Your task is to analyze the provided text line by line and determine its origin, providing specific proofs for each finding.
|
| 27 |
|
| 28 |
-
|
| 29 |
{text}
|
| 30 |
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
- "This can't be AI because..." with specific linguistic proof
|
| 34 |
-
- "This suggests AI because..." with specific markers
|
| 35 |
-
2. Provide line numbers or quote specific phrases
|
| 36 |
-
3. Include a modern conclusion about text origin uncertainty
|
| 37 |
-
4. Format output exactly as specified
|
| 38 |
|
| 39 |
-
|
| 40 |
-
|
|
|
|
| 41 |
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
- π’ Human indicator: Explanation why this can't be AI-generated
|
| 45 |
-
- π΄ AI indicator: Explanation why this is unlikely from human
|
| 46 |
|
| 47 |
-
|
|
|
|
| 48 |
|
| 49 |
-
##
|
| 50 |
-
**Verdict
|
| 51 |
-
**Confidence
|
| 52 |
-
**
|
| 53 |
-
|
| 54 |
-
## π‘ Modern Conclusion
|
| 55 |
-
In today's digital age, distinguishing AI from human text has become increasingly challenging. While my analysis suggests [VERDICT], this conclusion can be challenged because [REASON]. The boundaries between human and machine writing continue to blur, making absolute certainty impossible. My suggestion is based on current linguistic patterns, but new AI models may overcome these limitations.
|
| 56 |
"""
|
| 57 |
|
| 58 |
try:
|
| 59 |
if new_openai:
|
| 60 |
response = client.chat.completions.create(
|
| 61 |
-
model="gpt-
|
| 62 |
messages=[
|
| 63 |
-
{"role": "system", "content": "You are a forensic
|
| 64 |
-
{"role": "user", "content":
|
| 65 |
],
|
| 66 |
temperature=0.1,
|
| 67 |
-
max_tokens=
|
| 68 |
)
|
| 69 |
return response.choices[0].message.content
|
| 70 |
else:
|
| 71 |
response = openai.ChatCompletion.create(
|
| 72 |
-
model="gpt-
|
| 73 |
messages=[
|
| 74 |
-
{"role": "system", "content": "You are a forensic
|
| 75 |
-
{"role": "user", "content":
|
| 76 |
],
|
| 77 |
temperature=0.1,
|
| 78 |
-
max_tokens=
|
| 79 |
)
|
| 80 |
return response['choices'][0]['message']['content']
|
| 81 |
except Exception as e:
|
|
@@ -87,17 +78,17 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="emerald")) as app:
|
|
| 87 |
|
| 88 |
with gr.Row():
|
| 89 |
with gr.Column():
|
| 90 |
-
input_text = gr.Textbox(label="π Text to Analyze", lines=7,
|
| 91 |
-
|
|
|
|
| 92 |
|
| 93 |
with gr.Column():
|
| 94 |
-
output_text = gr.Markdown(label="π
|
| 95 |
|
| 96 |
-
# Add some examples
|
| 97 |
examples = [
|
| 98 |
-
["The
|
| 99 |
-
["
|
| 100 |
-
["
|
| 101 |
]
|
| 102 |
|
| 103 |
gr.Examples(
|
|
@@ -105,19 +96,16 @@ with gr.Blocks(theme=gr.themes.Soft(primary_hue="emerald")) as app:
|
|
| 105 |
inputs=input_text,
|
| 106 |
outputs=output_text,
|
| 107 |
fn=analyze_text,
|
| 108 |
-
|
| 109 |
-
label="π‘ Try these examples"
|
| 110 |
)
|
| 111 |
|
| 112 |
analyze_btn.click(analyze_text, inputs=input_text, outputs=output_text)
|
| 113 |
|
| 114 |
-
# Add footer
|
| 115 |
gr.Markdown("""
|
| 116 |
<div style="text-align: center; margin-top: 20px; color: #666;">
|
| 117 |
-
<small>
|
| 118 |
</div>
|
| 119 |
""")
|
| 120 |
|
| 121 |
-
# Launch the app
|
| 122 |
if __name__ == "__main__":
|
| 123 |
app.launch()
|
|
|
|
| 16 |
new_openai = False
|
| 17 |
|
| 18 |
def analyze_text(text):
|
| 19 |
+
"""Forensic analysis focusing on 3-5 biggest logical proofs"""
|
| 20 |
if len(text.strip()) < 50:
|
| 21 |
return "β οΈ Please provide at least 50 characters for accurate analysis."
|
| 22 |
|
| 23 |
+
prompt = f"""
|
| 24 |
+
Conduct a forensic analysis of this text and identify the 3-5 BIGGEST, MOST LOGICAL proofs
|
| 25 |
+
that definitively show whether it's human or AI-generated. Focus only on the most undeniable evidence.
|
|
|
|
| 26 |
|
| 27 |
+
TEXT:
|
| 28 |
{text}
|
| 29 |
|
| 30 |
+
RESPONSE FORMAT:
|
| 31 |
+
# π Ultimate Text Verdict
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 32 |
|
| 33 |
+
## π― Top Irrefutable Proofs
|
| 34 |
+
1. **Proof** (Human/AI): "[Exact quote]"
|
| 35 |
+
β’ **Why it's conclusive**: [Clear, logical explanation why this is impossible for AI/human to produce]
|
| 36 |
|
| 37 |
+
2. **Proof** (Human/AI): "[Exact quote]"
|
| 38 |
+
β’ **Why it's conclusive**: [Bulletproof reasoning]
|
|
|
|
|
|
|
| 39 |
|
| 40 |
+
3. **Proof** (Human/AI): "[Exact quote]"
|
| 41 |
+
β’ **Why it's conclusive**: [Air-tight argument]
|
| 42 |
|
| 43 |
+
## π Final Judgment
|
| 44 |
+
**Verdict**: [Human/AI/Uncertain]
|
| 45 |
+
**Confidence**: [XX% certainty]
|
| 46 |
+
**Final Note**: "In today's AI era, while this analysis presents strong evidence, the possibility of error remains."
|
|
|
|
|
|
|
|
|
|
| 47 |
"""
|
| 48 |
|
| 49 |
try:
|
| 50 |
if new_openai:
|
| 51 |
response = client.chat.completions.create(
|
| 52 |
+
model="gpt-4", # Using GPT-4 for stronger logical analysis
|
| 53 |
messages=[
|
| 54 |
+
{"role": "system", "content": "You are a forensic expert who only identifies the most undeniable proofs."},
|
| 55 |
+
{"role": "user", "content": prompt}
|
| 56 |
],
|
| 57 |
temperature=0.1,
|
| 58 |
+
max_tokens=500
|
| 59 |
)
|
| 60 |
return response.choices[0].message.content
|
| 61 |
else:
|
| 62 |
response = openai.ChatCompletion.create(
|
| 63 |
+
model="gpt-4",
|
| 64 |
messages=[
|
| 65 |
+
{"role": "system", "content": "You are a forensic expert who only identifies the most undeniable proofs."},
|
| 66 |
+
{"role": "user", "content": prompt}
|
| 67 |
],
|
| 68 |
temperature=0.1,
|
| 69 |
+
max_tokens=500
|
| 70 |
)
|
| 71 |
return response['choices'][0]['message']['content']
|
| 72 |
except Exception as e:
|
|
|
|
| 78 |
|
| 79 |
with gr.Row():
|
| 80 |
with gr.Column():
|
| 81 |
+
input_text = gr.Textbox(label="π Text to Analyze", lines=7,
|
| 82 |
+
placeholder="Paste text (min 50 chars)...")
|
| 83 |
+
analyze_btn = gr.Button("π§ͺ Get Definitive Proofs", variant="primary")
|
| 84 |
|
| 85 |
with gr.Column():
|
| 86 |
+
output_text = gr.Markdown(label="π Irrefutable Evidence Report")
|
| 87 |
|
|
|
|
| 88 |
examples = [
|
| 89 |
+
["The way the moonlight danced... that's not something algorithms capture. It's in the imperfect pauses between words where humanity lives."],
|
| 90 |
+
["The optimal temperature for this chemical reaction is 37.5Β°C, with a tolerance of Β±2Β°C. This falls within the expected range according to published studies."],
|
| 91 |
+
["Lol idk why but when I try to explain it just comes out all wrong? Like my brain and mouth ain't connected today smh"]
|
| 92 |
]
|
| 93 |
|
| 94 |
gr.Examples(
|
|
|
|
| 96 |
inputs=input_text,
|
| 97 |
outputs=output_text,
|
| 98 |
fn=analyze_text,
|
| 99 |
+
label="π‘ Try These Challenge Cases"
|
|
|
|
| 100 |
)
|
| 101 |
|
| 102 |
analyze_btn.click(analyze_text, inputs=input_text, outputs=output_text)
|
| 103 |
|
|
|
|
| 104 |
gr.Markdown("""
|
| 105 |
<div style="text-align: center; margin-top: 20px; color: #666;">
|
| 106 |
+
<small>Analyzes only the most undeniable evidence β’ Confidence scores reflect logical certainty</small>
|
| 107 |
</div>
|
| 108 |
""")
|
| 109 |
|
|
|
|
| 110 |
if __name__ == "__main__":
|
| 111 |
app.launch()
|