Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -4,31 +4,28 @@ from sentence_transformers import SentenceTransformer
|
|
4 |
from sklearn.metrics.pairwise import cosine_similarity
|
5 |
import numpy as np
|
6 |
|
7 |
-
#
|
8 |
-
embedder = SentenceTransformer("
|
9 |
|
10 |
-
#
|
11 |
with open("memory_questions.json", "r") as f:
|
12 |
memory_data = json.load(f)
|
13 |
|
14 |
-
# 3. Tüm memory'leri embed et (başta bir defa)
|
15 |
memory_texts = [item['description'] for item in memory_data]
|
16 |
memory_embeddings = embedder.encode(memory_texts)
|
17 |
|
18 |
-
# 4. Soru üretme fonksiyonu
|
19 |
def generate_question(user_memory):
|
20 |
user_embedding = embedder.encode([user_memory])
|
21 |
similarities = cosine_similarity(user_embedding, memory_embeddings)[0]
|
22 |
best_match_index = np.argmax(similarities)
|
23 |
return memory_data[best_match_index]['question']
|
24 |
|
25 |
-
# 5. Gradio Arayüzü
|
26 |
iface = gr.Interface(
|
27 |
fn=generate_question,
|
28 |
inputs=gr.Textbox(label="Your Memory"),
|
29 |
outputs=gr.Textbox(label="Generated Question"),
|
30 |
title="MemoRease - Semantic Memory Question Generator",
|
31 |
-
description="
|
32 |
)
|
33 |
|
34 |
iface.launch()
|
|
|
4 |
from sklearn.metrics.pairwise import cosine_similarity
|
5 |
import numpy as np
|
6 |
|
7 |
+
# Küçük gömme modeli (daha az RAM kullanır)
|
8 |
+
embedder = SentenceTransformer("paraphrase-MiniLM-L3-v2")
|
9 |
|
10 |
+
# JSON veri yükle
|
11 |
with open("memory_questions.json", "r") as f:
|
12 |
memory_data = json.load(f)
|
13 |
|
|
|
14 |
memory_texts = [item['description'] for item in memory_data]
|
15 |
memory_embeddings = embedder.encode(memory_texts)
|
16 |
|
|
|
17 |
def generate_question(user_memory):
|
18 |
user_embedding = embedder.encode([user_memory])
|
19 |
similarities = cosine_similarity(user_embedding, memory_embeddings)[0]
|
20 |
best_match_index = np.argmax(similarities)
|
21 |
return memory_data[best_match_index]['question']
|
22 |
|
|
|
23 |
iface = gr.Interface(
|
24 |
fn=generate_question,
|
25 |
inputs=gr.Textbox(label="Your Memory"),
|
26 |
outputs=gr.Textbox(label="Generated Question"),
|
27 |
title="MemoRease - Semantic Memory Question Generator",
|
28 |
+
description="Find the most semantically similar question from your memory set."
|
29 |
)
|
30 |
|
31 |
iface.launch()
|