krishnadhulipalla commited on
Commit
43f39e7
·
1 Parent(s): af9c758

update app.py

Browse files
Files changed (1) hide show
  1. app.py +56 -31
app.py CHANGED
@@ -35,6 +35,13 @@ if not api_key:
35
  # Constants
36
  FAISS_PATH = "faiss_store/v30_600_150"
37
  CHUNKS_PATH = "all_chunks.json"
 
 
 
 
 
 
 
38
  KRISHNA_BIO = """Krishna Vamsi Dhulipalla is a graduate student in Computer Science at Virginia Tech (M.Eng, expected 2024), with over 3 years of experience across data engineering, machine learning research, and real-time analytics. He specializes in building scalable data systems and intelligent LLM-powered applications, with strong expertise in Python, PyTorch, Hugging Face Transformers, and end-to-end ML pipelines.
39
 
40
  He has led projects involving retrieval-augmented generation (RAG), feature selection for genomic classification, fine-tuning domain-specific LLMs (e.g., DNABERT, HyenaDNA), and real-time forecasting systems using Kafka, Spark, and Airflow. His cloud proficiency spans AWS (S3, SageMaker, ECS, CloudWatch), GCP (BigQuery, Cloud Composer), and DevOps tools like Docker, Kubernetes, and MLflow.
@@ -317,16 +324,13 @@ answer_chain = (
317
  )
318
 
319
  # Full Pipeline
320
- full_pipeline = (
321
- hybrid_chain
322
- | RunnableAssign({"validation": validation_chain})
323
- | RunnableAssign({"answer": answer_chain})
324
- )
325
 
326
  import gradio as gr
 
327
 
328
  def chat_interface(message, history):
329
- # Handle different input formats
330
  if isinstance(message, list) and len(message) > 0:
331
  if isinstance(message[-1], dict):
332
  user_input = message[-1].get("content", "")
@@ -335,6 +339,7 @@ def chat_interface(message, history):
335
  else:
336
  user_input = str(message)
337
 
 
338
  inputs = {
339
  "query": user_input,
340
  "all_queries": [user_input],
@@ -346,12 +351,18 @@ def chat_interface(message, history):
346
  }
347
 
348
  response = ""
349
- for chunk in full_pipeline.stream(inputs):
350
- if isinstance(chunk, str):
351
- response += chunk
352
- elif isinstance(chunk, dict) and "answer" in chunk:
353
- response += chunk["answer"]
354
- yield [{"role": "assistant", "content": response}]
 
 
 
 
 
 
355
 
356
  with gr.Blocks(css="""
357
  html, body, .gradio-container {
@@ -385,22 +396,36 @@ with gr.Blocks(css="""
385
  height: 98%;
386
  }
387
  """) as demo:
388
- with gr.Column(elem_classes="chatbox-container"):
389
- gr.Markdown("## 💬 Ask Krishna's AI Assistant")
390
- gr.Markdown("💡 Ask anything about Krishna Vamsi Dhulipalla")
391
- chatbot = gr.Chatbot(elem_classes="chatbot", type="messages")
392
- textbox = gr.Textbox(placeholder="Ask a question about Krishna...", elem_classes="textbox")
393
-
394
- gr.ChatInterface(
395
- fn=chat_interface,
396
- chatbot=chatbot,
397
- textbox=textbox,
398
- examples=[
399
- "What are Krishna's research interests?",
400
- "Where did Krishna work?",
401
- "What did he study at Virginia Tech?",
402
- ],
403
- type="messages"
404
- )
405
-
406
- demo.launch(cache_examples=False)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
35
  # Constants
36
  FAISS_PATH = "faiss_store/v30_600_150"
37
  CHUNKS_PATH = "all_chunks.json"
38
+
39
+ if not Path(FAISS_PATH).exists():
40
+ raise FileNotFoundError(f"FAISS index not found at {FAISS_PATH}")
41
+
42
+ if not Path(CHUNKS_PATH).exists():
43
+ raise FileNotFoundError(f"Chunks file not found at {CHUNKS_PATH}")
44
+
45
  KRISHNA_BIO = """Krishna Vamsi Dhulipalla is a graduate student in Computer Science at Virginia Tech (M.Eng, expected 2024), with over 3 years of experience across data engineering, machine learning research, and real-time analytics. He specializes in building scalable data systems and intelligent LLM-powered applications, with strong expertise in Python, PyTorch, Hugging Face Transformers, and end-to-end ML pipelines.
46
 
47
  He has led projects involving retrieval-augmented generation (RAG), feature selection for genomic classification, fine-tuning domain-specific LLMs (e.g., DNABERT, HyenaDNA), and real-time forecasting systems using Kafka, Spark, and Airflow. His cloud proficiency spans AWS (S3, SageMaker, ECS, CloudWatch), GCP (BigQuery, Cloud Composer), and DevOps tools like Docker, Kubernetes, and MLflow.
 
324
  )
325
 
326
  # Full Pipeline
327
+ full_pipeline = hybrid_chain | RunnableAssign({"validation": validation_chain}) | answer_chain
 
 
 
 
328
 
329
  import gradio as gr
330
+ import time
331
 
332
  def chat_interface(message, history):
333
+ # Handle input formatting
334
  if isinstance(message, list) and len(message) > 0:
335
  if isinstance(message[-1], dict):
336
  user_input = message[-1].get("content", "")
 
339
  else:
340
  user_input = str(message)
341
 
342
+ # Prepare inputs for pipeline
343
  inputs = {
344
  "query": user_input,
345
  "all_queries": [user_input],
 
351
  }
352
 
353
  response = ""
354
+ try:
355
+ for chunk in full_pipeline.stream(inputs):
356
+ if isinstance(chunk, str):
357
+ response += chunk
358
+ elif isinstance(chunk, dict) and "answer" in chunk:
359
+ response += chunk["answer"]
360
+
361
+ # Yield simpler format
362
+ yield response
363
+ except Exception as e:
364
+ response = f"Error: {str(e)}"
365
+ yield response
366
 
367
  with gr.Blocks(css="""
368
  html, body, .gradio-container {
 
396
  height: 98%;
397
  }
398
  """) as demo:
399
+ chatbot = gr.Chatbot(elem_classes="chatbot")
400
+ msg = gr.Textbox(placeholder="Ask a question about Krishna...", elem_classes="textbox")
401
+ clear = gr.ClearButton([msg, chatbot])
402
+
403
+ def respond(message, chat_history):
404
+ bot_message = ""
405
+ for chunk in chat_interface(message, chat_history):
406
+ bot_message = chunk
407
+ chat_history[-1] = (message, bot_message)
408
+ yield chat_history
409
+
410
+ msg.submit(
411
+ lambda message, chat_history: chat_history + [(message, "")],
412
+ [msg, chatbot],
413
+ [chatbot],
414
+ queue=False
415
+ ).then(
416
+ respond,
417
+ [msg, chatbot],
418
+ [chatbot]
419
+ )
420
+
421
+ gr.Examples(
422
+ examples=[
423
+ "What are Krishna's research interests?",
424
+ "Where did Krishna work?",
425
+ "What did he study at Virginia Tech?",
426
+ ],
427
+ inputs=msg
428
+ )
429
+
430
+ if __name__ == "__main__":
431
+ demo.queue().launch(debug=True, cache_examples=False)