memorease-llm / app.py
memorease's picture
Update app.py
8d3bbae verified
import gradio as gr
import json
from sentence_transformers import SentenceTransformer
from sklearn.metrics.pairwise import cosine_similarity
import numpy as np
# Semantik model
embedder = SentenceTransformer("paraphrase-MiniLM-L3-v2")
# 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)
# Yalnızca eşleşen soruyu döndür
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']
# Arayüz
iface = gr.Interface(
fn=generate_question,
inputs=gr.Textbox(label="Your Memory"),
outputs=gr.Textbox(label="Matched Question"),
title="MemoRease – Smart Matched Question (No Hallucination)",
description="Enter a memory. You'll get the most relevant pre-written question from your dataset."
)
iface.launch()