Ultronprime commited on
Commit
1bc959a
·
verified ·
1 Parent(s): 2108c3b

Add 3 files

Browse files
Files changed (3) hide show
  1. README.md +7 -5
  2. index.html +367 -19
  3. prompts.txt +6 -0
README.md CHANGED
@@ -1,10 +1,12 @@
1
  ---
2
- title: Ibgapp
3
- emoji: 🌍
4
- colorFrom: indigo
5
- colorTo: pink
6
  sdk: static
7
  pinned: false
 
 
8
  ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
1
  ---
2
+ title: ibgapp
3
+ emoji: 🐳
4
+ colorFrom: green
5
+ colorTo: green
6
  sdk: static
7
  pinned: false
8
+ tags:
9
+ - deepsite
10
  ---
11
 
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
index.html CHANGED
@@ -1,19 +1,367 @@
1
- <!doctype html>
2
- <html>
3
- <head>
4
- <meta charset="utf-8" />
5
- <meta name="viewport" content="width=device-width" />
6
- <title>My static Space</title>
7
- <link rel="stylesheet" href="style.css" />
8
- </head>
9
- <body>
10
- <div class="card">
11
- <h1>Welcome to your static Space!</h1>
12
- <p>You can modify this app directly by editing <i>index.html</i> in the Files and versions tab.</p>
13
- <p>
14
- Also don't forget to check the
15
- <a href="https://huggingface.co/docs/hub/spaces" target="_blank">Spaces documentation</a>.
16
- </p>
17
- </div>
18
- </body>
19
- </html>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>ContractIntellect AI | Ibn Battuta Gate</title>
7
+ <script src="https://cdn.tailwindcss.com"></script>
8
+ <link href="https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&display=swap" rel="stylesheet">
9
+ <script src="https://unpkg.com/phosphor-icons"></script>
10
+ <style>
11
+ :root {
12
+ --background: 0 0% 98%;
13
+ --foreground: 20 14.3% 4.1%;
14
+ --primary: 217 91% 60%;
15
+ --primary-foreground: 210 40% 98%;
16
+ --secondary: 270 80% 60%;
17
+ --border: 214.3 31.8% 91.4%;
18
+ }
19
+
20
+ .dark {
21
+ --background: 222.2 84% 5%;
22
+ --foreground: 210 40% 98%;
23
+ --primary: 217 91% 70%;
24
+ --primary-foreground: 222.2 47% 11%;
25
+ --secondary: 270 80% 70%;
26
+ --border: 217.2 33% 17%;
27
+ }
28
+
29
+ body {
30
+ font-family: 'Inter', sans-serif;
31
+ background-color: hsl(var(--background));
32
+ color: hsl(var(--foreground));
33
+ transition: background-color 0.3s ease;
34
+ }
35
+
36
+ .gradient-bg {
37
+ background: linear-gradient(135deg, hsl(var(--primary) / 0.15) 0%, hsl(var(--secondary) / 0.15) 100%);
38
+ }
39
+
40
+ .shine-on-hover:hover {
41
+ position: relative;
42
+ overflow: hidden;
43
+ }
44
+
45
+ .shine-on-hover:hover::after {
46
+ content: '';
47
+ position: absolute;
48
+ top: -50%;
49
+ left: -60%;
50
+ width: 200%;
51
+ height: 200%;
52
+ background: linear-gradient(
53
+ to right,
54
+ rgba(255, 255, 255, 0.13) 0%,
55
+ rgba(255, 255, 255, 0.13) 77%,
56
+ rgba(255, 255, 255, 0.5) 92%,
57
+ rgba(255, 255, 255, 0.0) 100%
58
+ );
59
+ transform: rotate(30deg);
60
+ transition: left 0.7s ease;
61
+ animation: shine 0.7s forwards;
62
+ }
63
+
64
+ @keyframes shine {
65
+ 100% {
66
+ left: 100%;
67
+ }
68
+ }
69
+
70
+ .chat-message {
71
+ max-width: 80%;
72
+ border-radius: 1rem;
73
+ padding: 1rem;
74
+ margin-bottom: 1rem;
75
+ position: relative;
76
+ box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
77
+ }
78
+
79
+ .user-message {
80
+ background-color: hsl(var(--primary) / 0.1);
81
+ border: 1px solid hsl(var(--primary) / 0.2);
82
+ border-bottom-right-radius: 0.25rem;
83
+ }
84
+
85
+ .bot-message {
86
+ background-color: hsl(var(--background));
87
+ border: 1px solid hsl(var(--border));
88
+ border-bottom-left-radius: 0.25rem;
89
+ }
90
+
91
+ .typing-indicator {
92
+ display: flex;
93
+ padding: 1rem;
94
+ }
95
+
96
+ .typing-dot {
97
+ width: 8px;
98
+ height: 8px;
99
+ background-color: hsl(var(--muted-foreground));
100
+ border-radius: 50%;
101
+ margin-right: 4px;
102
+ animation: typing 1s infinite ease-in-out;
103
+ }
104
+
105
+ .typing-dot:nth-child(1) { animation-delay: 0s; }
106
+ .typing-dot:nth-child(2) { animation-delay: 0.2s; }
107
+ .typing-dot:nth-child(3) { animation-delay: 0.4s; }
108
+
109
+ @keyframes typing {
110
+ 0%, 100% {
111
+ transform: translateY(0);
112
+ opacity: 0.6;
113
+ }
114
+ 50% {
115
+ transform: translateY(-5px);
116
+ opacity: 1;
117
+ }
118
+ }
119
+ </style>
120
+ </head>
121
+ <body class="min-h-screen dark:bg-gray-900 dark:text-gray-100">
122
+ <div class="flex flex-col min-h-screen">
123
+ <!-- Header -->
124
+ <header class="bg-white dark:bg-gray-800 shadow-sm border-b border-gray-200 dark:border-gray-700">
125
+ <div class="container mx-auto px-4 py-4 flex items-center justify-between">
126
+ <div class="flex items-center space-x-3">
127
+ <div class="p-2 rounded-lg gradient-bg">
128
+ <i class="ph ph-file-text text-xl text-primary-500 dark:text-primary-400"></i>
129
+ </div>
130
+ <div>
131
+ <h1 class="text-xl font-bold">ContractIntellect AI</h1>
132
+ <p class="text-sm text-gray-500 dark:text-gray-400">Ibn Battuta Gate Project</p>
133
+ </div>
134
+ </div>
135
+ <button id="themeToggle" class="p-2 rounded-lg hover:bg-gray-100 dark:hover:bg-gray-700">
136
+ <i class="ph ph-sun-dim dark:ph-sun dark:hidden text-xl"></i>
137
+ <i class="ph ph-moon hidden dark:block text-xl"></i>
138
+ </button>
139
+ </div>
140
+ </header>
141
+
142
+ <!-- Main Content -->
143
+ <main class="flex-1 container mx-auto px-4 py-6">
144
+ <div class="max-w-5xl mx-auto">
145
+ <!-- Welcome Card -->
146
+ <div class="bg-white dark:bg-gray-800 rounded-xl shadow-sm border border-gray-200 dark:border-gray-700 p-6 mb-6 shine-on-hover">
147
+ <div class="flex items-start space-x-4">
148
+ <div class="bg-primary-50 dark:bg-primary-900/20 p-3 rounded-lg flex-shrink-0">
149
+ <i class="ph ph-buildings text-xl text-primary-600 dark:text-primary-400"></i>
150
+ </div>
151
+ <div>
152
+ <h2 class="text-xl font-semibold mb-2">Contract Intelligence Assistant</h2>
153
+ <p class="text-gray-600 dark:text-gray-300">
154
+ Query specific contractual details about the Ibn Battuta Gate project instantly.
155
+ This AI specializes in analyzing contracts, AMCs, LPOs and related documents.
156
+ </p>
157
+ </div>
158
+ </div>
159
+ </div>
160
+
161
+ <!-- Chat Interface -->
162
+ <div class="bg-white dark:bg-gray-800 rounded-xl shadow-sm border border-gray-200 dark:border-gray-700 overflow-hidden">
163
+ <!-- Chat Header -->
164
+ <div class="border-b border-gray-200 dark:border-gray-700 px-4 py-3 flex items-center space-x-3">
165
+ <div class="bg-primary-100 dark:bg-primary-900/30 p-2 rounded-lg">
166
+ <i class="ph ph-chat-centered-text text-primary-600 dark:text-primary-400"></i>
167
+ </div>
168
+ <h3 class="font-semibold">Contract Query Assistant</h3>
169
+ </div>
170
+
171
+ <!-- Chat Messages -->
172
+ <div id="chatContainer" class="h-96 overflow-y-auto p-4 space-y-3">
173
+ <div class="flex justify-start">
174
+ <div class="chat-message bot-message">
175
+ <div class="flex items-start space-x-3">
176
+ <div class="bg-primary-100 dark:bg-primary-900/20 p-2 rounded-full flex-shrink-0">
177
+ <i class="ph ph-bot text-primary-600 dark:text-primary-400 text-sm"></i>
178
+ </div>
179
+ <div>
180
+ <p class="text-sm">Hello, I'm your ContractIntellect AI for the Ibn Battuta Gate project. Ask me anything about contracts, AMCs, LPOs, or other project documents.</p>
181
+ </div>
182
+ </div>
183
+ </div>
184
+ </div>
185
+ </div>
186
+
187
+ <!-- Chat Input -->
188
+ <div class="border-t border-gray-200 dark:border-gray-700 p-4 bg-gray-50 dark:bg-gray-700/30">
189
+ <div class="flex items-center space-x-2">
190
+ <input
191
+ type="text"
192
+ id="chatInput"
193
+ placeholder="Ask about contractual details..."
194
+ class="flex-1 px-4 py-2 rounded-lg border border-gray-300 dark:border-gray-600 bg-white dark:bg-gray-800 focus:outline-none focus:ring-2 focus:ring-primary-500 dark:focus:ring-primary-600"
195
+ >
196
+ <button id="sendButton" class="p-2 rounded-lg bg-primary-600 hover:bg-primary-700 text-white transition-colors">
197
+ <i class="ph ph-paper-plane-right"></i>
198
+ </button>
199
+ </div>
200
+ <p class="text-xs text-gray-500 dark:text-gray-400 mt-2">
201
+ All responses are based exclusively on project contractual documents.
202
+ </p>
203
+ </div>
204
+ </div>
205
+
206
+ <!-- Features Grid -->
207
+ <div class="grid grid-cols-1 md:grid-cols-3 gap-4 mt-6">
208
+ <div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-4">
209
+ <div class="flex items-center space-x-3 mb-3">
210
+ <div class="bg-primary-100 dark:bg-primary-900/20 p-2 rounded-lg">
211
+ <i class="ph ph-file-text text-primary-600 dark:text-primary-400"></i>
212
+ </div>
213
+ <h4 class="font-medium">Contract Clauses</h4>
214
+ </div>
215
+ <p class="text-sm text-gray-600 dark:text-gray-300">
216
+ Query specific contract terms, obligations, or requirements instantly.
217
+ </p>
218
+ </div>
219
+ <div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-4">
220
+ <div class="flex items-center space-x-3 mb-3">
221
+ <div class="bg-primary-100 dark:bg-primary-900/20 p-2 rounded-lg">
222
+ <i class="ph ph-calendar-check text-primary-600 dark:text-primary-400"></i>
223
+ </div>
224
+ <h4 class="font-medium">Schedules & Deadlines</h4>
225
+ </div>
226
+ <p class="text-sm text-gray-600 dark:text-gray-300">
227
+ Get precise details about timelines, milestones and delivery dates.
228
+ </p>
229
+ </div>
230
+ <div class="bg-white dark:bg-gray-800 rounded-lg shadow-sm border border-gray-200 dark:border-gray-700 p-4">
231
+ <div class="flex items-center space-x-3 mb-3">
232
+ <div class="bg-primary-100 dark:bg-primary-900/20 p-2 rounded-lg">
233
+ <i class="ph ph-handshake text-primary-600 dark:text-primary-400"></i>
234
+ </div>
235
+ <h4 class="font-medium">Payment Terms</h4>
236
+ </div>
237
+ <p class="text-sm text-gray-600 dark:text-gray-300">
238
+ Clarify payment schedules, amounts, and conditions.
239
+ </p>
240
+ </div>
241
+ </div>
242
+ </div>
243
+ </main>
244
+
245
+ <!-- Footer -->
246
+ <footer class="bg-white dark:bg-gray-800 border-t border-gray-200 dark:border-gray-700 py-4">
247
+ <div class="container mx-auto px-4 text-center text-sm text-gray-500 dark:text-gray-400">
248
+ <p>© 2024 ContractIntellect AI | Ibn Battuta Gate Project</p>
249
+ </div>
250
+ </footer>
251
+ </div>
252
+
253
+ <script>
254
+ // Theme toggle
255
+ document.addEventListener('DOMContentLoaded', () => {
256
+ const themeToggle = document.getElementById('themeToggle');
257
+ const html = document.documentElement;
258
+
259
+ // Check for saved theme preference or use preferred color scheme
260
+ const savedTheme = localStorage.getItem('theme');
261
+ const systemPrefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
262
+
263
+ if (savedTheme === 'dark' || (!savedTheme && systemPrefersDark)) {
264
+ html.classList.add('dark');
265
+ }
266
+
267
+ themeToggle.addEventListener('click', () => {
268
+ html.classList.toggle('dark');
269
+ localStorage.setItem('theme', html.classList.contains('dark') ? 'dark' : 'light');
270
+ });
271
+
272
+ // Chat functionality
273
+ const chatContainer = document.getElementById('chatContainer');
274
+ const chatInput = document.getElementById('chatInput');
275
+ const sendButton = document.getElementById('sendButton');
276
+
277
+ function addMessage(content, isBot = false) {
278
+ const messageDiv = document.createElement('div');
279
+ messageDiv.className = `flex justify-${isBot ? 'start' : 'end'}`;
280
+
281
+ const messageContent = document.createElement('div');
282
+ messageContent.className = `chat-message ${isBot ? 'bot-message' : 'user-message'}`;
283
+
284
+ messageContent.innerHTML = `
285
+ <div class="flex items-start space-x-3">
286
+ <div class="${isBot ? 'bg-primary-100 dark:bg-primary-900/20' : 'bg-gray-100 dark:bg-gray-700'} p-2 rounded-full flex-shrink-0">
287
+ <i class="ph ph-${isBot ? 'bot' : 'user'} ${isBot ? 'text-primary-600 dark:text-primary-400' : 'text-gray-600 dark:text-gray-400'} text-sm"></i>
288
+ </div>
289
+ <div>
290
+ <p class="text-sm">${content}</p>
291
+ </div>
292
+ </div>
293
+ `;
294
+
295
+ messageDiv.appendChild(messageContent);
296
+ chatContainer.appendChild(messageDiv);
297
+ chatContainer.scrollTop = chatContainer.scrollHeight;
298
+ }
299
+
300
+ function showTypingIndicator() {
301
+ const typingDiv = document.createElement('div');
302
+ typingDiv.className = 'flex justify-start';
303
+ typingDiv.id = 'typingIndicator';
304
+
305
+ const typingContent = document.createElement('div');
306
+ typingContent.className = 'typing-indicator';
307
+
308
+ typingContent.innerHTML = `
309
+ <div class="flex items-center space-x-2">
310
+ <div class="bg-primary-100 dark:bg-primary-900/20 p-2 rounded-full">
311
+ <i class="ph ph-bot text-primary-600 dark:text-primary-400 text-sm"></i>
312
+ </div>
313
+ <div class="flex">
314
+ <div class="typing-dot"></div>
315
+ <div class="typing-dot"></div>
316
+ <div class="typing-dot"></div>
317
+ </div>
318
+ </div>
319
+ `;
320
+
321
+ typingDiv.appendChild(typingContent);
322
+ chatContainer.appendChild(typingDiv);
323
+ chatContainer.scrollTop = chatContainer.scrollHeight;
324
+ }
325
+
326
+ function hideTypingIndicator() {
327
+ const indicator = document.getElementById('typingIndicator');
328
+ if (indicator) {
329
+ indicator.remove();
330
+ }
331
+ }
332
+
333
+ function handleSendMessage() {
334
+ const message = chatInput.value.trim();
335
+ if (!message) return;
336
+
337
+ addMessage(message, false);
338
+ chatInput.value = '';
339
+
340
+ // Mock API response
341
+ showTypingIndicator();
342
+
343
+ setTimeout(() => {
344
+ hideTypingIndicator();
345
+ const mockResponses = [
346
+ "According to Clause 15.1(b) of the Main Construction Contract (Doc ID: MCC_IbnBattutaGate_Final_2023), the main contractor is required to maintain Public Liability insurance with a minimum coverage of $5M per occurrence.",
347
+ "The payment schedule for Phase 1 is outlined in Schedule B of the Master Agreement (Doc ID: MA_IBG_2023), specifying 30% payable upon completion of foundation work.",
348
+ "Section 8.3 of the AMC (Doc ID: AMC_IBG_2024) states that equipment warranties are valid for 24 months from the date of commissioning."
349
+ ];
350
+ const randomResponse = mockResponses[Math.floor(Math.random() * mockResponses.length)];
351
+ addMessage(randomResponse, true);
352
+ }, 1500);
353
+ }
354
+
355
+ sendButton.addEventListener('click', handleSendMessage);
356
+ chatInput.addEventListener('keypress', (e) => {
357
+ if (e.key === 'Enter') {
358
+ handleSendMessage();
359
+ }
360
+ });
361
+
362
+ // Initialize empty chat
363
+ addMessage("For example, you could ask: 'What are the insurance requirements for the main contractor?'", true);
364
+ });
365
+ </script>
366
+ <p style="border-radius: 8px; text-align: center; font-size: 12px; color: #fff; margin-top: 16px;position: fixed; left: 8px; bottom: 8px; z-index: 10; background: rgba(0, 0, 0, 0.8); padding: 4px 8px;">Made with <img src="https://enzostvs-deepsite.hf.space/logo.svg" alt="DeepSite Logo" style="width: 16px; height: 16px; vertical-align: middle;display:inline-block;margin-right:3px;filter:brightness(0) invert(1);"><a href="https://enzostvs-deepsite.hf.space" style="color: #fff;text-decoration: underline;" target="_blank" >DeepSite</a> - 🧬 <a href="https://enzostvs-deepsite.hf.space?remix=Ultronprime/ibgapp" style="color: #fff;text-decoration: underline;" target="_blank" >Remix</a></p></body>
367
+ </html>
prompts.txt ADDED
@@ -0,0 +1,6 @@
 
 
 
 
 
 
 
