Spaces:
Running
Running
Rohit Rajpoot
commited on
Commit
·
64c9182
1
Parent(s):
40f582a
add timing logs & reduce tokens
Browse files
app.py
CHANGED
@@ -65,13 +65,28 @@ with col2:
|
|
65 |
if not title.strip():
|
66 |
st.warning("Please enter a question first.")
|
67 |
else:
|
|
|
|
|
|
|
|
|
|
|
68 |
q_emb = _encoder.encode(title, convert_to_tensor=True)
|
69 |
sims = torch.nn.functional.cosine_similarity(q_emb.unsqueeze(0), passage_embs)
|
70 |
topk = torch.topk(sims, k=min(3, len(passages))).indices.tolist()
|
71 |
context = "\n\n".join(passages[i] for i in topk)
|
72 |
-
|
73 |
-
|
74 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
75 |
st.write(out[0]["generated_text"])
|
76 |
|
77 |
# Embedding Q&A in col3
|
|
|
65 |
if not title.strip():
|
66 |
st.warning("Please enter a question first.")
|
67 |
else:
|
68 |
+
# 1) mark the start
|
69 |
+
t0 = time.time()
|
70 |
+
st.write(f"⏱ Retrieval start: {t0:.1f}s")
|
71 |
+
|
72 |
+
# retrieval
|
73 |
q_emb = _encoder.encode(title, convert_to_tensor=True)
|
74 |
sims = torch.nn.functional.cosine_similarity(q_emb.unsqueeze(0), passage_embs)
|
75 |
topk = torch.topk(sims, k=min(3, len(passages))).indices.tolist()
|
76 |
context = "\n\n".join(passages[i] for i in topk)
|
77 |
+
|
78 |
+
t1 = time.time()
|
79 |
+
st.write(f"⏱ Retrieval done in {t1-t0:.1f}s; generation starting…")
|
80 |
+
|
81 |
+
# 2) generation (reduce tokens for now)
|
82 |
+
out = deepseek_gen(
|
83 |
+
f"Use these notes to answer:\n\n{context}\n\nQ: {title}\nA:",
|
84 |
+
max_new_tokens=20,
|
85 |
+
do_sample=False
|
86 |
+
)
|
87 |
+
|
88 |
+
t2 = time.time()
|
89 |
+
st.write(f"⏱ Generation took {t2-t1:.1f}s (total {t2-t0:.1f}s)")
|
90 |
st.write(out[0]["generated_text"])
|
91 |
|
92 |
# Embedding Q&A in col3
|
assist/__pycache__/__init__.cpython-312.pyc
CHANGED
Binary files a/assist/__pycache__/__init__.cpython-312.pyc and b/assist/__pycache__/__init__.cpython-312.pyc differ
|
|
assist/__pycache__/bayes_chat.cpython-312.pyc
ADDED
Binary file (1.89 kB). View file
|
|
assist/__pycache__/chat.cpython-312.pyc
CHANGED
Binary files a/assist/__pycache__/chat.cpython-312.pyc and b/assist/__pycache__/chat.cpython-312.pyc differ
|
|
assist/__pycache__/transformer_demo.cpython-312.pyc
ADDED
Binary file (3.22 kB). View file
|
|