This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from llama_index.core import Document, VectorStoreIndex | |
from llama_index.core import Settings | |
import trafilatura | |
class PageSummarizer: | |
def __init__(self, llm, embed_model): | |
self.llm = llm | |
self.embed_model = embed_model | |
def summarize(self, html: str) -> str: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def compute_box(element): | |
location = element.location | |
size = element.size | |
# Coordinates | |
x_coordinate = location['x'] | |
y_coordinate = location['y'] | |
# Size | |
width = size['width'] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from playwright.async_api import async_playwright | |
# Example on how to call these async functions using asyncio | |
import asyncio | |
async def load(): | |
# Example where we connect to a local existing Chrome session in debug mode | |
playwright = await async_playwright().start() | |
browser = await playwright.chromium.connect_over_cdp("http://localhost:9222") | |
default_context = browser.contexts[0] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Inspired from https://github.com/microsoft/onnxruntime/blob/main/onnxruntime/python/tools/transformers/notebooks/Inference_GPT2_with_OnnxRuntime_on_CPU.ipynb | |
def get_example_inputs(example, tokenizer): | |
tokenizer.padding_side = "left" | |
tokenizer.pad_token = tokenizer.eos_token | |
max_length = 64 | |
num_attention_heads, hidden_size, num_layer = 12, 768, 12 | |
encodings_dict = tokenizer.batch_encode_plus(example, padding='max_length', max_length=max_length) |
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@patch_to(CKKSEncoder) | |
def pi(self, z: np.array) -> np.array: | |
"""Projects a vector of H into C^{N/2}.""" | |
N = self.M // 4 | |
return z[:N] | |
@patch_to(CKKSEncoder) | |
def pi_inverse(self, z: np.array) -> np.array: | |
"""Expands a vector of C^{N/2} by expanding it with its |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@patch_to(CKKSEncoder) | |
def compute_basis_coordinates(self, z): | |
"""Computes the coordinates of a vector with respect to the orthogonal lattice basis.""" | |
output = np.array([np.real(np.vdot(z, b) / np.vdot(b,b)) for b in self.sigma_R_basis]) | |
return output | |
def round_coordinates(coordinates): | |
"""Gives the integral rest.""" | |
coordinates = coordinates - np.floor(coordinates) | |
return coordinates |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
p1 = encoder.sigma_inverse(m1) | |
p2 = encoder.sigma_inverse(m2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b_reconstructed = encoder.sigma(p) | |
b_reconstructed |
NewerOlder