File size: 3,012 Bytes
1dcb483
 
 
 
 
 
 
 
 
 
 
 
88390ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b6d6235
88390ff
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1dcb483
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
---
title: Text Pdf Summarizer Ui
emoji: 🐠
colorFrom: blue
colorTo: gray
sdk: gradio
sdk_version: 5.29.0
app_file: app.py
pinned: false
license: mit
short_description: πŸ“ Text & PDF Summarizer UI
---
# πŸ“ Text & PDF Summarizer UI

A lightweight web application that allows users to paste text or upload a PDF document, then summarizes the content using a HuggingFace transformer model integrated with LangChain and displayed via a Gradio interface.

## πŸš€ Key Features

- Input text manually or via PDF upload
- Extracts and summarizes PDF text using NLP
- User-friendly Gradio interface
- Uses pre-trained `facebook/bart-large-cnn` summarization model

## πŸ—οΈ Project Architecture

- **Gradio**: Frontend interface to interact with the app
- **PyPDF2**: Extracts text from PDF files
- **LangChain**: Framework for managing LLM-based workflows
- **HuggingFace**: Provides transformer models like BART for summarization

## πŸ”§ Getting Started

**1- Clone the repo**
   ```bash
   git clone https://github.com/rahimizadeh/text-pdf-summarizer-ui.git
   cd text-pdf-summarizer-ui
 ```

   πŸ“**Project Structure**  

      β”œβ”€β”€ text-pdf-summarizer-ui/  
            β”œβ”€β”€ app.py      # Application  
            β””── requirements.txt               
            β””── README.md

**2- Create a virtual environment (optional)**
   ``` python -m venv venv
   source venv/bin/activate  # On Windows: venv\\Scripts\\activate
 ```

**3- Install dependencies**

```bash
pip install -r requirements.txt
 ```

**4- Run the app**
```bash
python app.py
```


## 🧠 About the Tools

    **LangChain**: provides a modular framework for building applications with language models. Here, it's used to manage prompting and model output formatting.

    **HuggingFace Transformers**: We use the facebook/bart-large-cnn model, a powerful encoder-decoder model ideal for summarization.

    **Gradio**: lets us quickly build and share user-friendly web interfaces for Machine Learning apps.


## πŸ” Implementation Details

      1- Model Initialization: Using HuggingFacePipeline via LangChain
   
     2- PromptTemplate: Wraps text for inference
   
     3- PDF Handling: Reads uploaded file as bytes and extracts text using PyPDF2
   
     4- UI Logic: Built with Gradio Blocks to control layout, input, and output


## βœ… Example Usage
   - Upload a PDF or paste article text
   - Cick β€œConvert PDF to Text” (if PDF)- 
   - Click β€œSummarize Text”
   - View summary below the input

## πŸ“ License
    MIT

##  🀝 Contributions
    Pull requests and suggestions welcome!

Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference