hashirlodhi commited on
Commit
d2cf20b
Β·
verified Β·
1 Parent(s): d4e9eca

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +35 -47
app.py CHANGED
@@ -16,66 +16,57 @@ except ImportError:
16
  new_openai = False
17
 
18
  def analyze_text(text):
19
- """Advanced forensic analysis with line-by-line proofs and modern conclusion"""
20
  if len(text.strip()) < 50:
21
  return "⚠️ Please provide at least 50 characters for accurate analysis."
22
 
23
- # Enhanced prompt with line-by-line analysis requirement
24
- expert_prompt = f"""
25
- [ROLE]
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
- [TEXT TO ANALYZE]
29
  {text}
30
 
31
- [INSTRUCTIONS]
32
- 1. Analyze each significant line/sentence showing either:
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
- [REQUIRED OUTPUT FORMAT]
40
- # πŸ•΅οΈβ€β™‚οΈ Forensic Text Analysis Report
 
41
 
42
- ## πŸ” Line-by-Line Proofs
43
- **Line X/Y:** "Quote specific text"
44
- - 🟒 Human indicator: Explanation why this can't be AI-generated
45
- - πŸ”΄ AI indicator: Explanation why this is unlikely from human
46
 
47
- (Repeat for each significant line)
 
48
 
49
- ## πŸ“Š Final Assessment
50
- **Verdict:** {{Human/AI/Uncertain}}
51
- **Confidence:** {{XX%}}
52
- **Score:** {{X/10}} (0=Human, 10=AI)
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-3.5-turbo",
62
  messages=[
63
- {"role": "system", "content": "You are a forensic text analysis AI that provides specific proofs."},
64
- {"role": "user", "content": expert_prompt}
65
  ],
66
  temperature=0.1,
67
- max_tokens=700 # Increased for detailed analysis
68
  )
69
  return response.choices[0].message.content
70
  else:
71
  response = openai.ChatCompletion.create(
72
- model="gpt-3.5-turbo",
73
  messages=[
74
- {"role": "system", "content": "You are a forensic text analysis AI that provides specific proofs."},
75
- {"role": "user", "content": expert_prompt}
76
  ],
77
  temperature=0.1,
78
- max_tokens=700
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, placeholder="Paste the text you want analyzed (minimum 50 characters)...")
91
- analyze_btn = gr.Button("πŸ§ͺ Analyze Text", variant="primary")
 
92
 
93
  with gr.Column():
94
- output_text = gr.Markdown(label="πŸ“œ Analysis Report")
95
 
96
- # Add some examples
97
  examples = [
98
- ["The rain fell softly on the weathered cobblestones as I wandered through memories of a time long past. There's something about autumn that makes nostalgia feel almost tangible."],
99
- ["Based on statistical analysis of meteorological patterns, precipitation occurred with 78% probability in the specified geographic coordinates during the recorded time period."],
100
- ["I dunno why but it just feels right, ya know? Like when you put on those old jeans that fit just perfect. Can't explain it, just feels good."]
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
- cache_examples=True,
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>Note: In the modern AI era, no analysis can be 100% certain. All verdicts can be challenged.</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()