Ashendilantha commited on
Commit
4834dfe
·
verified ·
1 Parent(s): ed9bb4a

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +5 -15
app.py CHANGED
@@ -58,8 +58,7 @@ def classify_csv(file):
58
  text_column = df.columns[0] # Assume first column is the text column
59
 
60
  df[text_column] = df[text_column].astype(str).apply(clean_text) # Clean text column
61
- df["Encoded Prediction"] = df[text_column].apply(lambda x: news_classifier(x)[0]['label'])
62
- df["Decoded Prediction"] = df["Encoded Prediction"].map(label_mapping)
63
  df["Confidence"] = df[text_column].apply(lambda x: round(news_classifier(x)[0]['score'] * 100, 2))
64
 
65
  # Store all text as a single context for QA
@@ -73,29 +72,20 @@ def classify_csv(file):
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
-
98
- # Append the question and answer to the chat history
99
  history.append([user_input, answer])
100
 
101
  return history, answer
 
58
  text_column = df.columns[0] # Assume first column is the text column
59
 
60
  df[text_column] = df[text_column].astype(str).apply(clean_text) # Clean text column
61
+ df["Decoded Prediction"] = df[text_column].apply(lambda x: label_mapping.get(news_classifier(x)[0]['label'], "Unknown"))
 
62
  df["Confidence"] = df[text_column].apply(lambda x: round(news_classifier(x)[0]['score'] * 100, 2))
63
 
64
  # Store all text as a single context for QA
 
72
  return None, f"Error: {str(e)}"
73
 
74
  def chatbot_response(history, user_input, text_input=None, file_input=None):
75
+ user_input = user_input.lower()
 
 
 
76
  context = ""
77
 
 
78
  if text_input:
79
+ context += text_input
80
 
81
  if file_input:
82
+ df, _ = classify_csv(file_input)
83
+ context += context_storage["bulk_context"]
 
84
 
 
85
  if context:
86
  with st.spinner("Finding answer..."):
 
87
  result = qa_pipeline(question=user_input, context=context)
88
  answer = result["answer"]
 
 
89
  history.append([user_input, answer])
90
 
91
  return history, answer