Kavinda2000003 commited on
Commit
23df277
·
verified ·
1 Parent(s): 45f60a9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +55 -4
app.py CHANGED
@@ -1,6 +1,57 @@
1
  import streamlit as st
 
 
 
2
 
3
- st.title("GK AI Detector") # Your app title
4
- user_text = st.text_input("Enter text here") # User input
5
- if user_text:
6
- st.success(f"Your text: {user_text}") # Display result
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ from transformers import pipeline
3
+ from PyPDF2 import PdfReader
4
+ import docx
5
 
6
+ # Page setup
7
+ st.set_page_config(layout="wide")
8
+ st.title("📄 AI Content Analyzer")
9
+ st.markdown("Upload PDF/Word files to detect AI-generated text")
10
+
11
+ # Load AI detection model
12
+ @st.cache_resource
13
+ def load_model():
14
+ return pipeline("text-classification", model="roberta-base-openai-detector")
15
+
16
+ detector = load_model()
17
+
18
+ # File uploader
19
+ uploaded_file = st.file_uploader("Upload file (PDF or Word)", type=["pdf", "docx", "txt"])
20
+
21
+ if uploaded_file:
22
+ # Extract text
23
+ text = ""
24
+ if uploaded_file.name.endswith(".pdf"):
25
+ reader = PdfReader(uploaded_file)
26
+ text = "".join([page.extract_text() or "" for page in reader.pages])
27
+ elif uploaded_file.name.endswith(".docx"):
28
+ doc = docx.Document(uploaded_file)
29
+ text = "\n".join([para.text for para in doc.paragraphs])
30
+ else:
31
+ text = uploaded_file.read().decode("utf-8")
32
+
33
+ # Analyze on button click
34
+ if st.button("Analyze Content"):
35
+ if len(text) < 50:
36
+ st.warning("Not enough text to analyze!")
37
+ else:
38
+ result = detector(text[:5000]) # First 5000 chars for speed
39
+ ai_prob = result[0]['score'] * 100 if result[0]['label'] == 'FAKE' else 100 - (result[0]['score'] * 100)
40
+
41
+ # Display results
42
+ st.subheader("Analysis Results")
43
+
44
+ # AI Probability Meter
45
+ st.metric("AI Content Probability", f"{ai_prob:.2f}%")
46
+ st.progress(int(ai_prob))
47
+
48
+ # File details
49
+ st.markdown(f"""
50
+ - **File:** `{uploaded_file.name}`
51
+ - **Text Length:** {len(text)} characters
52
+ - **AI Probability:** {ai_prob:.2f}%
53
+ """)
54
+
55
+ # Text preview
56
+ with st.expander("View extracted text"):
57
+ st.text(text[:1000] + "...") # First 1000 chars