Commit
Β·
c48f9e1
1
Parent(s):
1074e67
fix1
Browse files
app.py
CHANGED
@@ -330,103 +330,73 @@ full_pipeline = hybrid_chain | RunnableAssign({"validation": validation_chain})
|
|
330 |
|
331 |
|
332 |
def chat_interface(message, history):
|
333 |
-
|
334 |
-
|
335 |
-
|
336 |
-
|
337 |
-
|
338 |
-
|
339 |
-
|
340 |
-
|
341 |
-
|
342 |
-
|
343 |
-
|
344 |
-
|
345 |
-
|
346 |
-
|
347 |
-
|
348 |
-
|
349 |
-
# Process through pipeline
|
350 |
-
response = ""
|
351 |
-
for chunk in full_pipeline.stream(inputs):
|
352 |
-
if isinstance(chunk, str):
|
353 |
-
response += chunk
|
354 |
-
elif isinstance(chunk, dict) and "answer" in chunk:
|
355 |
-
response += chunk["answer"]
|
356 |
yield response
|
357 |
-
except Exception as e:
|
358 |
-
yield f"π¨ Error: {str(e)}"
|
359 |
|
360 |
-
# Custom ChatInterface implementation
|
361 |
with gr.Blocks(css="""
|
|
|
|
|
|
|
|
|
|
|
362 |
.gradio-container {
|
363 |
width: 90%;
|
364 |
max-width: 1000px;
|
365 |
margin: 0 auto;
|
366 |
padding: 1rem;
|
367 |
}
|
|
|
368 |
.chatbox-container {
|
369 |
display: flex;
|
370 |
flex-direction: column;
|
371 |
-
height:
|
372 |
}
|
|
|
373 |
.chatbot {
|
374 |
flex: 1;
|
375 |
overflow-y: auto;
|
376 |
min-height: 500px;
|
377 |
}
|
|
|
378 |
.textbox {
|
379 |
margin-top: 1rem;
|
380 |
}
|
|
|
|
|
|
|
381 |
""") as demo:
|
382 |
with gr.Column(elem_classes="chatbox-container"):
|
383 |
gr.Markdown("## π¬ Ask Krishna's AI Assistant")
|
384 |
gr.Markdown("π‘ Ask anything about Krishna Vamsi Dhulipalla")
|
385 |
-
|
386 |
-
|
387 |
-
|
388 |
-
|
389 |
-
|
390 |
-
|
391 |
-
|
392 |
-
gr.Examples(
|
393 |
examples=[
|
394 |
"What are Krishna's research interests?",
|
395 |
"Where did Krishna work?",
|
396 |
-
"What did he study at Virginia Tech?"
|
397 |
],
|
398 |
-
|
399 |
-
label="Example Questions"
|
400 |
)
|
401 |
-
|
402 |
-
def respond(message, chat_history):
|
403 |
-
"""Handle user message and generate response"""
|
404 |
-
bot_message = ""
|
405 |
-
for chunk in chat_interface(message, chat_history):
|
406 |
-
bot_message = chunk
|
407 |
-
# Update last message in history
|
408 |
-
if chat_history and len(chat_history) > 0:
|
409 |
-
chat_history[-1] = (message, bot_message)
|
410 |
-
else:
|
411 |
-
chat_history.append((message, bot_message))
|
412 |
-
yield chat_history
|
413 |
-
|
414 |
-
def user(user_message, history):
|
415 |
-
"""Append user message to history"""
|
416 |
-
return "", history + [[user_message, None]]
|
417 |
-
|
418 |
-
msg.submit(
|
419 |
-
user,
|
420 |
-
[msg, chatbot],
|
421 |
-
[msg, chatbot],
|
422 |
-
queue=False
|
423 |
-
).then(
|
424 |
-
respond,
|
425 |
-
[msg, chatbot],
|
426 |
-
[chatbot]
|
427 |
-
)
|
428 |
-
|
429 |
-
clear.click(lambda: None, None, chatbot, queue=False)
|
430 |
|
431 |
if __name__ == "__main__":
|
432 |
# Add resource verification
|
|
|
330 |
|
331 |
|
332 |
def chat_interface(message, history):
|
333 |
+
inputs = {
|
334 |
+
"query": message,
|
335 |
+
"all_queries": [message],
|
336 |
+
"all_texts": all_chunks,
|
337 |
+
"k_per_query": 3,
|
338 |
+
"alpha": 0.7,
|
339 |
+
"vectorstore": vectorstore,
|
340 |
+
"full_document": "",
|
341 |
+
}
|
342 |
+
response = ""
|
343 |
+
for chunk in full_pipeline.stream(inputs):
|
344 |
+
if isinstance(chunk, str):
|
345 |
+
response += chunk
|
346 |
+
yield response
|
347 |
+
elif isinstance(chunk, dict) and "answer" in chunk:
|
348 |
+
response += chunk["answer"]
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
349 |
yield response
|
|
|
|
|
350 |
|
|
|
351 |
with gr.Blocks(css="""
|
352 |
+
html, body, .gradio-container {
|
353 |
+
height: 100%;
|
354 |
+
margin: 0;
|
355 |
+
padding: 0;
|
356 |
+
}
|
357 |
.gradio-container {
|
358 |
width: 90%;
|
359 |
max-width: 1000px;
|
360 |
margin: 0 auto;
|
361 |
padding: 1rem;
|
362 |
}
|
363 |
+
|
364 |
.chatbox-container {
|
365 |
display: flex;
|
366 |
flex-direction: column;
|
367 |
+
height: 95%;
|
368 |
}
|
369 |
+
|
370 |
.chatbot {
|
371 |
flex: 1;
|
372 |
overflow-y: auto;
|
373 |
min-height: 500px;
|
374 |
}
|
375 |
+
|
376 |
.textbox {
|
377 |
margin-top: 1rem;
|
378 |
}
|
379 |
+
#component-523 {
|
380 |
+
height: 98%;
|
381 |
+
}
|
382 |
""") as demo:
|
383 |
with gr.Column(elem_classes="chatbox-container"):
|
384 |
gr.Markdown("## π¬ Ask Krishna's AI Assistant")
|
385 |
gr.Markdown("π‘ Ask anything about Krishna Vamsi Dhulipalla")
|
386 |
+
chatbot = gr.Chatbot(elem_classes="chatbot", type="messages")
|
387 |
+
textbox = gr.Textbox(placeholder="Ask a question about Krishna...", elem_classes="textbox")
|
388 |
+
|
389 |
+
gr.ChatInterface(
|
390 |
+
fn=chat_interface,
|
391 |
+
chatbot=chatbot,
|
392 |
+
textbox=textbox,
|
|
|
393 |
examples=[
|
394 |
"What are Krishna's research interests?",
|
395 |
"Where did Krishna work?",
|
396 |
+
"What did he study at Virginia Tech?"
|
397 |
],
|
398 |
+
type= "messages",
|
|
|
399 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
400 |
|
401 |
if __name__ == "__main__":
|
402 |
# Add resource verification
|