Kabeer Akande commited on
Commit
39fb067
1 Parent(s): 82a1bb6

adds summariser script

Browse files
Files changed (4) hide show
  1. app.py +37 -0
  2. poetry.lock +0 -0
  3. pyproject.toml +17 -0
  4. requirement.txt +3 -0
app.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import gradio as gr
2
+ from transformers import pipeline
3
+
4
+ def summarize_text(input_text):
5
+ """
6
+ Function to summarize the input text using a Hugging Face transformers pipeline.
7
+
8
+ Args:
9
+ input_text (str): Text to be summarized.
10
+
11
+ Returns:
12
+ str: Summarized text.
13
+ """
14
+ # Load the summarization pipeline using a specific model from Hugging Face
15
+ summarizer = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")
16
+ # Summarize the text
17
+ summary = summarizer(input_text, max_length=130, min_length=30, do_sample=False)
18
+ # Extract and return the summarized text
19
+ return summary[0]['summary_text']
20
+
21
+ def main():
22
+ """
23
+ Main function to launch the Gradio interface.
24
+ """
25
+ # Define the Gradio interface
26
+ interface = gr.Interface(
27
+ fn=summarize_text,
28
+ inputs=gr.Textbox(lines=10, placeholder="Enter text here to summarize..."),
29
+ outputs="text",
30
+ title="Text Summarizer",
31
+ description="A simple text summarization app using Hugging Face's transformers. Enter your text and get a summarized version instantly!"
32
+ )
33
+ # Launch the app
34
+ interface.launch()
35
+
36
+ if __name__ == "__main__":
37
+ main()
poetry.lock ADDED
The diff for this file is too large to render. See raw diff
 
pyproject.toml ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ [tool.poetry]
2
+ name = "summarization"
3
+ version = "0.1.0"
4
+ description = ""
5
+ authors = ["Kabeer Akande <46060542+kbakande@users.noreply.github.com>"]
6
+ readme = "README.md"
7
+
8
+ [tool.poetry.dependencies]
9
+ python = "^3.11"
10
+ transformers = "^4.40.2"
11
+ gradio = "^4.31.0"
12
+ torch = "^2.3.0"
13
+
14
+
15
+ [build-system]
16
+ requires = ["poetry-core"]
17
+ build-backend = "poetry.core.masonry.api"
requirement.txt ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ transformers
2
+ gradio
3
+ torch