sundaram07 commited on
Commit
5dcfd82
ยท
verified ยท
1 Parent(s): c0a3abb

Update src/streamlit_app.py

Browse files
Files changed (1) hide show
  1. src/streamlit_app.py +12 -3
src/streamlit_app.py CHANGED
@@ -11,12 +11,16 @@ os.environ["TRANSFORMERS_CACHE"] = "/tmp/huggingface"
11
 
12
  # ๐Ÿ“ฅ Download NLTK tokenizer
13
  nltk_data_path = "/tmp/nltk_data"
14
- nltk.download("punkt_tab", download_dir=nltk_data_path)
15
  nltk.data.path.append(nltk_data_path)
16
 
17
  # ๐Ÿ”„ Load tokenizer and model from Hugging Face
18
- tokenizer = DistilBertTokenizerFast.from_pretrained("distilbert-base-uncased", cache_dir="/tmp/huggingface")
19
- model = TFDistilBertForSequenceClassification.from_pretrained("sundaram07/distilbert-sentence-classifier", cache_dir="/tmp/huggingface")
 
 
 
 
20
 
21
  # ๐Ÿ”ฎ Predict AI probability for a sentence
22
  def predict_sentence_ai_probability(sentence):
@@ -49,18 +53,23 @@ st.set_page_config(page_title="AI Detector", layout="wide")
49
  st.title("๐Ÿง  AI Content Detector")
50
  st.markdown("This app detects the percentage of **AI-generated content** based on sentence-level analysis using DistilBERT.")
51
 
 
52
  user_input = st.text_area("๐Ÿ“‹ Paste your text below to check for AI-generated sentences:", height=300)
53
 
 
54
  if st.button("๐Ÿ” Analyze"):
55
  if not user_input.strip():
56
  st.warning("โš ๏ธ Please enter some text to analyze.")
57
  else:
 
58
  ai_percentage, analysis_results = predict_ai_generated_percentage(user_input)
59
 
 
60
  st.subheader("๐Ÿ” Sentence-level Analysis")
61
  for i, (sentence, prob, is_ai) in enumerate(analysis_results, start=1):
62
  label = "๐ŸŸข Human" if not is_ai else "๐Ÿ”ด AI"
63
  st.markdown(f"**{i}.** _{sentence}_\n\n โ†’ {label}")
64
 
 
65
  st.subheader("๐Ÿ“Š Final Result")
66
  st.success(f"Estimated **AI-generated content**: **{ai_percentage:.2f}%**")
 
11
 
12
  # ๐Ÿ“ฅ Download NLTK tokenizer
13
  nltk_data_path = "/tmp/nltk_data"
14
+ nltk.download("punkt", download_dir=nltk_data_path)
15
  nltk.data.path.append(nltk_data_path)
16
 
17
  # ๐Ÿ”„ Load tokenizer and model from Hugging Face
18
+ tokenizer = DistilBertTokenizerFast.from_pretrained(
19
+ "distilbert-base-uncased", cache_dir="/tmp/huggingface"
20
+ )
21
+ model = TFDistilBertForSequenceClassification.from_pretrained(
22
+ "sundaram07/distilbert-sentence-classifier", cache_dir="/tmp/huggingface"
23
+ )
24
 
25
  # ๐Ÿ”ฎ Predict AI probability for a sentence
26
  def predict_sentence_ai_probability(sentence):
 
53
  st.title("๐Ÿง  AI Content Detector")
54
  st.markdown("This app detects the percentage of **AI-generated content** based on sentence-level analysis using DistilBERT.")
55
 
56
+ # ๐Ÿ“‹ User Input Area
57
  user_input = st.text_area("๐Ÿ“‹ Paste your text below to check for AI-generated sentences:", height=300)
58
 
59
+ # ๐Ÿ”˜ Analyze Button
60
  if st.button("๐Ÿ” Analyze"):
61
  if not user_input.strip():
62
  st.warning("โš ๏ธ Please enter some text to analyze.")
63
  else:
64
+ # Run analysis
65
  ai_percentage, analysis_results = predict_ai_generated_percentage(user_input)
66
 
67
+ # ๐Ÿ” Sentence-Level Results
68
  st.subheader("๐Ÿ” Sentence-level Analysis")
69
  for i, (sentence, prob, is_ai) in enumerate(analysis_results, start=1):
70
  label = "๐ŸŸข Human" if not is_ai else "๐Ÿ”ด AI"
71
  st.markdown(f"**{i}.** _{sentence}_\n\n โ†’ {label}")
72
 
73
+ # ๐Ÿ“Š Final Result
74
  st.subheader("๐Ÿ“Š Final Result")
75
  st.success(f"Estimated **AI-generated content**: **{ai_percentage:.2f}%**")