Nishant0803 commited on
Commit
cea5dbc
·
verified ·
1 Parent(s): b30a3dd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import T5ForConditionalGeneration, T5Tokenizer
3
+
4
+ # Load model & tokenizer once
5
+ model_name = "utrobinmv/t5_summary_en_ru_zh_base_2048"
6
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
7
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
8
+
9
+ def summarize_email(email_text, mode):
10
+ """
11
+ Summarizes the given email text using the selected mode.
12
+ """
13
+ prefix_map = {
14
+ "Short Summary": "summary to en: ",
15
+ "Detailed Summary": "summary big to en: ",
16
+ "Brief Summary": "summary brief to en: "
17
+ }
18
+ prefix = prefix_map.get(mode, "summary to en: ")
19
+ input_text = prefix + email_text
20
+
21
+ inputs = tokenizer(input_text, return_tensors="pt", max_length=1024, truncation=True)
22
+ outputs = model.generate(**inputs, max_new_tokens=200)
23
+
24
+ return tokenizer.decode(outputs[0], skip_special_tokens=True)
25
+
26
+ # Gradio UI
27
+ demo = gr.Interface(
28
+ fn=summarize_email,
29
+ inputs=[
30
+ gr.Textbox(lines=12, placeholder="Paste your email text here...", label="Email Text"),
31
+ gr.Radio(["Short Summary", "Detailed Summary", "Brief Summary"], label="Mode", value="Short Summary")
32
+ ],
33
+ outputs="text",
34
+ title="Email Summarizer (T5)",
35
+ description="Paste your email, select summary mode, and get a concise version."
36
+ )
37
+
38
+ if __name__ == "__main__":
39
+ demo.launch()