File size: 1,085 Bytes
ac2fa94
863d80b
830876b
 
 
ac2fa94
8d3bbae
 
7efac98
8d3bbae
863d80b
 
 
830876b
 
863d80b
8d3bbae
830876b
 
 
 
8d3bbae
8c2067d
8d3bbae
ac2fa94
 
 
8d3bbae
 
 
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
33
34
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()