Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -62,15 +62,21 @@ qa = RetrievalQA.from_llm(llm=llm, retriever=retriever)
|
|
| 62 |
# Chatbot function
|
| 63 |
def chatbot(selected_llm, user_input, chat_history):
|
| 64 |
global llm
|
| 65 |
-
if
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
|
|
|
|
|
|
|
|
|
|
| 68 |
response = qa.invoke({"query": user_input})
|
| 69 |
answer = response.get("result", "No response received.")
|
| 70 |
chat_history.append(("π§βπ» You", user_input))
|
| 71 |
chat_history.append(("π€ Bot", answer))
|
| 72 |
return chat_history, ""
|
| 73 |
|
|
|
|
| 74 |
# Gradio Interface
|
| 75 |
with gr.Blocks() as demo:
|
| 76 |
gr.Markdown("# π€ RAG-Powered Chatbot")
|
|
|
|
| 62 |
# Chatbot function
|
| 63 |
def chatbot(selected_llm, user_input, chat_history):
|
| 64 |
global llm
|
| 65 |
+
if hasattr(llm, "pipeline"): # Ensure llm has a pipeline
|
| 66 |
+
current_model = llm.pipeline.model.name_or_path # Get the model name
|
| 67 |
+
else:
|
| 68 |
+
current_model = None # Handle cases where llm is not initialized
|
| 69 |
|
| 70 |
+
if selected_llm != current_model:
|
| 71 |
+
llm = load_llm(selected_llm, llm_options[selected_llm])
|
| 72 |
+
|
| 73 |
response = qa.invoke({"query": user_input})
|
| 74 |
answer = response.get("result", "No response received.")
|
| 75 |
chat_history.append(("π§βπ» You", user_input))
|
| 76 |
chat_history.append(("π€ Bot", answer))
|
| 77 |
return chat_history, ""
|
| 78 |
|
| 79 |
+
|
| 80 |
# Gradio Interface
|
| 81 |
with gr.Blocks() as demo:
|
| 82 |
gr.Markdown("# π€ RAG-Powered Chatbot")
|