Spaces:
Sleeping
Sleeping
Update src/streamlit_app.py
Browse files- 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("
|
15 |
nltk.data.path.append(nltk_data_path)
|
16 |
|
17 |
# ๐ Load tokenizer and model from Hugging Face
|
18 |
-
tokenizer = DistilBertTokenizerFast.from_pretrained(
|
19 |
-
|
|
|
|
|
|
|
|
|
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}%**")
|