Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- src/streamlit_app.py +9 -8
src/streamlit_app.py
CHANGED
|
@@ -1,18 +1,18 @@
|
|
| 1 |
-
|
| 2 |
import streamlit as st
|
| 3 |
import tensorflow as tf
|
| 4 |
import numpy as np
|
| 5 |
import re
|
| 6 |
import nltk
|
| 7 |
-
|
| 8 |
-
# Ensure NLTK sentence tokenizer is available
|
| 9 |
-
nltk.download('punkt')
|
| 10 |
from nltk.tokenize import sent_tokenize
|
| 11 |
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
|
|
|
| 15 |
|
|
|
|
|
|
|
| 16 |
|
| 17 |
def predict_sentence_ai_probability(sentence):
|
| 18 |
preds = model.predict([sentence])
|
|
@@ -20,7 +20,7 @@ def predict_sentence_ai_probability(sentence):
|
|
| 20 |
return prob_ai
|
| 21 |
|
| 22 |
def predict_ai_generated_percentage(text, threshold=0.75):
|
| 23 |
-
text
|
| 24 |
sentences = sent_tokenize(text)
|
| 25 |
ai_sentence_count = 0
|
| 26 |
results = []
|
|
@@ -36,6 +36,7 @@ def predict_ai_generated_percentage(text, threshold=0.75):
|
|
| 36 |
ai_percentage = (ai_sentence_count / total_sentences) * 100 if total_sentences > 0 else 0.0
|
| 37 |
return ai_percentage, results
|
| 38 |
|
|
|
|
| 39 |
st.title("🧠 AI Content Detector")
|
| 40 |
st.markdown("This tool detects the percentage of **AI-generated content** in your input text based on sentence-level analysis.")
|
| 41 |
|
|
|
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
import tensorflow as tf
|
| 3 |
import numpy as np
|
| 4 |
import re
|
| 5 |
import nltk
|
| 6 |
+
import os
|
|
|
|
|
|
|
| 7 |
from nltk.tokenize import sent_tokenize
|
| 8 |
|
| 9 |
+
# Use local nltk_data folder (safe for Hugging Face Spaces)
|
| 10 |
+
nltk_data_path = os.path.join(os.path.dirname(__file__), "nltk_data")
|
| 11 |
+
nltk.download("punkt", download_dir=nltk_data_path)
|
| 12 |
+
nltk.data.path.append(nltk_data_path)
|
| 13 |
|
| 14 |
+
# Load model
|
| 15 |
+
model = tf.keras.models.load_model('src/my_distilbert_classifier.keras')
|
| 16 |
|
| 17 |
def predict_sentence_ai_probability(sentence):
|
| 18 |
preds = model.predict([sentence])
|
|
|
|
| 20 |
return prob_ai
|
| 21 |
|
| 22 |
def predict_ai_generated_percentage(text, threshold=0.75):
|
| 23 |
+
text += "."
|
| 24 |
sentences = sent_tokenize(text)
|
| 25 |
ai_sentence_count = 0
|
| 26 |
results = []
|
|
|
|
| 36 |
ai_percentage = (ai_sentence_count / total_sentences) * 100 if total_sentences > 0 else 0.0
|
| 37 |
return ai_percentage, results
|
| 38 |
|
| 39 |
+
# Streamlit UI
|
| 40 |
st.title("🧠 AI Content Detector")
|
| 41 |
st.markdown("This tool detects the percentage of **AI-generated content** in your input text based on sentence-level analysis.")
|
| 42 |
|