Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -215,47 +215,60 @@ def clear_kb(user_id="demo"):
|
|
| 215 |
return f"User ID '{user_id}' not found."
|
| 216 |
|
| 217 |
# ---- UI layout (feel free to tweak cosmetics) -----------------------------
|
|
|
|
| 218 |
with gr.Blocks() as demo:
|
| 219 |
-
gr.Markdown(
|
|
|
|
|
|
|
|
|
|
| 220 |
|
| 221 |
-
# ---- passage ingestion ----
|
| 222 |
with gr.Row():
|
| 223 |
passage_box = gr.Textbox(lines=6, label="Reference passage")
|
| 224 |
-
user_id_box
|
| 225 |
-
|
| 226 |
-
|
| 227 |
-
|
| 228 |
-
|
| 229 |
-
|
| 230 |
-
|
| 231 |
-
|
|
|
|
|
|
|
| 232 |
clear_btn = gr.Button("Clear KB")
|
| 233 |
-
|
|
|
|
| 234 |
status_box = gr.Markdown()
|
| 235 |
|
| 236 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 237 |
|
| 238 |
-
|
| 239 |
-
|
| 240 |
-
|
|
|
|
|
|
|
| 241 |
|
| 242 |
-
# ---- Q
|
| 243 |
question_box = gr.Textbox(lines=2, label="Ask a question")
|
| 244 |
history_cb = gr.Textbox(value="None", label="Use chat history")
|
| 245 |
system_box = gr.Textbox(lines=2, label="System prompt")
|
| 246 |
context_box = gr.Textbox(lines=6, label="Context passages")
|
| 247 |
|
| 248 |
-
#
|
| 249 |
-
temp_box
|
| 250 |
-
|
| 251 |
-
topp_box
|
| 252 |
-
|
| 253 |
-
topk_box
|
| 254 |
-
|
| 255 |
-
# ---------- /NEW ----------
|
| 256 |
|
| 257 |
-
answer_btn
|
| 258 |
-
answer_box
|
| 259 |
|
| 260 |
answer_btn.click(
|
| 261 |
fn=answer,
|
|
@@ -265,6 +278,7 @@ with gr.Blocks() as demo:
|
|
| 265 |
outputs=answer_box
|
| 266 |
)
|
| 267 |
|
|
|
|
| 268 |
# ---------- 3. FastAPI layer --------------------------------------------------
|
| 269 |
class IngestReq(BaseModel):
|
| 270 |
user_id:str
|
|
|
|
| 215 |
return f"User ID '{user_id}' not found."
|
| 216 |
|
| 217 |
# ---- UI layout (feel free to tweak cosmetics) -----------------------------
|
| 218 |
+
# ---- UI layout -----------------------------------------------------
|
| 219 |
with gr.Blocks() as demo:
|
| 220 |
+
gr.Markdown(
|
| 221 |
+
"### Tiny-RAG playground – 1) paste a passage → **Store** · "
|
| 222 |
+
"2) ask a question → **Answer**"
|
| 223 |
+
)
|
| 224 |
|
| 225 |
+
# ---------- passage ingestion ----------
|
| 226 |
with gr.Row():
|
| 227 |
passage_box = gr.Textbox(lines=6, label="Reference passage")
|
| 228 |
+
user_id_box = gr.Textbox(value="demo", label="User ID")
|
| 229 |
+
|
| 230 |
+
# NEW chunking knobs
|
| 231 |
+
chunk_box = gr.Slider(128, 2048, value=DEFAULT_CHUNK_SIZE,
|
| 232 |
+
step=64, label="Chunk size (chars)")
|
| 233 |
+
overlap_box = gr.Slider(0, 1024, value=DEFAULT_CHUNK_OVERLAP,
|
| 234 |
+
step=32, label="Chunk overlap")
|
| 235 |
+
|
| 236 |
+
# buttons (declare *before* you use them)
|
| 237 |
+
store_btn = gr.Button("Store passage")
|
| 238 |
clear_btn = gr.Button("Clear KB")
|
| 239 |
+
|
| 240 |
+
# status line (defined before we wire handlers)
|
| 241 |
status_box = gr.Markdown()
|
| 242 |
|
| 243 |
+
# wire up buttons -----------------------
|
| 244 |
+
store_btn.click(
|
| 245 |
+
fn=store_doc,
|
| 246 |
+
inputs=[passage_box, user_id_box, chunk_box, overlap_box],
|
| 247 |
+
outputs=status_box
|
| 248 |
+
)
|
| 249 |
|
| 250 |
+
clear_btn.click(
|
| 251 |
+
fn=clear_kb,
|
| 252 |
+
inputs=user_id_box,
|
| 253 |
+
outputs=status_box
|
| 254 |
+
)
|
| 255 |
|
| 256 |
+
# ---------- Q & A ----------
|
| 257 |
question_box = gr.Textbox(lines=2, label="Ask a question")
|
| 258 |
history_cb = gr.Textbox(value="None", label="Use chat history")
|
| 259 |
system_box = gr.Textbox(lines=2, label="System prompt")
|
| 260 |
context_box = gr.Textbox(lines=6, label="Context passages")
|
| 261 |
|
| 262 |
+
# NEW sampling sliders
|
| 263 |
+
temp_box = gr.Slider(0.0, 1.5, value=DEFAULT_TEMP,
|
| 264 |
+
step=0.05, label="Temperature")
|
| 265 |
+
topp_box = gr.Slider(0.0, 1.0, value=DEFAULT_TOP_P,
|
| 266 |
+
step=0.01, label="Top-p")
|
| 267 |
+
topk_box = gr.Slider(1, 100, value=DEFAULT_TOP_K_TOK,
|
| 268 |
+
step=1, label="Top-k (tokens)")
|
|
|
|
| 269 |
|
| 270 |
+
answer_btn = gr.Button("Answer")
|
| 271 |
+
answer_box = gr.Textbox(lines=6, label="Assistant reply")
|
| 272 |
|
| 273 |
answer_btn.click(
|
| 274 |
fn=answer,
|
|
|
|
| 278 |
outputs=answer_box
|
| 279 |
)
|
| 280 |
|
| 281 |
+
|
| 282 |
# ---------- 3. FastAPI layer --------------------------------------------------
|
| 283 |
class IngestReq(BaseModel):
|
| 284 |
user_id:str
|