File size: 1,048 Bytes
ac2fa94
863d80b
830876b
 
 
ac2fa94
6259ab9
 
7efac98
6259ab9
863d80b
 
 
830876b
 
863d80b
830876b
 
 
 
 
8c2067d
ac2fa94
 
 
 
830876b
6259ab9
ac2fa94
 
 
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
32
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()