Spaces:
Runtime error
Runtime error
Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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 |
+
prefix_map = {
|
11 |
+
"Short Summary": "summary to en: ",
|
12 |
+
"Detailed Summary": "summary big to en: ",
|
13 |
+
"Brief Summary": "summary brief to en: "
|
14 |
+
}
|
15 |
+
prefix = prefix_map.get(mode, "summary to en: ")
|
16 |
+
input_text = prefix + email_text
|
17 |
+
|
18 |
+
inputs = tokenizer(input_text, return_tensors="pt", max_length=1024, truncation=True)
|
19 |
+
outputs = model.generate(**inputs, max_new_tokens=200)
|
20 |
+
|
21 |
+
return tokenizer.decode(outputs[0], skip_special_tokens=True)
|
22 |
+
|
23 |
+
demo = gr.Interface(
|
24 |
+
fn=summarize_email,
|
25 |
+
inputs=[
|
26 |
+
gr.Textbox(lines=12, placeholder="Paste your email text here...", label="Email Text"),
|
27 |
+
gr.Radio(["Short Summary", "Detailed Summary", "Brief Summary"], label="Mode", value="Short Summary")
|
28 |
+
],
|
29 |
+
outputs="text",
|
30 |
+
title="Email Summarizer (T5)",
|
31 |
+
description="Paste your email, select summary mode, and get a concise version."
|
32 |
+
)
|
33 |
+
|
34 |
+
if __name__ == "__main__":
|
35 |
+
demo.launch()
|