Usmanmarketer commited on
Commit
c30c5ac
·
verified ·
1 Parent(s): 6179b1f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +51 -0
app.py ADDED
@@ -0,0 +1,51 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import AutoTokenizer, PegasusForConditionalGeneration
3
+
4
+ # Load the Humaneyes model from Hugging Face
5
+ tokenizer = AutoTokenizer.from_pretrained("Eemansleepdeprived/Humaneyes")
6
+ model = PegasusForConditionalGeneration.from_pretrained("Eemansleepdeprived/Humaneyes")
7
+
8
+ # Ensure the model has a pad_token_id (use eos_token_id if missing)
9
+ if model.config.pad_token_id is None:
10
+ model.config.pad_token_id = tokenizer.eos_token_id
11
+
12
+ def humanize_text(ai_text):
13
+ if not ai_text.strip():
14
+ return "❌ Please enter some text to process."
15
+ # Tokenize the input text
16
+ inputs = tokenizer(ai_text, return_tensors="pt")
17
+ # Generate human-like text with controlled parameters
18
+ outputs = model.generate(
19
+ inputs["input_ids"],
20
+ max_length=256,
21
+ num_beams=5,
22
+ early_stopping=True
23
+ )
24
+ # Decode and return the generated text
25
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
26
+
27
+ # Build a modern Gradio UI
28
+ with gr.Blocks(theme=gr.themes.Soft(), css=".container {max-width: 700px; margin: auto;}") as demo:
29
+ gr.Markdown("# ✨ AI to Human Text Converter ✨")
30
+ gr.Markdown("Convert AI-generated text into natural, human-like text!")
31
+
32
+ with gr.Row():
33
+ ai_input = gr.Textbox(
34
+ label="Enter AI Text",
35
+ placeholder="Type or paste AI-generated text here...",
36
+ lines=7
37
+ )
38
+
39
+ btn = gr.Button("🚀 Humanize Text", variant="primary")
40
+
41
+ with gr.Row():
42
+ human_output = gr.Textbox(
43
+ label="Humanized Output",
44
+ interactive=False,
45
+ lines=7
46
+ )
47
+
48
+ btn.click(humanize_text, inputs=ai_input, outputs=human_output)
49
+
50
+ if __name__ == "__main__":
51
+ demo.launch()