Spaces:
Sleeping
Sleeping
Upload 2 files
Browse files- app.py +61 -0
- requirements.txt +4 -0
app.py
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import pipeline
|
| 3 |
+
from sentence_transformers import SentenceTransformer, util
|
| 4 |
+
import random
|
| 5 |
+
|
| 6 |
+
# Load models
|
| 7 |
+
paraphraser = pipeline("text2text-generation", model="Vamsi/T5_Paraphrase_Paws")
|
| 8 |
+
similarity_model = SentenceTransformer('all-MiniLM-L6-v2')
|
| 9 |
+
|
| 10 |
+
# Tone modifier prompts
|
| 11 |
+
tone_prompts = {
|
| 12 |
+
"Academic": "Rewrite this in a scholarly and formal way:",
|
| 13 |
+
"Casual": "Rewrite this casually like a real student would talk:",
|
| 14 |
+
"Friendly": "Make this sound friendly and human-like:",
|
| 15 |
+
"Stealth (AI Detection Bypass)": "Paraphrase to avoid sounding like AI-generated content:"
|
| 16 |
+
}
|
| 17 |
+
|
| 18 |
+
def humanize_text(input_text, tone):
|
| 19 |
+
if not input_text.strip():
|
| 20 |
+
return "Please enter some text.", "", ""
|
| 21 |
+
|
| 22 |
+
style_prompt = tone_prompts.get(tone, "Paraphrase:")
|
| 23 |
+
result = paraphraser(f"{style_prompt} {input_text}", max_length=80, num_return_sequences=1)
|
| 24 |
+
output_text = result[0]['generated_text']
|
| 25 |
+
|
| 26 |
+
# Semantic similarity score
|
| 27 |
+
emb1 = similarity_model.encode(input_text, convert_to_tensor=True)
|
| 28 |
+
emb2 = similarity_model.encode(output_text, convert_to_tensor=True)
|
| 29 |
+
similarity_score = util.pytorch_cos_sim(emb1, emb2).item()
|
| 30 |
+
|
| 31 |
+
score_description = "✔️ Humanized (Safe)" if similarity_score < 0.92 else "⚠️ Still Close to AI Tone"
|
| 32 |
+
|
| 33 |
+
return output_text, f"{similarity_score:.2f}", score_description
|
| 34 |
+
|
| 35 |
+
# Gradio Interface
|
| 36 |
+
with gr.Blocks(theme=gr.themes.Base(primary_hue="blue", secondary_hue="blue")) as demo:
|
| 37 |
+
gr.Markdown("""
|
| 38 |
+
<h1 style='text-align: center; color: #0f172a;'>🧠 Taha's AI Humanizer Tool</h1>
|
| 39 |
+
<p style='text-align: center; color: #334155;'>Rewriting AI-generated text to sound real, authentic, and undetectable — made by Taha.</p>
|
| 40 |
+
""")
|
| 41 |
+
|
| 42 |
+
with gr.Row():
|
| 43 |
+
input_text = gr.Textbox(lines=6, label="🔤 Enter Your AI-Sounding Text")
|
| 44 |
+
output_text = gr.Textbox(lines=6, label="✅ Humanized Output")
|
| 45 |
+
|
| 46 |
+
tone = gr.Radio(["Academic", "Casual", "Friendly", "Stealth (AI Detection Bypass)"], label="🎯 Select Tone", value="Stealth (AI Detection Bypass)")
|
| 47 |
+
|
| 48 |
+
with gr.Row():
|
| 49 |
+
similarity = gr.Textbox(label="🔍 Semantic Similarity Score")
|
| 50 |
+
score_label = gr.Textbox(label="🧠 Humanization Check")
|
| 51 |
+
|
| 52 |
+
btn = gr.Button("🚀 Humanize It")
|
| 53 |
+
|
| 54 |
+
btn.click(fn=humanize_text, inputs=[input_text, tone], outputs=[output_text, similarity, score_label])
|
| 55 |
+
|
| 56 |
+
gr.Markdown("""
|
| 57 |
+
<hr>
|
| 58 |
+
<p style='text-align: center; font-size: 14px; color: #64748b;'>✨ Created with love by <strong>Taha</strong> — helping students stay original.</p>
|
| 59 |
+
""")
|
| 60 |
+
|
| 61 |
+
demo.launch()
|
requirements.txt
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
gradio
|
| 2 |
+
transformers
|
| 3 |
+
sentence-transformers
|
| 4 |
+
torch
|