Spaces:
Sleeping
Sleeping
| from google.genai import Client, types | |
| import os | |
| import numpy as np | |
| from sentence_transformers import SentenceTransformer, util | |
| from dotenv import load_dotenv | |
| load_dotenv() | |
| def text_to_saoke(data): | |
| saoke_list = [] | |
| for d in data: | |
| prompt = get_prompt() | |
| prompt += d | |
| result = send_request(prompt) | |
| saoke_list.append(result) | |
| return saoke_list | |
| def text_to_embeddings(list1, list2, model): | |
| embeddings1 = [] | |
| for l1 in list1: | |
| embeddings1.append(model.encode(l1)) | |
| embeddings2 = [] | |
| for l2 in list2: | |
| embeddings2.append(model.encode(l2)) | |
| return embeddings1, embeddings2 | |
| def embeddings_to_matrix(embeddings1, embeddings2): | |
| matrix = [] | |
| for e1 in embeddings1: | |
| for e2 in embeddings2: | |
| cosim = util.cos_sim(e1, e2) | |
| matrix.append(cosim) | |
| matrix = np.array(matrix).reshape(len(embeddings1), len(embeddings2)) | |
| return matrix.tolist() | |
| def send_request(prompt): | |
| client = Client(api_key=os.getenv("GEMINI_API_KEY")) | |
| response = client.models.generate_content( | |
| model="gemini-2.5-flash", | |
| contents=prompt, | |
| ) | |
| return response.text | |
| def get_prompt(): | |
| prompt = """ | |
| You are well educated in S-A-O-K-E decomposition methodology applied to patents: | |
| **Subject (S):** The entity that performs the action (e.g., device, user, system). | |
| **Action (A):** This represents the specific intervention, process, or method that the invention performs. It describes what the invention *does* to or with specific objects or systems (e.g., transmits, applies, mixes). | |
| **Object (O):** The entity or target that the action is performed upon (e.g., signal, data, mixture). | |
| **Knowledge (K):** This is the body of technical and scientific information that underpins the invention. It is the knowledge that is necessary to design, implement, and operate the action successfully. | |
| **Effect (E):** This refers to the outcome, result, or consequence of the action. It describes the benefit, improvement, or new capability that the invention provides. | |
| the entire invention can be mapped as a linked set of S-A–O-K–E units. For example: | |
| Step 1: (S₁, A₁, O₁, K₁) → E₁ | |
| Step 2: (S₂,A₂, O₂, K₂=E₁+...) → E₂ | |
| ...and so on. | |
| You mission is to help the user write and analyse their ideas, concept, inventions, problems etc... in the form of S-A-O-K-E. | |
| You must output a JSON object containings all of the SAOKE: | |
| { | |
| "subject": "Mobile payment app", | |
| "action": "interlaces affine and non-linear lookup tables", | |
| "object": "AES state bytes", | |
| "knowledge": "space-hard SPNbox design using table incompressibility theory", | |
| "effect": "prevents code-lifting and key-extraction even under full memory disclosure." | |
| }, | |
| { | |
| "subject": "DRM client", | |
| "action": "randomizes table encodings on every re-installation", | |
| "object": "symmetric key material", | |
| "knowledge": "PUF-bound whitening keys with Even-Mansour construction", | |
| "effect": "renders stolen binaries unusable on non-bound devices." | |
| },... | |
| ### Document | |
| """ | |
| return prompt |