mynkchaudhry commited on
Commit
d736c62
·
verified ·
1 Parent(s): e759989

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -12
app.py CHANGED
@@ -1,23 +1,36 @@
1
- import gradio as gr
2
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
 
3
 
4
- # Load the model and tokenizer
5
  tokenizer = AutoTokenizer.from_pretrained("mynkchaudhry/Summarization-Pro")
6
  model = AutoModelForSeq2SeqLM.from_pretrained("mynkchaudhry/Summarization-Pro")
7
 
8
  def summarize(text):
9
- inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=1024, truncation=True)
10
- summary_ids = model.generate(inputs, max_length=800, min_length=300, length_penalty=2.0, num_beams=4, early_stopping=True)
 
 
 
 
 
 
 
11
  summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
12
  return summary
13
 
14
- # Create a Gradio interface
15
- interface = gr.Interface(theme="NoCrypt/miku",
16
- fn=summarize,
17
- inputs=gr.Textbox(lines=10, label="Input Text"),
18
- outputs=gr.Textbox(label="Summary"),
19
- title="Text Summarization Tool",
20
- description="Enter a long text and get a summarized version of it.")
 
 
 
 
 
 
 
21
 
22
- # Launch the interface
23
  interface.launch()
 
 
1
  from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
2
+ import gradio as gr
3
 
4
+ # Load model and tokenizer
5
  tokenizer = AutoTokenizer.from_pretrained("mynkchaudhry/Summarization-Pro")
6
  model = AutoModelForSeq2SeqLM.from_pretrained("mynkchaudhry/Summarization-Pro")
7
 
8
  def summarize(text):
9
+ inputs = tokenizer(text, return_tensors="pt", max_length=1024, truncation=True)
10
+ summary_ids = model.generate(
11
+ inputs.input_ids,
12
+ max_length=1500, # Increased max_length for longer summaries
13
+ min_length=100, # Ensures summaries are sufficiently long
14
+ length_penalty=0.9, # Encourages longer summaries but balances precision
15
+ num_beams=6, # More beams for better exploration of possible summaries
16
+ early_stopping=True
17
+ )
18
  summary = tokenizer.decode(summary_ids[0], skip_special_tokens=True)
19
  return summary
20
 
21
+ # Gradio interface
22
+ interface = gr.Interface(
23
+ fn=summarize,
24
+ inputs=gr.Textbox(lines=10, label="Input Text"),
25
+ outputs=gr.Textbox(label="Summary"),
26
+ examples=[
27
+ ["The quick brown fox jumps over the lazy dog. This sentence is an English-language pangram—a sentence that contains all the letters of the English alphabet. It is often used for testing typewriters, keyboards, and computer fonts."],
28
+ ["Artificial intelligence (AI) is intelligence demonstrated by machines, in contrast to the natural intelligence displayed by humans and animals. Leading AI textbooks define the field as the study of intelligent agents: any device that perceives its environment and takes actions that maximize its chance of successfully achieving its goals."],
29
+ ["In data science, an anomaly is an observation that deviates significantly from other observations. Anomalies are also known as outliers, novelties, noise, deviations, and exceptions. Anomaly detection finds application in many domains, including fraud detection, network security, and fault detection."]
30
+ ],
31
+ title="Text Summarization",
32
+ description="Generate a summary from the input text using a pre-trained summarization model.",
33
+ theme="freddyaboulton/dracula_revamped" # Ensure this theme exists or use a default theme
34
+ )
35
 
 
36
  interface.launch()