File size: 4,298 Bytes
d4e9eca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
75413cc
d2cf20b
0d76684
ce981c0
276462a
d2cf20b
ce981c0
 
d2cf20b
75413cc
d2cf20b
75413cc
 
d2cf20b
 
10458da
d2cf20b
 
 
75413cc
d2cf20b
 
75413cc
d2cf20b
 
75413cc
d2cf20b
 
 
 
75413cc
 
 
 
 
d2cf20b
75413cc
d2cf20b
 
75413cc
c58b6d1
d2cf20b
8dc41a0
75413cc
 
 
d2cf20b
75413cc
d2cf20b
 
75413cc
 
d2cf20b
8dc41a0
75413cc
8dc41a0
d4e9eca
 
 
 
 
 
 
 
d2cf20b
 
 
d4e9eca
 
d2cf20b
d4e9eca
 
d2cf20b
 
ce981c0
d4e9eca
 
 
 
 
 
 
d2cf20b
d4e9eca
 
 
 
 
 
d2cf20b
d4e9eca
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
import gradio as gr
import openai
import os
from dotenv import load_dotenv

# Load environment variables
load_dotenv()

# Initialize OpenAI
try:
    from openai import OpenAI
    client = OpenAI(api_key=os.getenv("OPENAI_API_KEY").strip())
    new_openai = True
except ImportError:
    openai.api_key = os.getenv("OPENAI_API_KEY").strip()
    new_openai = False

def analyze_text(text):
    """Forensic analysis focusing on 3-5 biggest logical proofs"""
    if len(text.strip()) < 50:
        return "🔍Write Your Text here for Analysis!"
    
    prompt = f"""
    You are a Text Analyzer Anna with experience of 40 Years in this field, and you are an expert in  Analyzing Text, whether a text is written 
    by AI or not. Conduct a forensic analysis of this text and identify the 3-5 BIGGEST, MOST LOGICAL proofs 
    that definitively show whether it's human or AI-generated. Focus only on the most undeniable evidence.

    TEXT:
    {text}

    RESPONSE FORMAT:
    # 🔍 Ultimate Text Verdict

    ## 🎯 Top Irrefutable Proofs
    1. **Proof** (Human/AI): "[Exact quote]"  
       • **Why it's conclusive**: [Clear, logical explanation why this is impossible for AI/human to produce]

    2. **Proof** (Human/AI): "[Exact quote]"  
       • **Why it's conclusive**: [Bulletproof reasoning]

    3. **Proof** (Human/AI): "[Exact quote]"  
       • **Why it's conclusive**: [Air-tight argument]

    ## 🏁 Final Judgment
    **Verdict**: [Human/AI/Uncertain]  
    **Confidence**: [XX% certainty]  
    **Final Note**: "In today's AI era, while this analysis presents strong evidence, the possibility of error remains."
    """

    try:
        if new_openai:
            response = client.chat.completions.create(
                model="gpt-4",  # Using GPT-4 for stronger logical analysis
                messages=[
                    {"role": "system", "content": "You are a forensic expert who only identifies the most undeniable proofs."},
                    {"role": "user", "content": prompt}
                ],
                temperature=0.1,
                max_tokens=500
            )
            return response.choices[0].message.content
        else:
            response = openai.ChatCompletion.create(
                model="gpt-4",
                messages=[
                    {"role": "system", "content": "You are a forensic expert who only identifies the most undeniable proofs."},
                    {"role": "user", "content": prompt}
                ],
                temperature=0.1,
                max_tokens=500
            )
            return response['choices'][0]['message']['content']
    except Exception as e:
        return f"🔴 Analysis failed. Error: {str(e)}"

# Create Gradio interface
with gr.Blocks(theme=gr.themes.Soft(primary_hue="emerald")) as app:
    gr.Markdown("""# 🔬 AI/Human Text Forensic Analyzer""")
    
    with gr.Row():
        with gr.Column():
            input_text = gr.Textbox(label="📝 Text to Analyze", lines=7, 
                                  placeholder="Paste text (min 50 chars)...")
            analyze_btn = gr.Button("🧪 Get Definitive Proofs", variant="primary")
        
        with gr.Column():
            output_text = gr.Markdown(label="📜 Irrefutable Evidence Report")
    
    examples = [
        ["The way the moonlight danced... that's not something algorithms capture. It's in the imperfect pauses between words where humanity lives."],
        ["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."],
        ["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"]
    ]
    
    gr.Examples(
        examples=examples,
        inputs=input_text,
        outputs=output_text,
        fn=analyze_text,
        label="💡 Try These Challenge Cases"
    )
    
    analyze_btn.click(analyze_text, inputs=input_text, outputs=output_text)

    gr.Markdown("""
    <div style="text-align: center; margin-top: 20px; color: #666;">
    <small>Analyzes only the most undeniable evidence • Confidence scores reflect logical certainty</small>
    </div>
    """)

if __name__ == "__main__":
    app.launch()