ritampatra commited on
Commit
052782a
·
verified ·
1 Parent(s): 06495ea

Upload 2 files

Browse files
Files changed (2) hide show
  1. app.py +30 -0
  2. requirements.txt +3 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import T5Tokenizer, T5ForConditionalGeneration
3
+
4
+ # Load model and tokenizer
5
+ model_name = "t5-small"
6
+ tokenizer = T5Tokenizer.from_pretrained(model_name)
7
+ model = T5ForConditionalGeneration.from_pretrained(model_name)
8
+
9
+ # Function to summarize text
10
+ def summarize_text(text, max_length=100):
11
+ input_text = "summarize: " + text
12
+ inputs = tokenizer.encode(input_text, return_tensors="pt", max_length=512, truncation=True)
13
+
14
+ summary_ids = model.generate(inputs, max_length=max_length, min_length=30, length_penalty=2.0, num_beams=4)
15
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
16
+
17
+ return summary
18
+
19
+ # Gradio UI
20
+ iface = gr.Interface(
21
+ fn=summarize_text,
22
+ inputs=[gr.Textbox(label="Enter Text to Summarize"), gr.Slider(50, 200, step=10, label="Max Length")],
23
+ outputs="text",
24
+ title="Text Summarization App",
25
+ description="This app summarizes long texts using the T5 Transformer model.",
26
+ )
27
+
28
+ # Launch the app
29
+ if __name__ == "__main__":
30
+ iface.launch()
requirements.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ torch
3
+ gradio