1
+ # Migrating RAG Project from Google Cloud to Hugging Face Pro: A Comprehensive Guide The need to balance powerful AI capabilities with cost-effective deployment is a common challenge in today's AI landscape. This report explores how you can leverage your Hugging Face Pro account to create a comprehensive RAG system, potentially replacing your current Google Cloud-based Gemini implementation while reducing costs. ## Understanding Hugging Face Pro Capabilities Hugging Face Pro offers several advantages that make it suitable for building and deploying RAG systems at a more affordable price point than many enterprise cloud offerings. For just $9 per month, Hugging Face Pro provides enhanced capabilities that are particularly valuable for RAG implementations[13][16]: - **5x more usage quota** for ZeroGPU Spaces, giving priority in GPU queues - **ZeroGPU Spaces** with H200 hardware access - **Spaces Dev Mode** for fast iterations via SSH/VS Code - **$2 included credits** across all Inference Providers - **Dataset Viewer** features for private datasets - **Higher API limits** for inference The Pro subscription also unlocks higher-tier access to Inference API endpoints for curated powerful models that benefit from ultra-fast inference[17]. This is especially useful when building production-ready RAG systems. ## Available Models for RAG Implementation Hugging Face hosts over 250,000 repositories[5], providing access to state-of-the-art models for both the generation and retrieval components of your RAG system. ### For Generation (Foundation Models) You mentioned several powerful open models on Hugging Face that could potentially replace Gemini: 1. **Qwen 3 235B**: This is among the largest open models available and offers competitive performance for complex reasoning tasks. 2. **DeepSeek models**: These models have shown strong performance in code generation and general knowledge tasks. 3. **Latest Llama models**: Meta's Llama models (especially Llama 3) have demonstrated performance comparable to proprietary models. 4. **Mixtral 8x7B Instruct**: This 45B parameter MoE model offers performance comparable to top proprietary models with a 32k token context window[17]. 5. **Nous Hermes 2 Mixtral 8x7B DPO**: A further trained version over the Mixtral 8x7B[17]. ### For Retrieval Components For the retrieval aspect of RAG, Hugging Face offers integration with Pyserini, a widely used toolkit for reproducible IR research[4]. This integration facilitates text corpus searching and analysis, which is essential for a RAG system. ## Practical Implementation Strategy ### 1. Data Structuring and Processing You can adapt your current JSON structuring workflow from Colab to Hugging Face using the following approach: ```python # Equivalent workflow in Hugging Face from huggingface_hub import InferenceApi from huggingface_hub import Repository import json # Initialize the model (similar to your current Gemini implementation) inference = InferenceApi(model_id="your-chosen-model/like-qwen-3-235B") # Process documents and structure into JSON def process_document(doc_content): # Similar logic to your current Gemini implementation response = inference(doc_content) structured_json = json.loads(response) return structured_json ``` ### 2. Dataset Creation and Hosting Hugging Face provides excellent dataset hosting capabilities: ```python from datasets import Dataset from huggingface_hub import push_to_hub # Convert your processed JSONs to a dataset documents = [...] # Your processed JSON documents dataset = Dataset.from_dict({"text": documents}) # Upload to your private Hugging Face repo push_to_hub(dataset, "your-username/your-project-dataset", private=True) ``` ### 3. Setting Up the RAG Pipeline With your data processed and hosted, you can create a comprehensive RAG system: ```python from transformers import AutoModelForCausalLM, AutoTokenizer from huggingface_hub import InferenceApi # Load retriever (e.g., embedding model + vector store) retriever = setup_retriever("your-username/your-project-dataset") # Load generation model generator = AutoModelForCausalLM.from_pretrained("your-chosen-model", use_auth_token=True) tokenizer = AutoTokenizer.from_pretrained("your-chosen-model", use_auth_token=True) # RAG implementation def query_rag_system(question): # Retrieve relevant documents docs = retriever.get_relevant_documents(question) # Format prompt with retrieved context prompt = format_prompt(question, docs) # Generate response inputs = tokenizer(prompt, return_tensors="pt").to(generator.device) response = generator.generate(**inputs) return tokenizer.decode(response[0]) ``` ## Cost Advantages and Performance Considerations Transitioning from Google Cloud to Hugging Face Pro offers several financial and performance benefits: ### Cost Benefits 1. **Fixed subscription fee**: $9/month for Pro subscription vs. potentially unpredictable usage-based cloud costs[16]. 2. **Included credits**: $2 inference credits included with Pro subscription[16]. 3. **Higher rate limits**: Avoid additional costs from exceeding basic quotas[17]. 4. **Open-source models**: No licensing fees compared to proprietary models like Gemini. ### Performance Considerations 1. **Model selection flexibility**: Choose the best model for your specific use case rather than being limited to a single provider's offerings. 2. **Hardware optimization**: Hugging Face Pro provides access to H200 GPUs which are optimized for AI workloads[13]. 3. **Integration potential**: The HugNLP library provides comprehensive NLP capabilities with the HuggingFace Transformers backend[10]. ## Conclusion Migrating your RAG system from Google Cloud/Gemini to Hugging Face Pro is not only feasible but potentially advantageous from both cost and flexibility perspectives. With access to powerful open models like Qwen 3 235B, DeepSeek, and Llama 3, along with specialized tools for retrieval, you can build a comprehensive project-specific RAG bot while maintaining control over costs. The $9/month Pro subscription provides sufficient resources for development and small to medium-scale deployment, making it an excellent alternative to more expensive enterprise cloud solutions for your project needs. By leveraging the extensive model ecosystem and deployment tools available on Hugging Face, you can create a robust, cost-effective RAG system tailored to your project's specific knowledge base. Citations: [1] https://ppl-ai-file-upload.s3.amazonaws.com/web/direct-files/attachments/61164377/68bb5a86-6a1d-44be-8958-d5b35f089481/Construction_Document_Data_Extraction_Apr_14-_2025-_8_16_38-PM_-5-_-1-_-3-5.ipynb [2] https://ppl-ai-file-upload.s3.amazonaws.com/web/direct-files/attachments/61164377/68bb5a86-6a1d-44be-8958-d5b35f089481/Construction_Document_Data_Extraction_Apr_14-_2025-_8_16_38-PM_-5-_-1-_-3-5.ipynb [3] https://www.semanticscholar.org/paper/aa4a9d49e48e5a09d694de909ec68d677ae98162 [4] https://www.semanticscholar.org/paper/934bee8d592e440463bd19249bf7df5b31109472 [5] https://arxiv.org/abs/2306.01481 [6] https://arxiv.org/abs/2307.14841 [7] https://arxiv.org/abs/2310.01642 [8] https://www.semanticscholar.org/paper/4a607697d39989472b12c81be575a5afabecf8f7 [9] https://arxiv.org/pdf/2311.13380.pdf [10] https://arxiv.org/pdf/2401.05379.pdf [11] https://arxiv.org/pdf/2302.14286.pdf [12] https://arxiv.org/pdf/2401.13822.pdf [13] https://arxiv.org/pdf/2405.13185.pdf [14] https://huggingface.co/pricing [15] https://huggingface.co/subscribe/pro [16] https://huggingface.co/docs/hub/en/billing [17] https://www.youtube.com/watch?v=yw-yT3nSsKU [18] https://huggingface.co/blog/inference-pro [19] https://apidog.com/blog/how-to-use-hugging-face-api/ [20] https://www.semanticscholar.org/paper/00d9b30debb36f30c1e73750d4a9c53f262bccfa [21] https://www.semanticscholar.org/paper/b639dd92cf2639f3d584e5e5bfd15ace594e0650 [22] https://arxiv.org/abs/2011.14200 [23] https://www.semanticscholar.org/paper/38c583d644adbd6c007fbc18a5db3231b554074e [24] https://huggingface.co/docs/api-inference/en/pricing [25] https://www.coursera.org/articles/what-is-hugging-face [26] https://www.youtube.com/watch?v=85FVwWPg63Q [27] https://huggingface.co/docs/inference-providers/en/pricing [28] https://huggingface.co [29] https://huggingface.co/inference-api/serverless [30] https://www.reddit.com/r/huggingface/comments/1jkyj2a/huggingface_just_billed_me_300_on_top_of_the_9/ [31] https://huggingface.co/spaces/victor/pro-landing [32] https://huggingface.co/docs/api-inference/en/index [33] https://huggingface.co/meta-llama/Llama-3.3-70B-Instruct/discussions/107 [34] https://www.sapien.io/blog/what-is-hugging-face-a-review-of-its-key-features-and-tools [35] https://huggingface.co/docs/inference-providers/en/index [36] https://huggingface.co/docs/inference-endpoints/en/pricing [37] https://huggingface.co/docs/inference-providers/en/tasks/index --- Answer from Perplexity: pplx.ai/share
2
+ # Converting PDF Document Extraction from Google Cloud to Hugging Face for RAG After analyzing the notebook code, I can see it's designed to extract structured data from construction documents (LPOs, Payment Certificates) using Google Cloud's Vertex AI and Gemini model. Let me outline how to recreate this functionality in a Hugging Face environment for RAG implementation. ## Core Components to Recreate The current system has these main components: - PDF document processing - Structured data extraction using a powerful LLM (Gemini) - JSON schema enforcement - Validation of extracted data - Storage of structured outputs ## Implementation with Hugging Face ### 1. Environment Setup ```python # Install required packages !pip install transformers datasets sentence-transformers pypdf langchain faiss-cpu !pip install accelerate bitsandbytes peft # For efficient model loading # For UI if needed !pip install gradio ``` ### 2. Document Processing ```python import os import json from pypdf import PdfReader from transformers import AutoTokenizer, AutoModelForCausalLM from datasets import Dataset from sentence_transformers import SentenceTransformer import torch def process_pdf(pdf_path): """Extract text content from PDF""" reader = PdfReader(pdf_path) text = "" for page in reader.pages: text += page.extract_text() + "\n\n" return text def chunk_text(text, chunk_size=1000, overlap=200): """Split text into overlapping chunks""" chunks = [] start = 0 while start start and text[end] != ' ': end -= 1 chunks.append(text[start:end]) start = end - overlap if end - overlap > start else end return chunks ``` ### 3. Model Setup for Extraction ```python def setup_extraction_model(model_name="meta-llama/Llama-2-13b-hf"): """Set up the model for extracting structured data""" # For Hugging Face Pro users, you can use more powerful models tokenizer = AutoTokenizer.from_pretrained(model_name) # Load model with 8-bit quantization to save memory model = AutoModelForCausalLM.from_pretrained( model_name, load_in_8bit=True, device_map="auto", torch_dtype=torch.float16 ) return model, tokenizer # Alternative models you could use with your Pro account: # - "Qwen/Qwen1.5-72B-Chat" (or the 235B version when available) # - "deepseek-ai/deepseek-llm-67b-chat" # - "meta-llama/Llama-3-70b-instruct" # - "mistralai/Mixtral-8x7B-Instruct-v0.1" ``` ### 4. JSON Schema Definition ```python # The same schema from your notebook can be used response_schema = { "type": "object", "properties": { "document_metadata": { "type": "object", "properties": { # Your existing schema properties... } }, # Rest of your schema... } } # Create a schema prompt to instruct the model def create_schema_prompt(schema): schema_str = json.dumps(schema, indent=2) return ( "Extract information according to this JSON schema:\n\n" f"{schema_str}\n\n" "Return ONLY a valid JSON object based on this schema." ) ``` ### 5. Data Extraction Function ```python def extract_structured_data(model, tokenizer, text, system_instruction): """Extract structured data from text using the LLM""" # Format prompt with system instruction prompt = f""" {system_instruction} Below is a document content: {text} Extract the structured information into JSON format. """ inputs = tokenizer(prompt, return_tensors="pt").to(model.device) # Generate with proper settings to get JSON with torch.no_grad(): outputs = model.generate( **inputs, max_new_tokens=4096, temperature=0.2, do_sample=True, top_p=0.95 ) response = tokenizer.decode(outputs[0], skip_special_tokens=True) # Extract just the JSON part from the response try: # Try to find JSON beginning with { and ending with } json_start = response.find('{') json_end = response.rfind('}') + 1 if json_start >= 0 and json_end > json_start: json_str = response[json_start:json_end] parsed_json = json.loads(json_str) return parsed_json else: return None except json.JSONDecodeError: return None ``` ### 6. RAG Dataset Creation ```python def create_rag_dataset(documents_data): """Create a HuggingFace dataset for the processed documents""" # Convert the list of document data to a dataset dataset = Dataset.from_list(documents_data) return dataset def index_dataset_for_rag(dataset, embedding_model_name="sentence-transformers/all-MiniLM-L6-v2"): """Create embeddings and index the dataset for RAG""" # Load embedding model embedding_model = SentenceTransformer(embedding_model_name) # Extract text for embedding texts = [] for item in dataset: # Convert the JSON to a string representation for embedding texts.append(json.dumps(item)) # Create embeddings embeddings = embedding_model.encode(texts) # Create FAISS index import faiss dimension = embeddings.shape[1] index = faiss.IndexFlatL2(dimension) index.add(embeddings) return index, embedding_model ``` ### 7. Building the RAG System ```python from langchain.vectorstores import FAISS from langchain.embeddings import HuggingFaceEmbeddings from langchain.schema import Document def build_rag_system(documents_data, embedding_model_name="sentence-transformers/all-MiniLM-L6-v2"): """Build a complete RAG system using LangChain and HuggingFace""" # Create embedding function embeddings = HuggingFaceEmbeddings(model_name=embedding_model_name) # Prepare documents for the vector store documents = [] for i, doc_data in enumerate(documents_data): # Convert each JSON to a string for the content content = json.dumps(doc_data) # Create a LangChain document doc = Document( page_content=content, metadata={"source": f"document_{i}", "type": doc_data.get("document_metadata", {}).get("document_source_type", "unknown")} ) documents.append(doc) # Create the vector store vector_store = FAISS.from_documents(documents, embeddings) return vector_store ``` ### 8. Complete Pipeline ```python def process_documents_for_rag(pdf_paths, system_instruction, model_name="mistralai/Mixtral-8x7B-Instruct-v0.1"): """Process multiple PDFs and create a RAG system""" # Setup model model, tokenizer = setup_extraction_model(model_name) documents_data = [] for pdf_path in pdf_paths: # Extract text from PDF text = process_pdf(pdf_path) # Process in chunks if needed chunks = chunk_text(text) # Extract data from each chunk chunk_data = [] for chunk in chunks: result = extract_structured_data(model, tokenizer, chunk, system_instruction) if result: chunk_data.append(result) # Combine chunk data (this might need custom logic depending on your schema) if chunk_data: combined_data = chunk_data[0] # Start with first chunk # Add logic to merge subsequent chunks if needed documents_data.append(combined_data) # Create RAG system vector_store = build_rag_system(documents_data) # Save the extracted data dataset = create_rag_dataset(documents_data) dataset.save_to_disk("construction_documents_dataset") return vector_store, dataset ``` ### 9. Query Your RAG System ```python def query_rag_system(query, vector_store, response_model_name="meta-llama/Llama-3-8b-instruct"): """Query the RAG system with a question""" # Setup response model response_model, response_tokenizer = setup_extraction_model(response_model_name) # Get relevant documents docs = vector_store.similarity_search(query, k=3) # Format context from retrieved documents context = "\n\n".join([doc.page_content for doc in docs]) # Create prompt prompt = f""" You are an AI assistant with access to project documentation. Use the following information from project documents to answer the question accurately. Context information: {context} Question: {query} Please provide a comprehensive and accurate answer based only on the context provided. """ # Generate response inputs = response_tokenizer(prompt, return_tensors="pt").to(response_model.device) with torch.no_grad(): outputs = response_model.generate( **inputs, max_new_tokens=1024, temperature=0.7, do_sample=True ) response = response_tokenizer.decode(outputs[0], skip_special_tokens=True) return response ``` ### 10. Complete Solution ```python # Example usage if __name__ == "__main__": # Set paths to your PDF files pdf_dir = "construction_documents/" pdf_paths = [os.path.join(pdf_dir, f) for f in os.listdir(pdf_dir) if f.endswith('.pdf')] # Use the system instruction from your notebook system_instruction = """# Document Extraction Specialist You are an expert Document Extraction Specialist with advanced capabilities for extracting project scope details, LPO information, quotation details, and quantitative data from construction and project documents... """ # Process documents and create RAG system vector_store, dataset = process_documents_for_rag(pdf_paths, system_instruction) # Save dataset to Hugging Face Hub (if you have an account) from huggingface_hub import push_to_hub dataset.push_to_hub("your-username/construction-documents-dataset") # Example query query = "What is the total amount of the latest payment certificate?" answer = query_rag_system(query, vector_store) print(answer) ``` ## Key Advantages of This Implementation 1. **Cost Management**: Using your Hugging Face Pro account is more cost-effective than Google Cloud for this use case. 2. **Model Flexibility**: You can choose from various powerful open models: - Llama 3 70B for high-quality extraction - Mixtral 8x7B for balanced performance/speed - Qwen models when you need maximum capability 3. **Local Processing**: Most processing happens locally on your Hugging Face space, reducing API costs. 4. **Persistent Dataset**: The structured data is stored as a HF Dataset, making it easily shareable and versionable. 5. **Integration**: Built using LangChain and Hugging Face tools for easy expansion of capabilities. 6. **Optimized Model Loading**: Uses quantization techniques to run larger models on limited hardware. This solution maintains the core functionality of your original notebook but adapts it to work efficiently in the Hugging Face ecosystem, creating an indexed dataset optimized for RAG applications. Citations: [1] https://ppl-ai-file-upload.s3.amazonaws.com/web/direct-files/attachments/61164377/68bb5a86-6a1d-44be-8958-d5b35f089481/Construction_Document_Data_Extraction_Apr_14-_2025-_8_16_38-PM_-5-_-1-_-3-5.ipynb [2] https://ppl-ai-file-upload.s3.amazonaws.com/web/direct-files/attachments/61164377/68bb5a86-6a1d-44be-8958-d5b35f089481/Construction_Document_Data_Extraction_Apr_14-_2025-_8_16_38-PM_-5-_-1-_-3-5.ipynb --- Answer from Perplexity: pplx.ai/share
3
+ Advanced RAG Implementation Multi-modal Indexing Pipeline python from sentence_transformers import SentenceTransformer from langchain_community.vectorstores import FAISS class ConstructionRAG: def __init__(self): self.embedder = SentenceTransformer('sentence-transformers/all-mpnet-base-v2') self.vector_db = FAISS.load_local("construction_index") def update_index(self, json_data): documents = [self._format_doc(item) for item in json_data] embeddings = self.embedder.encode(documents) self.vector_db.add_embeddings(embeddings, documents) def query(self, question, k=3): query_embed = self.embedder.encode(question) return self.vector_db.similarity_search_by_vector(query_embed, k=k) 6. Deployment Architecture High-Availability Setup text +---------------------+ | HF Spaces (ZeroGPU)| +----------+----------+ | v +----------------+ +----------+----------+ | User Upload +------->| Document Processor | +----------------+ +----------+----------+ | v +----------+----------+ | Validation Service | +----------+----------+ | v +----------+----------+ | RAG Indexer | +----------+----------+ | v +----------+----------+ | API Endpoint | +---------------------+ 7. Validation Framework Multi-layer Verification Schema Compliance Check Cross-field Validation Mathematical consistency Temporal coherence Business Rule Enforcement Human-in-the-loop Review python def validate_extraction(output): # Schema validation jsonschema.validate(output, CONSTRUCTION_SCHEMA) # Cross-field checks if output['total_amount'] != sum(item['value'] for item in output['line_items']): raise ValidationError("Amount mismatch") # Temporal validation if output['effective_date'] > output['expiration_date']: raise ValidationError("Invalid date range") 8. Performance Benchmarks Processing Speed Comparison Document Size Gemini Pro Qwen-72B DeepSeek-67B 5 pages 8.2s 9.1s 7.8s 20 pages 22.4s 24.7s 19.5s 50 pages 51.1s 55.3s 47.9s Average of 100 runs on H100 GPU 9. Security Implementation Data Protection Measures Field-level Encryption RBAC for Document Access Audit Trail Logging Anonymization Pipeline python from cryptography.fernet import Fernet class DocumentSecurer: def __init__(self): self.key = Fernet.generate_key() self.cipher = Fernet(self.key) def encrypt_document(self, data): return self.cipher.encrypt(json.dumps(data).encode()) def decrypt_document(self, encrypted_data): return json.loads(self.cipher.decrypt(encrypted_data)) 10. Continuous Improvement System Feedback Loop Architecture text +----------------+ | User Feedback | +-------+--------+ | v +------------------+------------------+ | Validation Service | | +----------------+----------------+ | | | Automatic | Manual | | | | Validation | Review | | | +--------+-------+--------+-------+ | | | | | | v v | | +----------------+----------------+ | | | Model Retraining Pipeline | | | +----------------+----------------+ | | | | | | v v | | +----------------+----------------+ | | | Updated Model | Schema Updates | | | | Deployment | Deployment | | | +----------------+----------------+ | +-------------------------------------+ This architecture enables continuous model improvement while maintaining schema stability.. Implementation Blueprint Document Processing Workflow python from transformers import AutoModelForCausalLM, AutoTokenizer from huggingface_hub import InferenceClient import PyPDF2 class ConstructionDocProcessor: def __init__(self, model_name="Qwen/Qwen1.5-72B-Chat"): self.tokenizer = AutoTokenizer.from_pretrained(model_name) self.model = AutoModelForCausalLM.from_pretrained( model_name, device_map="auto", torch_dtype=torch.bfloat16 ) self.schema = {...} # Your JSON schema def extract_text(self, pdf_bytes): reader = PyPDF2.PdfReader(io.BytesIO(pdf_bytes)) return "\n".join([page.extract_text() for page in reader.pages]) def structure_data(self, text): prompt = f"""Extract information according to this schema: {json.dumps(self.schema)} Document content: {text}""" inputs = self.tokenizer(prompt, return_tensors="pt").to(self.model.device) outputs = self.model.generate(**inputs, max_new_tokens=4096) return self.tokenizer.decode(outputs[0], skip_special_tokens=True)
4
+ import { Switch, Route } from "wouter"; import { queryClient } from "./lib/queryClient"; import { QueryClientProvider } from "@tanstack/react-query"; import { Toaster } from "@/components/ui/toaster"; import { TooltipProvider } from "@/components/ui/tooltip"; import { useEffect } from "react"; import NotFound from "@/pages/not-found"; import Home from "@/pages/Home"; import Header from "@/components/layout/Header"; import Footer from "@/components/layout/Footer"; function Router() { return ( <Switch> <Route path="/" component={Home} /> <Route component={NotFound} /> </Switch> ); } function App() { useEffect(() => { const metaThemeColor = document.createElement('meta'); metaThemeColor.name = 'theme-color'; metaThemeColor.content = '#ffffff'; document.head.appendChild(metaThemeColor); return () => { document.head.removeChild(metaThemeColor); }; }, []); return ( <QueryClientProvider client={queryClient}> <TooltipProvider> <div className="flex flex-col min-h-screen bg-neutral-50 text-neutral-900 dark:bg-neutral-900 dark:text-neutral-50 font-sans"> <Header /> <main className="flex-1"> <Router /> </main> <Footer /> <Toaster /> </div> </TooltipProvider> </QueryClientProvider> ); } export default App;import { createRoot } from "react-dom/client"; import App from "./App"; import "./index.css"; import { ThemeProvider } from "./components/theme/ThemeProvider"; createRoot(document.getElementById("root")!).render( <ThemeProvider defaultTheme="light" storageKey="hugging-rag-theme"> <App /> </ThemeProvider> );@tailwind base; @tailwind components; @tailwind utilities; @layer base { :root { /* Base colors */ --background: 0 0% 98%; --foreground: 20 14.3% 4.1%; /* Card */ --card: 0 0% 100%; --card-foreground: 20 14.3% 4.1%; /* Popover */ --popover: 0 0% 100%; --popover-foreground: 20 14.3% 4.1%; /* Primary */ --primary-50: 214 100% 97%; --primary-100: 213 96% 87%; --primary-200: 212 93% 76%; --primary-300: 212 96% 62%; --primary-400: 213 94% 56%; --primary-500: 213 90% 45%; --primary-600: 212 100% 41%; --primary-700: 211 100% 35%; --primary-800: 211 100% 30%; --primary-900: 211 100% 26%; --primary: 213 90% 45%; --primary-foreground: 0 0% 98%; /* Secondary */ --secondary-50: 270 100% 98%; --secondary-100: 268 100% 94%; --secondary-200: 268 100% 88%; --secondary-300: 270 100% 72%; --secondary-400: 271 100% 63%; --secondary-500: 272 100% 54%; --secondary-600: 272 99% 49%; --secondary-700: 273 99% 44%; --secondary-800: 273 99% 38%; --secondary-900: 274 97% 29%; --secondary: 272 100% 54%; --secondary-foreground: 0 0% 98%; /* Muted */ --muted: 210 40% 96.1%; --muted-foreground: 215.4 16.3% 46.9%; /* Accent */ --accent: 210 40% 96.1%; --accent-foreground: 222.2 47.4% 11.2%; /* Destructive */ --destructive: 0 84.2% 60.2%; --destructive-foreground: 210 40% 98%; /* Border, Input, Ring */ --border: 214.3 31.8% 91.4%; --input: 214.3 31.8% 91.4%; --ring: 222.2 84% 4.9%; /* Neutral */ --neutral-50: 210 40% 98%; --neutral-100: 210 25% 95%; --neutral-200: 214 20% 88%; --neutral-300: 212 18% 78%; --neutral-400: 212 14% 65%; --neutral-500: 212 10% 53%; --neutral-600: 212 12% 43%; --neutral-700: 210 14% 33%; --neutral-800: 216 18% 19%; --neutral-900: 214 25% 12%; /* Success, Warning, Danger */ --success-50: 145 80% 96%; --success-500: 160 84% 29%; --warning-50: 48 100% 96%; --warning-500: 36 100% 48%; --danger-50: 0 100% 97%; --danger-500: 0 84% 60%; /* Radius */ --radius: 0.5rem; } .dark { /* Base colors */ --background: 224 71% 4%; --foreground: 213 31% 91%; /* Card */ --card: 224 71% 4%; --card-foreground: 213 31% 91%; /* Popover */ --popover: 224 71% 4%; --popover-foreground: 213 31% 91%; /* Primary (slightly lighter for dark mode) */ --primary-50: 214 100% 97%; --primary-100: 213 96% 87%; --primary-200: 212 93% 76%; --primary-300: 212 96% 62%; --primary-400: 213 94% 56%; --primary-500: 213 90% 50%; /* Lighter in dark mode */ --primary-600: 212 100% 45%; --primary-700: 211 100% 40%; --primary-800: 211 100% 35%; --primary-900: 211 100% 30%; --primary: 213 90% 50%; --primary-foreground: 0 0% 98%; /* Secondary (adjusted for dark mode) */ --secondary: 272 100% 70%; /* Lighter in dark mode */ --secondary-foreground: 0 0% 98%; /* Muted */ --muted: 223 47% 11%; --muted-foreground: 215.4 16.3% 56.9%; /* Accent */ --accent: 216 34% 17%; --accent-foreground: 210 40% 98%; /* Destructive */ --destructive: 0 63% 31%; --destructive-foreground: 210 40% 98%; /* Border, Input, Ring */ --border: 216 34% 17%; --input: 216 34% 17%; --ring: 213 31% 91%; /* Success, Warning, Danger (darker for dark mode) */ --success-50: 145 80% 96%; --success-500: 160 84% 39%; --warning-50: 48 100% 96%; --warning-500: 36 100% 58%; --danger-50: 0 100% 97%; --danger-500: 0 84% 70%; } } @layer base { * { @apply border-border; } body { @apply font-sans antialiased bg-background text-foreground; font-feature-settings: "rlig" 1, "calt" 1; } /* Custom scrollbar */ *::-webkit-scrollbar { width: 8px; height: 8px; } *::-webkit-scrollbar-track { background: hsl(var(--muted)); border-radius: 4px; } *::-webkit-scrollbar-thumb { background: hsl(var(--muted-foreground) / 0.4); border-radius: 4px; } *::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground) / 0.6); } } .font-mono { font-family: 'JetBrains Mono', monospace; }
5
+ <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Advanced RAG Implementation</title> <script src="https://cdn.tailwindcss.com"></script> <script> tailwind.config = { theme: { extend: { colors: { background: 'hsl(var(--background))', foreground: 'hsl(var(--foreground))', card: 'hsl(var(--card))', cardForeground: 'hsl(var(--card-foreground))', primary: { 50: 'hsl(var(--primary-50))', 100: 'hsl(var(--primary-100))', 200: 'hsl(var(--primary-200))', 300: 'hsl(var(--primary-300))', 400: 'hsl(var(--primary-400))', 500: 'hsl(var(--primary-500))', 600: 'hsl(var(--primary-600))', 700: 'hsl(var(--primary-700))', 800: 'hsl(var(--primary-800))', 900: 'hsl(var(--primary-900))', DEFAULT: 'hsl(var(--primary))', foreground: 'hsl(var(--primary-foreground))' }, secondary: { 50: 'hsl(var(--secondary-50))', 100: 'hsl(var(--secondary-100))', 200: 'hsl(var(--secondary-200))', 300: 'hsl(var(--secondary-300))', 400: 'hsl(var(--secondary-400))', 500: 'hsl(var(--secondary-500))', 600: 'hsl(var(--secondary-600))', 700: 'hsl(var(--secondary-700))', 800: 'hsl(var(--secondary-800))', 900: 'hsl(var(--secondary-900))', DEFAULT: 'hsl(var(--secondary))', foreground: 'hsl(var(--secondary-foreground))' }, muted: 'hsl(var(--muted))', mutedForeground: 'hsl(var(--muted-foreground))', accent: 'hsl(var(--accent))', accentForeground: 'hsl(var(--accent-foreground))', destructive: 'hsl(var(--destructive))', destructiveForeground: 'hsl(var(--destructive-foreground))', border: 'hsl(var(--border))', input: 'hsl(var(--input))', ring: 'hsl(var(--ring))', success: { 50: 'hsl(var(--success-50))', 500: 'hsl(var(--success-500))' }, warning: { 50: 'hsl(var(--warning-50))', 500: 'hsl(var(--warning-500))' }, danger: { 50: 'hsl(var(--danger-50))', 500: 'hsl(var(--danger-500))' }, neutral: { 50: 'hsl(var(--neutral-50))', 100: 'hsl(var(--neutral-100))', 200: 'hsl(var(--neutral-200))', 300: 'hsl(var(--neutral-300))', 400: 'hsl(var(--neutral-400))', 500: 'hsl(var(--neutral-500))', 600: 'hsl(var(--neutral-600))', 700: 'hsl(var(--neutral-700))', 800: 'hsl(var(--neutral-800))', 900: 'hsl(var(--neutral-900))' } }, borderRadius: { DEFAULT: 'var(--radius)' } } } }; </script> <style> :root { --background: 0 0% 98%; --foreground: 20 14.3% 4.1%; --card: 0 0% 100%; --card-foreground: 20 14.3% 4.1%; --popover: 0 0% 100%; --popover-foreground: 20 14.3% 4.1%; --primary: 213 90% 45%; --primary-foreground: 0 0% 98%; --secondary: 272 100% 54%; --secondary-foreground: 0 0% 98%; --muted: 210 40% 96.1%; --muted-foreground: 215.4 16.3% 46.9%; --accent: 210 40% 96.1%; --accent-foreground: 222.2 47.4% 11.2%; --destructive: 0 84.2% 60.2%; --destructive-foreground: 210 40% 98%; --border: 214.3 31.8% 91.4%; --input: 214.3 31.8% 91.4%; --ring: 222.2 84% 4.9%; --radius: 0.5rem; } .dark { --background: 224 71% 4%; --foreground: 213 31% 91%; --card: 224 71% 4%; --card-foreground: 213 31% 91%; --popover: 224 71% 4%; --popover-foreground: 213 31% 91%; --primary: 213 90% 50%; --primary-foreground: 0 0% 98%; --secondary: 272 100% 70%; --secondary-foreground: 0 0% 98%; --muted: 223 47% 11%; --muted-foreground: 215.4 16.3% 56.9%; --accent: 216 34% 17%; --accent-foreground: 210 40% 98%; --destructive: 0 63% 31%; --destructive-foreground: 210 40% 98%; --border: 216 34% 17%; --input: 216 34% 17%; --ring: 213 31% 91%; --success-500: 160 84% 39%; --warning-500: 36 100% 58%; --danger-500: 0 84% 70%; } * { border-color: hsl(var(--border)); } body { font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", "Noto Color Emoji"; -webkit-font-smoothing: antialiased; background-color: hsl(var(--background)); color: hsl(var(--foreground)); font-feature-settings: "rlig" 1, "calt" 1; } .font-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace; } *::-webkit-scrollbar { width: 8px; height: 8px; } *::-webkit-scrollbar-track { background: hsl(var(--muted)); border-radius: 4px; } *::-webkit-scrollbar-thumb { background: hsl(var(--muted-foreground) / 0.4); border-radius: 4px; } *::-webkit-scrollbar-thumb:hover { background: hsl(var(--muted-foreground) / 0.6); } </style> </head> <body class="min-h-screen"> <div id="root"></div> <script> // Mock React-like components class Component { constructor(props) { this.props = props; } } class Switch extends Component { constructor(props) { super(props); this.routes = []; this.defaultRoute = null; } addRoute(route) { if (route.props.path) { this.routes.push(route); } else { this.defaultRoute = route; } } render() { const path = window.location.pathname; const matchedRoute = this.routes.find(route => route.props.path === path); return matchedRoute ? matchedRoute.render() : this.defaultRoute?.render() || document.createElement('div'); } } class Route extends Component { render() { return typeof this.props.component === 'function' ? new this.props.component().render() : document.createElement('div'); } } class QueryClientProvider extends Component { render() { return this.props.children; } } class TooltipProvider extends Component { render() { return this.props.children; } } class ThemeProvider extends Component { constructor(props) { super(props); this.theme = localStorage.getItem(this.props.storageKey) || this.props.defaultTheme || 'light'; this.updateBodyClass(); } updateBodyClass() { if (this.theme === 'dark') { document.documentElement.classList.add('dark'); } else { document.documentElement.classList.remove('dark'); } this.updateMetaThemeColor(); } updateMetaThemeColor() { const color = this.theme === 'dark' ? '#1a1a1a' : '#ffffff'; document.querySelector('meta[name="theme-color"]').content = color; } toggleTheme() { this.theme = this.theme === 'dark' ? 'light' : 'dark'; localStorage.setItem(this.props.storageKey, this.theme); this.updateBodyClass(); } render() { return this.props.children; } } class Header { render() { const header = document.createElement('header'); header.className = 'border-b border-border py-4 px-6'; header.innerHTML = ` <div class="flex items-center justify-between"> <h1 class="text-xl font-bold">Advanced RAG Implementation</h1> <button id="themeToggle" class="p-2 rounded-md hover:bg-accent"> <svg xmlns="http://www.w3.org/2000/svg" width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <circle cx="12" cy="12" r="5"></circle> <line x1="12" y1="1" x2="12" y2="3"></line> <line x1="12" y1="21" x2="12" y2="23"></line> <line x1="4.22" y1="4.22" x2="5.64" y2="5.64"></line> <line x1="18.36" y1="18.36" x2="19.78" y2="19.78"></line> <line x1="1" y1="12" x2="3" y2="12"></line> <line x1="21" y1="12" x2="23" y2="12"></line> <line x1="4.22" y1="19.78" x2="5.64" y2="18.36"></line> <line x1="18.36" y1="5.64" x2="19.78" y2="4.22"></line> </svg> </button> </div> `; return header; } } class Footer { render() { const footer = document.createElement('footer'); footer.className = 'border-t border-border py-4 px-6 mt-auto'; footer.innerHTML = ` <div class="text-center text-sm text-muted-foreground"> © 2024 Advanced RAG Implementation </div> `; return footer; } } class Toaster { render() { return document.createElement('div'); } } class NotFound { render() { const div = document.createElement('div'); div.className = 'flex flex-col items-center justify-center h-full p-8'; div.innerHTML = ` <h1 class="text-4xl font-bold mb-4">404 Not Found</h1> <p class="text-lg mb-6">The page you're looking for doesn't exist.</p> <a href="/" class="px-4 py-2 bg-primary text-primary-foreground rounded-md hover:bg-primary/90 transition-colors"> Go Home </a> `; return div; } } class Home { render() { const div = document.createElement('div'); div.className = 'container mx-auto p-8'; div.innerHTML = ` <div class="max-w-4xl mx-auto"> <h1 class="text-3xl font-bold mb-6">Advanced RAG Implementation</h1> <div class="bg-card border rounded-lg shadow-sm p-6 mb-8"> <h2 class="text-xl font-semibold mb-4">Document Processing Pipeline</h2> <p class="text-muted-foreground mb-6">High-performance multimodal RAG pipeline optimized for construction document analysis.</p> <div class="space-y-6"> <div class="flex items-start space-x-4"> <div class="bg-primary/10 p-3 rounded-lg"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M14.5 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V7.5L14.5 2z"></path> <polyline points="14 2 14 8 20 8"></polyline> </svg> </div> <div> <h3 class="font-medium">Document Ingestion</h3> <p class="text-sm text-muted-foreground">Upload PDFs, DOCX, images, and scans for processing.</p> </div> </div> <div class="flex items-start space-x-4"> <div class="bg-primary/10 p-3 rounded-lg"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M12 20h9"></path> <path d="M16.5 3.5a2.121 2.121 0 0 1 3 3L7 19l-4 1 1-4L16.5 3.5z"></path> </svg> </div> <div> <h3 class="font-medium">Multimodal Extraction</h3> <p class="text-sm text-muted-foreground">Text, tables, and diagrams extracted with LLM-assisted parsing.</p> </div> </div> <div class="flex items-start space-x-4"> <div class="bg-primary/10 p-3 rounded-lg"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z"></path> <line x1="4" y1="22" x2="4" y2="15"></line> </svg> </div> <div> <h3 class="font-medium">Validation Framework</h3> <p class="text-sm text-muted-foreground">Multi-layer verification ensures data quality and consistency.</p> </div> </div> <div class="flex items-start space-x-4"> <div class="bg-primary/10 p-3 rounded-lg"> <svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"> <path d="M2 3h6a4 4 0 0 1 4 4v14a3 3 0 0 0-3-3H2z"></path> <path d="M22 3h-6a4 4 0 0 0-4 4v14a3 3 0 0 1 3-3h7z"></path> </svg> </div> <div> <h3 class="font-medium">RAG Indexing</h3> <p class="text-sm text-muted-foreground">Semantic embeddings stored in optimized FAISS vectors.</p> </div> </div> </div> </div> <div class="grid md:grid-cols-2 gap-6"> <div class="bg-card border rounded-lg shadow-sm p-6"> <h2 class="text-xl font-semibold mb-4">Processing Performance</h2> <div class="space-y-4"> <div> <div class="flex justify-between mb-1"> <span class="text-sm font-medium">5-page document</span> <span class="text-sm text-muted-foreground">8.2s</span> </div> <div class="w-full bg-secondary/10 h-2 rounded-full"> <div class="bg-primary h-2 rounded-full" style="width: 85%"></div> </div> </div> <div> <div class="flex justify-between mb-1"> <span class="text-sm font-medium">20-page document</span> <span class="text-sm text-muted-foreground">22.4s</span> </div> <div class="w-full bg-secondary/10 h-2 rounded-full"> <div class="bg-primary h-2 rounded-full" style="width: 75%"></div> </div> </div> <div> <div class="flex justify-between mb-1"> <span class="text-sm font-medium">50-page document</span> <span class="text-sm text-muted-foreground">51.1s</span> </div> <div class="w-full bg-secondary/10 h-2 rounded-full"> <div class="bg-primary h-2 rounded-full" style="width: 65%"></div> </div> </div> </div> </div> <div class="bg-card border rounded-lg shadow-sm p-6"> <h2 class="text-xl font-semibold mb-4">Model Comparison</h2> <div class="space-y-4"> <div> <div class="flex justify-between mb-1"> <span class="text-sm font-medium">Gemini Pro</span> <span class="text-sm text-muted-foreground">22.4s (20 pages)</span> </div> <div class="w-full bg-secondary/10 h-2 rounded-full"> <div class="bg-primary h-2 rounded-full" style="width: 75%"></div> </div> </div> <div> <div class="flex justify-between mb-1"> <span class="text-sm font-medium">Qwen-72B</span> <span class="text-sm text-muted-foreground">24.7s (20 pages)</span> </div> <div class="w-full bg-secondary/10 h-2 rounded-full"> <div class="bg-primary h-2 rounded-full" style="width: 70%"></div> </div> </div> <div> <div class="flex justify-between mb-1"> <span class="text-sm font-medium">DeepSeek-67B</span> <span class="text-sm text-muted-foreground">19.5s (20 pages)</span> </div> <div class="w-full bg-secondary/10 h-2 rounded-full"> <div class="bg-primary h-2 rounded-full" style="width: 80%"></div> </div> </div> </div> </div> </div> </div> `; return div; } } class Router { render() { const switchComponent = new Switch({}); switchComponent.addRoute(new Route({ path: '/', component: Home })); switchComponent.addRoute(new Route({ component: NotFound })); return switchComponent.render(); } } class App { constructor() { this.themeProvider = new ThemeProvider({ defaultTheme: 'light', storageKey: 'hugging-rag-theme' }); this.metaThemeColor = document.createElement('meta'); this.metaThemeColor.name = 'theme-color'; this.metaThemeColor.content = '#ffffff'; document.head.appendChild(this.metaThemeColor); this.cleanup = () => { document.head.removeChild(this.metaThemeColor); }; } render() { const rootDiv = document.createElement('div'); rootDiv.className = 'flex flex-col min-h-screen bg-background text-foreground font-sans'; const header = new Header(); const router = new Router(); const footer = new Footer(); const toaster = new Toaster(); const mainContent = document.createElement('main'); mainContent.className = 'flex-1'; mainContent.appendChild(router.render()); rootDiv.appendChild(header.render()); rootDiv.appendChild(mainContent); rootDiv.appendChild(footer.render()); rootDiv.appendChild(toaster.render()); // Attach theme toggle after DOM is built setTimeout(() => { const themeToggle = rootDiv.querySelector('#themeToggle'); if (themeToggle) { themeToggle.addEventListener('click', () => { this.themeProvider.toggleTheme(); }); } }, 0); return rootDiv; } } document.addEventListener('DOMContentLoaded', () => { const root = document.getElementById('root'); const app = new App(); root.appendChild(app.render()); window.addEventListener('unload', () => { app.cleanup(); }); }); </script> </body> </html>
6
+ can you just enhance the ui/ux removing the instruction and warning in it without changing any functions in it also enhance the ui to be modern """"Main entry point for the app. This app is generated based on your prompt in Vertex AI Studio using Google GenAI Python SDK (https://googleapis.github.io/python-genai/) and Gradio (https://www.gradio.app/). You can customize the app by editing the code in Cloud Run source code editor. You can also update the prompt in Vertex AI Studio and redeploy it. """ import base64 from google import genai from google.genai import types import gradio as gr import utils def generate( message, history: list[gr.ChatMessage], request: gr.Request ): """Function to call the model based on the request.""" validate_key_result = utils.validate_key(request) if validate_key_result is not None: yield validate_key_result return client = genai.Client( vertexai=True, project="ofworks-459904", location="us-central1", ) si_text1 = types.Part.from_text(text=f"""```You are **ContractIntellect AI**, a specialized assistant for the Project Management team of **the Ibn Battuda Gate project**. Your primary function is to provide accurate, timely, and context-aware assistance regarding all contractual matters related to this project. You will play the role of an advanced reasoning-based problem-solving expert for contract analysis. **Your Knowledge Base:** You have been exclusively linked with an indexed RAG (Retrieval Augmented Generation) dataset containing all contracts, Annual Maintenance Contracts (AMCs), Local Purchase Orders (LPOs), amendments, addendums, and other relevant contractual documents for **the Ibn Battuda Gate** project. Your responses MUST be based *solely* on the information contained within these documents. **Core Responsibilities:** 1. **Query Resolution:** Accurately answer specific questions and clarify doubts posed by the Project Management team. Queries can cover any aspect of the contracts, including but not limited to:   *  Scope of Work & Deliverables   *  Payment Terms, Schedules, and Amounts   *  Contract Duration, Key Dates, and Deadlines   *  Insurance Requirements (types, coverage amounts, beneficiaries)   *  Warranty Terms (duration, scope, claim process)   *  Liability Clauses and Indemnification   *  Termination Clauses (conditions, notice periods)   *  Dispute Resolution Mechanisms   *  Confidentiality Obligations   *  Reporting Requirements   *  Change Order Processes   *  Specific obligations of any party involved. 2. **Document Retrieval and Analysis (Powered by Advanced Reasoning):**   *  Upon receiving a query, use the RAG system to identify and retrieve the most relevant document(s) or sections of documents.   *  Employ the advanced internal reasoning process (detailed below) to thoroughly analyze the retrieved content and extract the precise information needed. 3. **Information Synthesis:** If information is spread across multiple clauses or documents (e.g., an LPO referencing a Master Agreement), synthesize the information to provide a comprehensive answer, guided by your internal reasoning. 4. **Follow-up Handling:** Maintain context from the current conversation to effectively address follow-up questions and requests for further clarification, using your internal reasoning to connect new queries with previous findings. **Advanced Internal Reasoning Process (`<inner_thoughts>`):** Before providing a final answer, you MUST engage in a detailed internal reasoning process. This process should be encapsulated within `<inner_thoughts></inner_thoughts>` tags. This section is for your internal \"thinking\" and will not be directly visible to the user but is crucial for arriving at accurate and well-supported answers. Follow these steps in your `<inner_thoughts>`: 1. **Deconstruct the Query (Step-by-step reasoning):**   *  Start with the user's problem/query and **break it down** into its fundamental components.   *  Identify the specific contractual aspect(s) being questioned (e.g., \"warranty duration for item X,\" \"payment milestone for phase Y\").   *  Clearly explain your reasoning at each step of deconstruction. 2. **Formulate Search Hypotheses & Test with RAG:**   *  Propose hypotheses about which document(s) or section(s) are likely to contain the relevant information (e.g., \"The warranty for specialized equipment is likely in the AMC or a specific LPO addendum, not just the main contract.\").   *  Use the RAG system to test these hypotheses by retrieving relevant documents.   *  Analyze the retrieved snippets. If a hypothesis fails (e.g., information not found where expected), adjust your hypothesis and explore alternative document types or search queries. **Break complex search steps into simpler ones.** 3. **Iterative Refinement & Thought Jumps:**   *  If new ideas, connections to other clauses, or potential ambiguities arise during analysis, revisit earlier steps in your reasoning. Explain *why* you are revisiting.   *  When trying different approaches to find or interpret information, note why previous attempts or interpretations were insufficient or incorrect based on further document evidence. 4. **Heavy Self-Doubt & Critical Scrutiny:**   *  **Always assume previous reasoning steps might contain flaws.** Actively try to spot errors or omissions in your understanding or in the information retrieved.   *  NEVER BLINDLY AGREE ON PREVIOUS REASONINGS.   *  If a potential answer is found, try your hardest to negate it or find contradictory information within the document set. Ask yourself: \"Is this the *complete* picture? Could an amendment, addendum, or a different section change this interpretation? Is there any ambiguity in the wording?\"   *  This self-doubt must be resolved by finding further *documentary evidence*, not by speculation. 5. **Systematic Exploration (Tree-like Path Search):**   *  Your contemplation process should mimic a tree search. List potential documents or clauses to check as branches.   *  Identify successful retrievals or key interpretive breakthroughs as checkpoints for further exploration.   *  **Always double-check retrieved information against other potentially relevant sections or documents before moving on.** For example, if a clause in an LPO seems relevant, check if the Master Agreement has an overriding clause. 6. **Quantitative & Detail-Oriented Thinking:**   *  If numbers, dates, durations, amounts, or specific defined terms are involved, break the problem down into verifying these precise details from the contracts.   *  Pay meticulous attention to units, currency, specific conditions attached to figures, and definitions provided within the contracts. 7. **Formatting within `<inner_thoughts>`:**   *  Each paragraph should ideally contain only one short sentence, handling one small reasoning step to ensure clarity and granularity in your thought process.   *  Be extremely detailed and thorough in your `inner_thoughts`. Do not rush to a conclusion. Explore all plausible avenues within the RAG data. **Operational Guidelines (for the `<final_answer>`):** *  **Accuracy First:** Your absolute priority is accuracy. All information provided in the `<final_answer>` must be directly traceable to the indexed contractual documents and validated through your `inner_thoughts` process. *  **No Speculation:** DO NOT provide opinions, advice, legal interpretations (unless explicitly stated as such *within* a document and cited), or information not found in the provided RAG dataset. If information is not available after thorough internal searching, clearly state that in the `<final_answer>`. *  **Cite Your Sources:** For every substantive piece of information you provide in the `<final_answer>`, you MUST cite the source document(s) and, where possible, the specific clause number, section, page, or exhibit. (e.g., \"As per Clause 5.2 of the Master Services Agreement (Doc ID: MSA_IbnBattudaGate_V2), the payment term is Net 30 days.\") *  **Clarity and Precision:** Provide clear, concise, and unambiguous answers in the `<final_answer>`. If a query was ambiguous, your `inner_thoughts` should explore this, and you might ask for clarification or present interpretations based on evidence in the `<final_answer>`. *  **Professional Tone:** Maintain a helpful, professional, and objective tone in the `<final_answer>`. *  **Data Confidentiality:** Treat all contract information as highly confidential. *  **Handling Missing or Conflicting Information (in `<final_answer>`):**   *  If, after exhaustive internal searching documented in your `<inner_thoughts>`, the requested information cannot be found, state: \"Based on a thorough review of the available project contracts for Ibn Battuda Gate, I could not find specific information regarding [topic].\"   *  If conflicting information is found across different documents (and explored in `<inner_thoughts>`), present both pieces of information in the `<final_answer>`, cite their respective sources, and note the discrepancy. (e.g., \"LPO #123, Section 3, states a warranty of 12 months, while the overarching AMC (Doc ID: AMC_IBG_001), Clause 8.1, specifies a 24-month warranty for similar equipment for the Ibn Battuda Gate project. Please review these conflicting terms.\") **Output Format:** For every user query, your complete response will be structured as follows. The `<inner_thoughts>` section is for your internal processing and, while generated by you, may not be visible to the end-user depending on the platform. The `<final_answer>` is what the user will see. ``` <inner_thoughts> (Your detailed, step-by-step reasoning, hypothesis testing, self-correction, and document analysis as described in \"Advanced Internal Reasoning Process\" goes here. This section can be very long and detailed.) (Example reasoning step: First, I need to understand what \"liquidated damages for delay\" means in this context.) (Example reasoning step: The user is asking about the Main Construction Contract.) (Example reasoning step: Hypothesis: Clause X.Y in MCC_IbnBattudaGate_Final_2023 should cover this.) (Example reasoning step: Retrieving Clause X.Y from MCC_IbnBattudaGate_Final_2023 via RAG.) (Example reasoning step: Analysis: Clause X.Y states [retrieved text]. This seems relevant.) (Example reasoning step: Self-doubt: Is there an amendment that modifies this clause? Checking amendment register.) (Example reasoning step: Found Amendment_002. Clause 2.1 of Amendment_002 supersedes Clause X.Y of the original MCC.) (Example reasoning step: Re-evaluating based on Amendment_002.) </inner_thoughts> <final_answer> (Your clear, concise, and cited answer to the user, based on the conclusions from your inner_thoughts, goes here.) (Example: \"Regarding liquidated damages for delay under the Main Construction Contract for the Ibn Battuda Gate project, Clause 2.1 of Amendment_002 (Doc ID: AMND_IBG_002), which supersedes Clause X.Y of the original Main Construction Contract (Doc ID: MCC_IbnBattudaGate_Final_2023), states that [paraphrased and cited information from the amendment].\") </final_answer> ``` **Interaction Example (Illustrating the final output visible to user):** *  **User:** \"What is the insurance requirement for public liability for the main contractor on the Ibn Battuda Gate project?\" *  **AI (after internal `<inner_thoughts>` process):**   `<final_answer>`   According to Clause 15.1(b) of the Main Construction Contract (Doc ID: MCC_IbnBattudaGate_Final_2023), for the Ibn Battuda Gate project, the main contractor is required to maintain Public Liability insurance with a minimum coverage of [Amount] per occurrence. This is further detailed in Schedule C (Insurance Requirements) of the same document.   `</final_answer>` **Your Goal:** To be an indispensable, reliable, and efficient resource for the Project Management team of the Ibn Battuda Gate project, enabling them to quickly understand and navigate the complexities of the project's contractual landscape through meticulously reasoned and evidence-backed insights. ```""") model = "gemini-2.5-pro-preview-05-06" contents = [ types.Content( role="user", parts=[ types.Part.from_text(text=f"""please output the final answer only""") ] ), ] for prev_msg in history: role = "user" if prev_msg["role"] == "user" else "model" parts = utils.get_parts_from_message(prev_msg["content"]) if parts: contents.append(types.Content(role=role, parts=parts)) if message: contents.append( types.Content(role="user", parts=utils.get_parts_from_message(message)) ) tools = [ types.Tool( retrieval=types.Retrieval( vertex_ai_search=types.VertexAISearch(datastore="projects/192173602605/locations/global/collections/default_collection/dataStores/ibgob_1747327921187") ) ), ] generate_content_config = types.GenerateContentConfig( temperature=1, top_p=0.95, seed=0, max_output_tokens=4096, safety_settings=[ types.SafetySetting( category="HARM_CATEGORY_HATE_SPEECH", threshold="OFF" ), types.SafetySetting( category="HARM_CATEGORY_DANGEROUS_CONTENT", threshold="OFF" ), types.SafetySetting( category="HARM_CATEGORY_SEXUALLY_EXPLICIT", threshold="OFF" ), types.SafetySetting( category="HARM_CATEGORY_HARASSMENT", threshold="OFF" ) ], tools=tools, system_instruction=[si_text1], ) results = [] for chunk in client.models.generate_content_stream( model=model, contents=contents, config=generate_content_config, ): if chunk.candidates and chunk.candidates[0] and chunk.candidates[0].content: results.extend( utils.convert_content_to_gr_type(chunk.candidates[0].content) ) if results: yield results with gr.Blocks(theme=utils.custom_theme) as demo: with gr.Row(): gr.HTML(utils.public_access_warning) with gr.Row(): with gr.Column(scale=1): with gr.Row(): gr.HTML("<h2>Welcome to Vertex AI GenAI App!</h2>") with gr.Row(): gr.HTML("""This prototype was built using your Vertex AI Studio prompt. Follow the steps and recommendations below to begin.""") with gr.Row(): gr.HTML(utils.next_steps_html) with gr.Column(scale=2, variant="panel"): gr.ChatInterface( fn=generate, title="ContractIntellect AI for Ibn Battuda Gate", type="messages", multimodal=True, ) demo.launch(show_error=True)"