Spaces:
Running
Running
Update app.py
Browse files
app.py
CHANGED
@@ -40,17 +40,15 @@ def data_ingestion_from_directory():
|
|
40 |
index = VectorStoreIndex.from_documents(documents)
|
41 |
index.storage_context.persist(persist_dir=PERSIST_DIR)
|
42 |
|
43 |
-
def handle_query(message,
|
44 |
# Prepare the chat history for context
|
45 |
-
|
46 |
-
for user_message, bot_response in chat_history:
|
47 |
-
context_str += f"User asked: '{user_message}'\nBot answered: '{bot_response}'\n"
|
48 |
|
49 |
# Prepare the chat prompt template
|
50 |
chat_text_qa_msgs = [
|
51 |
(
|
52 |
"user",
|
53 |
-
f"You are now the RedFerns Tech chatbot. Your aim is to provide answers to the user based on the conversation flow only.\n\nQuestion:\n{message}"
|
54 |
)
|
55 |
]
|
56 |
text_qa_template = ChatPromptTemplate.from_messages(chat_text_qa_msgs)
|
@@ -60,8 +58,8 @@ def handle_query(message, chat_history):
|
|
60 |
index = load_index_from_storage(storage_context)
|
61 |
|
62 |
# Use the Llama index to generate a response
|
63 |
-
query_engine = index.as_query_engine(text_qa_template=text_qa_template, context_str=
|
64 |
-
answer = query_engine.query(message)
|
65 |
|
66 |
if hasattr(answer, 'response'):
|
67 |
response = answer.response
|
@@ -71,7 +69,7 @@ def handle_query(message, chat_history):
|
|
71 |
response = "Sorry, I couldn't find an answer."
|
72 |
|
73 |
# Update chat history with the current interaction
|
74 |
-
chat_history.append([message, response])
|
75 |
|
76 |
return response
|
77 |
|
@@ -82,7 +80,7 @@ data_ingestion_from_directory()
|
|
82 |
# Create the Gradio interface
|
83 |
interface = gr.ChatInterface(
|
84 |
fn=handle_query,
|
85 |
-
|
86 |
title="RedfernsTech Q&A Chatbot",
|
87 |
description="Ask me anything about the uploaded document."
|
88 |
)
|
|
|
40 |
index = VectorStoreIndex.from_documents(documents)
|
41 |
index.storage_context.persist(persist_dir=PERSIST_DIR)
|
42 |
|
43 |
+
def handle_query(message, history):
|
44 |
# Prepare the chat history for context
|
45 |
+
chat_history = [[msg["text"], ""] for msg in history]
|
|
|
|
|
46 |
|
47 |
# Prepare the chat prompt template
|
48 |
chat_text_qa_msgs = [
|
49 |
(
|
50 |
"user",
|
51 |
+
f"You are now the RedFerns Tech chatbot. Your aim is to provide answers to the user based on the conversation flow only.\n\nQuestion:\n{message['text']}"
|
52 |
)
|
53 |
]
|
54 |
text_qa_template = ChatPromptTemplate.from_messages(chat_text_qa_msgs)
|
|
|
58 |
index = load_index_from_storage(storage_context)
|
59 |
|
60 |
# Use the Llama index to generate a response
|
61 |
+
query_engine = index.as_query_engine(text_qa_template=text_qa_template, context_str="")
|
62 |
+
answer = query_engine.query(message['text'])
|
63 |
|
64 |
if hasattr(answer, 'response'):
|
65 |
response = answer.response
|
|
|
69 |
response = "Sorry, I couldn't find an answer."
|
70 |
|
71 |
# Update chat history with the current interaction
|
72 |
+
chat_history.append([message['text'], response])
|
73 |
|
74 |
return response
|
75 |
|
|
|
80 |
# Create the Gradio interface
|
81 |
interface = gr.ChatInterface(
|
82 |
fn=handle_query,
|
83 |
+
examples=[{"text": "hello"}, {"text": "hola"}, {"text": "merhaba"}],
|
84 |
title="RedfernsTech Q&A Chatbot",
|
85 |
description="Ask me anything about the uploaded document."
|
86 |
)
|