memorease-llm / app.py
memorease's picture
Update app.py
6259ab9 verified
raw
history blame
1.05 kB
import gradio as gr
import json
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
# Küçük gömme modeli (daha az RAM kullanır)
embedder = SentenceTransformer("paraphrase-MiniLM-L3-v2")
# JSON veri yükle
with open("memory_questions.json", "r") as f:
memory_data = json.load(f)
memory_texts = [item['description'] for item in memory_data]
memory_embeddings = embedder.encode(memory_texts)
def generate_question(user_memory):
user_embedding = embedder.encode([user_memory])
similarities = cosine_similarity(user_embedding, memory_embeddings)[0]
best_match_index = np.argmax(similarities)
return memory_data[best_match_index]['question']
iface = gr.Interface(
fn=generate_question,
inputs=gr.Textbox(label="Your Memory"),
outputs=gr.Textbox(label="Generated Question"),
title="MemoRease - Semantic Memory Question Generator",
description="Find the most semantically similar question from your memory set."
)
iface.launch()