File size: 3,499 Bytes
760c69b
 
 
 
 
066b132
760c69b
 
 
 
632def0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
bb2ac09
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3cd1290
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
---
title: LLMSearchEngine
emoji: 🏆
colorFrom: gray
colorTo: purple
sdk: docker
app_file: app.py
pinned: false
---

# LLM Search Engine

This is a Flask-based web application that uses a large language model (LLM) to generate search engine-like results, styled to resemble Google’s classic search results page. Instead of querying an external search API, it prompts an LLM to create titles, snippets, and URLs for a given query, delivering a paginated, familiar interface.

## Why We Built It

We created this app to explore how LLMs can mimic traditional search engines by generating results directly from their training data. It offers:
- A nostalgic, Google-like pagination design with clickable links.
- A proof-of-concept for LLM-driven search without real-time web access.
- A simple, self-contained alternative for queries within the model’s knowledge base.

## Features
- **Google-Styled Interface**: Search bar, result list, and pagination styled with Google’s colors and layout.
- **Generated Results**: Titles, snippets, and URLs are fully produced by the LLM.
- **Pagination**: Displays 10 results per page, up to 30 total results across 3 pages.

## Limitations
- **Static Knowledge**: Results are limited to the LLM’s training cutoff (e.g., pre-2025).
- **Generated Content**: URLs and snippets may not correspond to real web pages—use as a starting point.
- **No Real-Time Data**: Best for historical or established topics, not breaking news.

## Using It on Hugging Face Spaces

### Try the Demo
Deployed on Hugging Face Spaces, you can test it at [https://codelion-llmsearchengine.hf.space](https://codelion-llmsearchengine.hf.space):
1. Open the URL in your browser.
2. Type a query (e.g. "best Python libraries") in the search bar and press Enter or click "LLM Search".
3. Browse the paginated results, styled like Google, using "Previous" and "Next" links.

## Using It as an API

### API Endpoint

Your app doubles as an API when hosted on HF Spaces:

- **URL:** `https://codelion-llmsearchengine.hf.space/`
- **Method:** `GET`
- **Parameters:**
  - `query`: The search query (e.g., `"best Python libraries"`).
  - `page`: Page number (`1-3`, defaults to `1`).

### Example Request

```bash
curl "https://codelion-llmsearchengine.hf.space/?query=best+Python+libraries&page=1"
```

### Response

Returns **raw HTML** styled like a Google search results page.

---

## Integration

You can fetch results programmatically and render or parse the HTML:

```python
import requests
from urllib.parse import quote

query = "best Python libraries"
page = 1
url = f"https://codelion-llmsearchengine.hf.space/?query={quote(query)}&page={page}"
response = requests.get(url)
html_content = response.text  # Render or process as needed
print(html_content)
```

---

## How It Works

1. **LLM Prompting**  
   - Queries trigger a prompt to the `"gemini-2.0-flash-lite"` model.  
   - Generates **30 results** in JSON format.

2. **Rendering**  
   - Flask converts results into a **Google-styled** HTML page.  
   - Includes a **search bar, results, and pagination**.

3. **Deployment**  
   - Runs via **Flask** and **Docker** on HF Spaces.  
   - Serves **dynamic pages** based on URL parameters.

---

## Setup Locally

### Install dependencies

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

### Set environment variables

```bash
export OPENAI_API_KEY="your-key"
export OPENAI_BASE_URL="your-url"
```

### Run the app

```bash
python app.py
```

Visit `http://localhost:5000`.