Nitzz4952 commited on
Commit
2b7c14a
·
verified ·
1 Parent(s): d082bda

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +25 -26
app.py CHANGED
@@ -12,12 +12,8 @@ model_path = "sshleifer/distilbart-cnn-12-6"
12
  text_summary = pipeline("summarization", model=model_path, torch_dtype=torch.bfloat16)
13
  tokenizer = AutoTokenizer.from_pretrained(model_path)
14
 
15
- # Function to process and tokenize text
16
- def tokenize_text(input_text):
17
- return tokenizer.encode(input_text, truncation=False)
18
-
19
  # Function to summarize text
20
- def summarize_text(input_text, min_length=50, max_length=200):
21
  summary_output = text_summary(
22
  input_text,
23
  min_length=min_length,
@@ -25,7 +21,7 @@ def summarize_text(input_text, min_length=50, max_length=200):
25
  )
26
  return summary_output[0]['summary_text']
27
 
28
- # Preload article and summary
29
  article_example = """Niteesh Nigam: A Visionary in Robotics, Machine Vision, and AI
30
 
31
  Niteesh Nigam, a forward-thinking robotics engineer and AI developer, has consistently demonstrated his passion for innovation and his ability to transform complex technological concepts into impactful real-world solutions. With a Master’s degree in Robotics and Autonomous Systems from Arizona State University (ASU) and a Bachelor’s degree in Mechanical Engineering from the Birla Institute of Technology and Science, Pilani Dubai, Niteesh has cultivated a robust foundation in engineering, computer vision, and artificial intelligence. His interdisciplinary expertise and hands-on experience have made him a standout professional in fields such as robotics, machine vision, deep learning, and control systems.
@@ -73,7 +69,7 @@ Niteesh Nigam’s work embodies a perfect blend of technical mastery, innovation
73
  As he looks to the future, Niteesh remains committed to making meaningful contributions in robotics, AI, and automation, with a focus on scalable solutions that benefit industries and communities alike. His journey is a testament to the transformative potential of technology when guided by a visionary like him.
74
  """
75
 
76
- # Precomputed summary
77
  summary_example = summarize_text(article_example, min_length=50, max_length=150)
78
 
79
  # Create Gradio interface
@@ -82,29 +78,32 @@ with gr.Blocks() as demo:
82
  gr.Markdown(
83
  "This app showcases the ability to summarize complex content into concise information. Below is an example:"
84
  )
85
- text_input = gr.Textbox(
86
- label="Input Text",
87
- lines=10,
88
- value=article_example,
89
- interactive=False
90
- )
91
- summary_output = gr.Textbox(
92
- label="Summarized Output",
93
- lines=10,
94
- value=summary_example,
95
- interactive=False
96
- )
97
 
98
- gr.Markdown("## Try It Yourself!")
99
- custom_input = gr.Textbox(label="Input Your Text", lines=10, placeholder="Paste your text here...")
 
 
100
  summarize_button = gr.Button("Summarize")
101
- custom_summary_output = gr.Textbox(label="Summary Output", lines=10)
102
 
103
- # Button action for custom input
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
  summarize_button.click(
105
- summarize_text,
106
- inputs=[custom_input],
107
- outputs=[custom_summary_output]
108
  )
109
 
110
  # Launch the Gradio app
 
12
  text_summary = pipeline("summarization", model=model_path, torch_dtype=torch.bfloat16)
13
  tokenizer = AutoTokenizer.from_pretrained(model_path)
14
 
 
 
 
 
15
  # Function to summarize text
16
+ def summarize_text(input_text, min_length=50, max_length=150):
17
  summary_output = text_summary(
18
  input_text,
19
  min_length=min_length,
 
21
  )
22
  return summary_output[0]['summary_text']
23
 
24
+ # Article Example
25
  article_example = """Niteesh Nigam: A Visionary in Robotics, Machine Vision, and AI
26
 
27
  Niteesh Nigam, a forward-thinking robotics engineer and AI developer, has consistently demonstrated his passion for innovation and his ability to transform complex technological concepts into impactful real-world solutions. With a Master’s degree in Robotics and Autonomous Systems from Arizona State University (ASU) and a Bachelor’s degree in Mechanical Engineering from the Birla Institute of Technology and Science, Pilani Dubai, Niteesh has cultivated a robust foundation in engineering, computer vision, and artificial intelligence. His interdisciplinary expertise and hands-on experience have made him a standout professional in fields such as robotics, machine vision, deep learning, and control systems.
 
69
  As he looks to the future, Niteesh remains committed to making meaningful contributions in robotics, AI, and automation, with a focus on scalable solutions that benefit industries and communities alike. His journey is a testament to the transformative potential of technology when guided by a visionary like him.
70
  """
71
 
72
+ # Precomputed Summary
73
  summary_example = summarize_text(article_example, min_length=50, max_length=150)
74
 
75
  # Create Gradio interface
 
78
  gr.Markdown(
79
  "This app showcases the ability to summarize complex content into concise information. Below is an example:"
80
  )
 
 
 
 
 
 
 
 
 
 
 
 
81
 
82
+ # Input Text
83
+ input_text = gr.Textbox(label="Input Text", lines=10)
84
+
85
+ # Button to Summarize
86
  summarize_button = gr.Button("Summarize")
 
87
 
88
+ # Output Summary
89
+ summary_output = gr.Textbox(label="Summary Output", lines=10)
90
+
91
+ # Add examples using Gradio's example feature
92
+ gr.Examples(
93
+ examples=[
94
+ [article_example], # Input text example
95
+ ],
96
+ inputs=input_text,
97
+ outputs=summary_output,
98
+ fn=summarize_text,
99
+ label="Example: Summarizing a Detailed Article"
100
+ )
101
+
102
+ # Button click to summarize user-provided input
103
  summarize_button.click(
104
+ summarize_text,
105
+ inputs=[input_text],
106
+ outputs=[summary_output]
107
  )
108
 
109
  # Launch the Gradio app