Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,18 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoTokenizer, PegasusForConditionalGeneration
|
| 3 |
|
| 4 |
-
# Load
|
| 5 |
tokenizer = AutoTokenizer.from_pretrained('Eemansleepdeprived/Humaneyes')
|
| 6 |
model = PegasusForConditionalGeneration.from_pretrained('Eemansleepdeprived/Humaneyes')
|
| 7 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 8 |
def humanize_text(ai_text):
|
| 9 |
if not ai_text.strip():
|
| 10 |
return "❌ Please enter some text to process."
|
|
|
|
|
|
|
| 11 |
inputs = tokenizer(ai_text, return_tensors="pt")
|
| 12 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 14 |
|
| 15 |
-
# Build a modern
|
| 16 |
with gr.Blocks(theme=gr.themes.Soft(), css=".container {max-width: 700px; margin: auto;}") as demo:
|
| 17 |
gr.Markdown("# ✨ AI to Human Text Converter ✨")
|
| 18 |
gr.Markdown("Convert AI-generated text into natural, human-like text!")
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from transformers import AutoTokenizer, PegasusForConditionalGeneration
|
| 3 |
|
| 4 |
+
# Load 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 |
+
|
| 16 |
+
# Tokenize the input text
|
| 17 |
inputs = tokenizer(ai_text, return_tensors="pt")
|
| 18 |
+
|
| 19 |
+
# Set generation parameters to avoid excessively long sequences
|
| 20 |
+
outputs = model.generate(
|
| 21 |
+
inputs["input_ids"],
|
| 22 |
+
max_length=256,
|
| 23 |
+
num_beams=5,
|
| 24 |
+
early_stopping=True
|
| 25 |
+
)
|
| 26 |
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 27 |
|
| 28 |
+
# Build Gradio UI with a modern layout
|
| 29 |
with gr.Blocks(theme=gr.themes.Soft(), css=".container {max-width: 700px; margin: auto;}") as demo:
|
| 30 |
gr.Markdown("# ✨ AI to Human Text Converter ✨")
|
| 31 |
gr.Markdown("Convert AI-generated text into natural, human-like text!")
|