VictorM-Coder commited on
Commit
105c7d1
·
verified ·
1 Parent(s): ecfe685

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import torch
3
+ from transformers import AutoModelForCausalLM, AutoTokenizer, TextIteratorStreamer
4
+ from threading import Thread
5
+ import spaces
6
+
7
+ # Model configuration
8
+ MODEL_ID = "Qwen/Qwen3-8B-Instruct" # Replace with specific adversarial repo if different
9
+ tokenizer = AutoTokenizer.from_pretrained(MODEL_ID)
10
+ model = AutoModelForCausalLM.from_pretrained(
11
+ MODEL_ID,
12
+ torch_dtype=torch.float16,
13
+ device_map="auto",
14
+ )
15
+
16
+ @spaces.GPU(duration=60)
17
+ def humanize_text(text, intensity):
18
+ # Constructing the adversarial prompt
19
+ prompt = f"Rewrite the following text to be highly human-like, varying sentence structure and avoiding common AI patterns. Maintain the original meaning perfectly.\n\nIntensity: {intensity}/10\nText: {text}\n\nHumanized Output:"
20
+
21
+ inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
22
+ streamer = TextIteratorStreamer(tokenizer, skip_prompt=True, skip_special_tokens=True)
23
+
24
+ generation_kwargs = dict(
25
+ inputs,
26
+ streamer=streamer,
27
+ max_new_tokens=1024,
28
+ do_sample=True,
29
+ temperature=0.7 + (intensity * 0.05), # Higher intensity = more randomness
30
+ top_p=0.95,
31
+ )
32
+
33
+ thread = Thread(target=model.generate, kwargs=generation_kwargs)
34
+ thread.start()
35
+
36
+ output_text = ""
37
+ for new_text in streamer:
38
+ output_text += new_text
39
+ yield output_text
40
+
41
+ # Gradio Interface
42
+ with gr.Blocks(theme=gr.themes.Soft()) as demo:
43
+ gr.Markdown("# 🤖 Adversarial Humanizer (Qwen3-8B)")
44
+ gr.Markdown("Transform AI-generated text into human-like prose to bypass detection.")
45
+
46
+ with gr.Row():
47
+ with gr.Column():
48
+ input_box = gr.Textbox(label="Input Text", lines=8, placeholder="Paste AI content here...")
49
+ intensity_slider = gr.Slider(minimum=1, maximum=10, value=5, step=1, label="Humanization Intensity")
50
+ submit_btn = gr.Button("Humanize", variant="primary")
51
+
52
+ with gr.Column():
53
+ output_box = gr.Textbox(label="Humanized Result", lines=10, interactive=False)
54
+
55
+ submit_btn.click(
56
+ fn=humanize_text,
57
+ inputs=[input_box, intensity_slider],
58
+ outputs=output_box
59
+ )
60
+
61
+ demo.launch()