Uwaish commited on
Commit
538f034
Β·
verified Β·
1 Parent(s): 1a7f224

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -12
app.py CHANGED
@@ -1,24 +1,59 @@
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
- # Initialize summarization pipeline
5
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
6
 
7
- # Function to summarize input
8
  def summarize_text(text):
9
  if not text.strip():
10
- return "⚠️ Please enter some text."
11
  summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
12
  return summary
13
 
14
- # Gradio Interface
15
- iface = gr.Interface(
16
- fn=summarize_text,
17
- inputs=gr.Textbox(lines=15, placeholder="Paste article, essay, or book paragraph here..."),
18
- outputs="text",
19
- title="πŸ“˜ AI Text Summarizer",
20
- description="Summarizes text using Hugging Face's facebook/bart-large-cnn model."
21
- )
22
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
23
  if __name__ == "__main__":
24
- iface.launch(server_name="0.0.0.0", server_port=7860)
 
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
+ # Load summarization pipeline
5
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
6
 
7
+ # Summarization function
8
  def summarize_text(text):
9
  if not text.strip():
10
+ return "⚠️ Please enter some text to summarize."
11
  summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
12
  return summary
13
 
14
+ # Interface components
15
+ title = "πŸ“˜ AI Text Summarizer"
16
+ description = """
17
+ This AI-powered tool summarizes articles, essays, or documents using Facebook's BART Large CNN model.
18
+ Just paste your content, and let the AI do the rest!
19
+ """
 
 
20
 
21
+ examples = [
22
+ ["India is a country with a rich cultural heritage..."],
23
+ ["Climate change is one of the biggest challenges faced globally..."],
24
+ ["The history of computing began in the early 20th century..."]
25
+ ]
26
+
27
+ with gr.Blocks(css=".gradio-container {background-color: #f8f9fa;} textarea {font-size: 16px;}") as demo:
28
+ gr.Markdown(f"# {title}")
29
+ gr.Markdown(description)
30
+
31
+ with gr.Row():
32
+ with gr.Column():
33
+ input_text = gr.Textbox(
34
+ label="πŸ“ Input Text",
35
+ placeholder="Paste your article, paragraph, or essay here...",
36
+ lines=15,
37
+ show_copy_button=True
38
+ )
39
+ submit_btn = gr.Button("✨ Summarize Now", variant="primary")
40
+ with gr.Column():
41
+ output = gr.Textbox(
42
+ label="πŸ“„ Summary Output",
43
+ lines=12,
44
+ interactive=False
45
+ )
46
+
47
+ submit_btn.click(fn=summarize_text, inputs=input_text, outputs=output)
48
+
49
+ gr.Examples(
50
+ examples=examples,
51
+ inputs=input_text,
52
+ outputs=output,
53
+ fn=summarize_text,
54
+ label="πŸ“Œ Try with Examples"
55
+ )
56
+
57
+ # Launch app
58
  if __name__ == "__main__":
59
+ demo.launch(server_name="0.0.0.0", server_port=7860)