-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmyq1.py
More file actions
31 lines (26 loc) · 949 Bytes
/
Copy pathmyq1.py
File metadata and controls
31 lines (26 loc) · 949 Bytes
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
from openpyxl import load_workbook
file_path = 'myq1.xlsx'
def extract_text_from_excel(file_path):
wb = load_workbook(file_path)
all_text = []
for sheet in wb.worksheets:
print(f"Reading sheet: {sheet.title}")
row_count=0
for row in sheet.iter_rows(values_only=True):
if row_count==15:
break
row_count+=1
row_text = " | ".join([str(cell) for cell in row if cell is not None])
if row_text.strip():
all_text.append(row_text)
return "\n".join(all_text)
file_path = 'myq1.xlsx'
extracted_text = extract_text_from_excel(file_path)
print(extracted_text)
#Embedding:
from sentence_transformers import SentenceTransformer
model = SentenceTransformer("all-MiniLM-L6-v2") # Small and fast
excel_text=extract_text_from_excel(file_path)
embeddings=model.encode([excel_text])
print("The embedding for the text is:\n")
print(embeddings)