File size: 1,513 Bytes
9ac4279
e8fb8fd
9ac4279
 
 
 
 
 
e8fb8fd
9ac4279
 
 
 
787875d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9ac4279
787875d
9ac4279
787875d
 
 
 
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
---
title: Grounding Snippet Generator
emoji: 🚀
colorFrom: red
colorTo: red
sdk: docker
app_port: 8501
tags:
- streamlit
pinned: false
short_description: Streamlit template space
---

---
title: Snippet Generator
emoji: ✂️
colorFrom: blue
colorTo: purple
sdk: streamlit
sdk_version: 1.28.0
app_file: app.py
pinned: false
license: mit
---

# ✂️ Snippet Generator

Recreates Google Vertex AI / Gemini grounding-style extractive snippets.

## How it works

1. **Sentence Segmentation** - Splits document on sentence boundaries and newlines, filters noise (URLs, questions, low-alpha content)
2. **Cross-Encoder Scoring** - Uses `cross-encoder/ms-marco-electra-base` to score query-sentence relevance
3. **Budget Selection** - Picks top-scoring sentences within character/count limits
4. **Document-Order Stitching** - Reassembles in original order with `...` for gaps

## Model

Uses [MS MARCO Cross-Encoder](https://huggingface.co/cross-encoder/ms-marco-electra-base) trained on search relevance data - the same task as snippet generation.

## Usage

1. Enter a search query
2. Paste document content
3. Adjust settings (max chars, max sentences)
4. Click "Generate Snippet"

## Example

**Query:** `best prostate cancer treatment in the world`

**Output:**
```
This makes Asklepios one of the best prostate cancer treatment centers for foreigners. ... Spain is a leader in prostate cancer treatment, with top clinics like Centro Médico Teknon, Quironsalud Madrid, and Hospital Quiron Barcelona. ...
```