12345deena commited on
Commit
44dde75
·
verified ·
1 Parent(s): 70075a0

Updated app.py

Browse files
Files changed (1) hide show
  1. app.py +27 -1
app.py CHANGED
@@ -1,3 +1,29 @@
 
1
  import gradio as gr
 
2
 
3
- gr.load("models/12345deena/t5-small-ilct5").launch()
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Load model directly
2
  import gradio as gr
3
+ from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
4
 
5
+ tokenizer = AutoTokenizer.from_pretrained("12345deena/t5-small-ilct5")
6
+ model = AutoModelForSeq2SeqLM.from_pretrained("12345deena/t5-small-ilct5")
7
+
8
+ def summarize(text):
9
+ # Tokenize input text
10
+ inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=512, truncation=True)
11
+
12
+ # Generate summary
13
+ summary_ids = model.generate(inputs, max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
14
+
15
+ # Decode the summary
16
+ summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
17
+ return summary
18
+
19
+ # Create Gradio interface
20
+ iface = gr.Interface(
21
+ fn=summarize,
22
+ inputs="text",
23
+ outputs="text",
24
+ title="Abstractive Text Summarization",
25
+ description="Enter a piece of text to summarize it."
26
+ )
27
+
28
+ # Launch the interface on port 8888
29
+ iface.launch()