dcolish commited on
Commit
f6ab87f
·
1 Parent(s): 157565e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -0
app.py ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ import transformers
3
+
4
+ model_name = "t5-small"
5
+ tokenizer = transformers.T5Tokenizer.from_pretrained(model_name)
6
+ model = transformers.T5ForCausalLM.from_pretrained(model_name)
7
+
8
+ def summarize_text(text, max_length):
9
+ input_ids = tokenizer.encode(text, return_tensors='pt', max_length=512)
10
+ summary_ids = model.generate(input_ids,
11
+ max_length=max_length,
12
+ num_beams=4,
13
+ early_stopping=True)
14
+ return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
15
+
16
+ iface = gr.Interface(
17
+ fn=summarize_text,
18
+ inputs=gr.inputs.Textbox(lines=5, default="Enter your text here"),
19
+ outputs=gr.outputs.Textbox(lines=3, default="Summary will appear here"),
20
+ parameters={
21
+ "max_length": gr.inputs.Slider(default=50, min_value=20, max_value=200, step=10, label="Summary Length")
22
+ },
23
+ title="Text Summarization with T5",
24
+ description="Generate a brief summary of the input text using the T5 model."
25
+ )
26
+
27
+ iface.launch()