Humaira81 commited on
Commit
eefbfb7
·
verified ·
1 Parent(s): 2268a52

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +42 -17
app.py CHANGED
@@ -1,5 +1,10 @@
1
- # Load better paraphraser model
2
- model_name = "Vamsi/T5_Paraphrase_Paws"
 
 
 
 
 
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
- prompt = f"paraphrase: {text} </s>"
11
-
12
- try:
13
- inputs = tokenizer(prompt, return_tensors="pt", truncation=True, max_length=512)
14
- outputs = model.generate(
15
- **inputs,
16
- max_length=256,
17
- num_beams=5,
18
- no_repeat_ngram_size=3,
19
- early_stopping=True
20
- )
21
- refined = tokenizer.decode(outputs[0], skip_special_tokens=True)
22
- return refined.strip(), "✅ Successfully humanized!"
23
- except Exception as e:
24
- return f"⚠️ Error: {str(e)}", "❌ Model error"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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