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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -1
app.py CHANGED
@@ -1,3 +1,20 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  def analyze_text(text):
2
  """Advanced forensic analysis with line-by-line proofs and modern conclusion"""
3
  if len(text.strip()) < 50:
@@ -62,4 +79,45 @@ def analyze_text(text):
62
  )
63
  return response['choices'][0]['message']['content']
64
  except Exception as e:
65
- return f"🔴 Analysis failed. Error: {str(e)}"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import openai
3
+ import os
4
+ from dotenv import load_dotenv
5
+
6
+ # Load environment variables
7
+ load_dotenv()
8
+
9
+ # Initialize OpenAI
10
+ try:
11
+ from openai import OpenAI
12
+ client = OpenAI(api_key=os.getenv("OPENAI_API_KEY").strip())
13
+ new_openai = True
14
+ except ImportError:
15
+ openai.api_key = os.getenv("OPENAI_API_KEY").strip()
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:
 
79
  )
80
  return response['choices'][0]['message']['content']
81
  except Exception as e:
82
+ return f"🔴 Analysis failed. Error: {str(e)}"
83
+
84
+ # Create Gradio interface
85
+ with gr.Blocks(theme=gr.themes.Soft(primary_hue="emerald")) as app:
86
+ gr.Markdown("""# 🔬 AI/Human Text Forensic Analyzer""")
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(
104
+ examples=examples,
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()