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

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -19
app.py CHANGED
@@ -1,59 +1,65 @@
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)
 
1
  from transformers import pipeline
2
  import gradio as gr
3
 
4
+ # Load the summarization model from Hugging Face
5
  summarizer = pipeline("summarization", model="facebook/bart-large-cnn")
6
 
7
+ # Define what the app does when someone enters text
8
  def summarize_text(text):
9
  if not text.strip():
10
+ return "⚠️ Oops! Looks like you forgot to enter some text."
11
  summary = summarizer(text, max_length=130, min_length=30, do_sample=False)[0]['summary_text']
12
  return summary
13
 
14
+ # Friendly title and helpful description
15
+ title = "πŸ“˜ Smart Text Summarizer"
16
  description = """
17
+ Tired of reading long paragraphs? Paste any article, essay, or block of text here,
18
+ and this tool will give you a clear, to-the-point summary using AI.
19
+ Great for studying, writing, or just saving time!
20
  """
21
 
22
+ # Some examples to help users get started
23
  examples = [
24
+ ["India is known for its cultural diversity, historical landmarks, and varied geography..."],
25
+ ["Climate change continues to impact our planet, causing rising temperatures and extreme weather events..."],
26
+ ["Artificial Intelligence has evolved over decades, starting from simple rule-based systems to powerful models like GPT..."]
27
  ]
28
 
29
+ # Build the interface
30
+ with gr.Blocks(css=".gradio-container {background-color: #f0f4f8;} textarea {font-size: 16px;}") as demo:
31
  gr.Markdown(f"# {title}")
32
  gr.Markdown(description)
33
 
34
  with gr.Row():
35
  with gr.Column():
36
  input_text = gr.Textbox(
37
+ label="✍️ Paste your text here",
38
+ placeholder="Drop in an article, essay, or book paragraph...",
39
+ lines=14,
40
  show_copy_button=True
41
  )
42
+ submit_btn = gr.Button("πŸͺ„ Summarize it!", variant="primary")
43
  with gr.Column():
44
  output = gr.Textbox(
45
+ label="βœ… Here's your summary",
46
  lines=12,
47
+ interactive=False,
48
+ show_copy_button=True
49
  )
50
 
51
+ # Button action
52
  submit_btn.click(fn=summarize_text, inputs=input_text, outputs=output)
53
 
54
+ # Example use cases
55
  gr.Examples(
56
  examples=examples,
57
  inputs=input_text,
58
  outputs=output,
59
  fn=summarize_text,
60
+ label="πŸ” Try one of these examples"
61
  )
62
 
63
+ # Run the app
64
  if __name__ == "__main__":
65
  demo.launch(server_name="0.0.0.0", server_port=7860)