Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,10 @@
|
|
| 1 |
-
|
| 2 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 4 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 5 |
|
|
@@ -7,20 +12,40 @@ def humanize_text(text, tone):
|
|
| 7 |
if not text.strip():
|
| 8 |
return "⚠️ Please enter text.", "❌ Empty input"
|
| 9 |
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
|
|
|
|
|
|
| 26 |
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
| 3 |
+
import torch
|
| 4 |
+
|
| 5 |
+
# Choose a model: try "google/flan-t5-base" or "Vamsi/T5_Paraphrase_Paws"
|
| 6 |
+
model_name = "google/flan-t5-base"
|
| 7 |
+
|
| 8 |
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 9 |
model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
| 10 |
|
|
|
|
| 12 |
if not text.strip():
|
| 13 |
return "⚠️ Please enter text.", "❌ Empty input"
|
| 14 |
|
| 15 |
+
# Create better prompts for FLAN-T5
|
| 16 |
+
prefix = {
|
| 17 |
+
"Academic": "Rewrite the following text in a scholarly academic tone:",
|
| 18 |
+
"Professional": "Rephrase the following text in a formal and professional style:",
|
| 19 |
+
"Conversational": "Rewrite the following text in a friendly, conversational tone:"
|
| 20 |
+
}[tone]
|
| 21 |
+
|
| 22 |
+
prompt = f"{prefix} {text}"
|
| 23 |
+
|
| 24 |
+
inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512)
|
| 25 |
+
outputs = model.generate(
|
| 26 |
+
**inputs,
|
| 27 |
+
max_length=256,
|
| 28 |
+
num_beams=5,
|
| 29 |
+
no_repeat_ngram_size=3,
|
| 30 |
+
early_stopping=True
|
| 31 |
+
)
|
| 32 |
+
refined = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 33 |
+
return refined.strip(), "✅ Successfully humanized!"
|
| 34 |
+
|
| 35 |
+
iface = gr.Interface(
|
| 36 |
+
fn=humanize_text,
|
| 37 |
+
inputs=[
|
| 38 |
+
gr.Textbox(lines=8, label="✍️ Enter your text"),
|
| 39 |
+
gr.Radio(["Academic", "Professional", "Conversational"], label="Tone", value="Academic")
|
| 40 |
+
],
|
| 41 |
+
outputs=[
|
| 42 |
+
gr.Textbox(lines=10, label="🧠 Refined Academic Rewrite"),
|
| 43 |
+
gr.Textbox(label="System Status")
|
| 44 |
+
],
|
| 45 |
+
title="🕌 Zawiyah AI Collective – Attention-Based Humanizer AI",
|
| 46 |
+
description="Transforms ordinary text into refined, academic, or professional language using a T5 transformer model."
|
| 47 |
+
)
|
| 48 |
|
| 49 |
+
if __name__ == "__main__":
|
| 50 |
+
iface.launch()
|
| 51 |
|