varshap03 commited on
Commit
137494b
·
verified ·
1 Parent(s): 349d44e

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +49 -0
  2. requirements.txt +5 -0
app.py ADDED
@@ -0,0 +1,49 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+
2
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM, pipeline
3
+ import gradio as gr
4
+
5
+ model_name = "ramsrigouthamg/t5_paraphraser"
6
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
7
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
8
+ paraphraser = pipeline("text2text-generation", model=model, tokenizer=tokenizer)
9
+
10
+ def rewrite_text(text, style):
11
+ if not text.strip():
12
+ return "Please enter some text."
13
+
14
+ if style == "Gen Z":
15
+ prompt = f"Rewrite the following text in a funny Gen Z tone with slang, emojis, and internet expressions:\n\n{text}"
16
+ elif style == "Poetic":
17
+ prompt = f"Rewrite the following text in a poetic and artistic style:\n\n{text}"
18
+ elif style == "Formal":
19
+ prompt = f"Rewrite the following text in a formal, professional tone:\n\n{text}"
20
+ elif style == "Friendly":
21
+ prompt = f"Rewrite the following text in a friendly and conversational style:\n\n{text}"
22
+ else:
23
+ prompt = f"Rewrite the following text:\n\n{text}"
24
+
25
+ response = paraphraser(prompt, max_length=100)[0]['generated_text']
26
+ return response.replace(prompt, "").strip()
27
+
28
+ with gr.Blocks(theme=gr.themes.Monochrome()) as demo:
29
+ gr.Markdown(
30
+ """
31
+ <h1 style="text-align: center;">📝 Rewrite My Text</h1>
32
+ <p style="text-align: center;">Transform your text into <b>fun, formal, poetic, or Gen Z</b> styles using AI! 🚀</p>
33
+ """,
34
+ )
35
+
36
+ with gr.Row():
37
+ with gr.Column():
38
+ input_text = gr.Textbox(label="Input Text", placeholder="Enter your sentence here...", lines=4)
39
+ style = gr.Dropdown(label="Choose Style", choices=["Gen Z", "Formal", "Poetic", "Friendly"], value="Gen Z")
40
+ submit_button = gr.Button("✨ Submit")
41
+ clear_button = gr.Button("🧹 Clear")
42
+
43
+ with gr.Column():
44
+ output_text = gr.Textbox(label="Rewritten Text", placeholder="Your rewritten sentence will appear here...", lines=4)
45
+
46
+ submit_button.click(fn=rewrite_text, inputs=[input_text, style], outputs=output_text)
47
+ clear_button.click(fn=lambda: ("", ""), inputs=[], outputs=[input_text, output_text])
48
+
49
+ demo.launch()
requirements.txt ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+
2
+ transformers
3
+ gradio
4
+ torch
5
+ sentencepiece