Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -72,28 +72,26 @@ def classify_csv(file):
|
|
| 72 |
except Exception as e:
|
| 73 |
return None, f"Error: {str(e)}"
|
| 74 |
|
| 75 |
-
def chatbot_response(history, user_input,
|
| 76 |
# Always use the user input as a question for the QA pipeline
|
| 77 |
user_input = user_input.lower() # Optionally make it lowercase
|
| 78 |
|
| 79 |
-
#
|
| 80 |
context = ""
|
| 81 |
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
context = text_input
|
| 85 |
|
| 86 |
-
|
| 87 |
-
#
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
df, _ = classify_csv(file_input) # This function should return the dataframe and context
|
| 91 |
-
context = context_storage["bulk_context"]
|
| 92 |
|
| 93 |
-
# Make sure there's context for QA pipeline
|
| 94 |
if context:
|
| 95 |
with st.spinner("Finding answer..."):
|
| 96 |
-
# Run QA pipeline with the user's question and context from
|
| 97 |
result = qa_pipeline(question=user_input, context=context)
|
| 98 |
answer = result["answer"]
|
| 99 |
|
|
|
|
| 72 |
except Exception as e:
|
| 73 |
return None, f"Error: {str(e)}"
|
| 74 |
|
| 75 |
+
def chatbot_response(history, user_input, text_input=None, file_input=None):
|
| 76 |
# Always use the user input as a question for the QA pipeline
|
| 77 |
user_input = user_input.lower() # Optionally make it lowercase
|
| 78 |
|
| 79 |
+
# Initialize context as empty
|
| 80 |
context = ""
|
| 81 |
|
| 82 |
+
# Combine the context from text_input and file_input
|
| 83 |
+
if text_input:
|
| 84 |
+
context += text_input # Add the single article text as context
|
| 85 |
|
| 86 |
+
if file_input:
|
| 87 |
+
# Process the CSV file and extract the content for bulk context
|
| 88 |
+
df, _ = classify_csv(file_input) # Assuming classify_csv processes the file and gets the context
|
| 89 |
+
context += context_storage["bulk_context"] # Append bulk context to the overall context
|
|
|
|
|
|
|
| 90 |
|
| 91 |
+
# Make sure there's context for the QA pipeline
|
| 92 |
if context:
|
| 93 |
with st.spinner("Finding answer..."):
|
| 94 |
+
# Run QA pipeline with the user's question and combined context from both text_input and file_input
|
| 95 |
result = qa_pipeline(question=user_input, context=context)
|
| 96 |
answer = result["answer"]
|
| 97 |
|