Javedalam commited on
Commit
fbddca2
·
verified ·
1 Parent(s): 9dd4939

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -22
app.py CHANGED
@@ -1,28 +1,21 @@
1
- # Step 2: Install the latest version of Gradio
2
- #!pip install gradio
3
-
4
- # Step 3: Verify the installation
5
  import gradio as gr
 
6
 
7
- print("Gradio version:", gr.__version__)
8
-
9
- # Step 4: Define the Gradio interface using the latest API
10
- from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
11
 
12
  def summarize(text):
13
- tokenizer = AutoTokenizer.from_pretrained("facebook/bart-large-cnn")
14
- model = AutoModelForSeq2SeqLM.from_pretrained("facebook/bart-large-cnn")
15
- inputs = tokenizer.encode("summarize: " + text, return_tensors="pt", max_length=1024, truncation=True)
16
- summary_ids = model.generate(inputs, max_length=150, min_length=40, length_penalty=2.0, num_beams=4, early_stopping=True)
17
- return tokenizer.decode(summary_ids[0], skip_special_tokens=True)
18
-
19
- iface1 = gr.Interface(fn=summarize, inputs="textbox", outputs="textbox", title="Text Summarizer")
20
- iface2 = gr.Interface(fn=summarize, inputs="textbox", outputs="textbox", title="Text Summarizer")
21
 
22
- # Combine interfaces using the latest Gradio Blocks API
23
- with gr.Blocks() as demo:
24
- with gr.Row():
25
- iface1.render()
26
-
 
 
 
27
 
28
- demo.launch()
 
 
 
 
 
 
1
  import gradio as gr
2
+ from transformers import pipeline
3
 
4
+ # Step 3: Define the summarization function
5
+ summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
 
 
6
 
7
  def summarize(text):
8
+ summary = summarizer(text, max_length=150, min_length=40, do_sample=False)
9
+ return summary[0]['summary_text']
 
 
 
 
 
 
10
 
11
+ # Step 4: Create the Gradio interface
12
+ iface = gr.Interface(
13
+ fn=summarize,
14
+ inputs="textbox",
15
+ outputs="textbox",
16
+ title="Text Summarizer",
17
+ description="Summarize text using the facebook/bart-large-cnn model from Hugging Face"
18
+ )
19
 
20
+ # Step 5: Launch the interface
21
+ iface.launch()