Update app.py
Browse files
app.py
CHANGED
@@ -610,7 +610,6 @@ if uploaded_file:
|
|
610 |
processing_time = round((time.time() - start_time) / 60, 2)
|
611 |
st.info(f"⏱️ Response generated in **{processing_time} minutes**.")
|
612 |
|
613 |
-
st.session_state.generated_summary = rag_summary
|
614 |
st.session_state.last_uploaded_hash = file_hash
|
615 |
st.session_state.processed = True
|
616 |
st.session_state.last_prompt_hash = None
|
@@ -703,43 +702,6 @@ if prompt:
|
|
703 |
|
704 |
######################################################################################################################
|
705 |
|
706 |
-
# 📚 Imports
|
707 |
-
import evaluate
|
708 |
-
from nltk.translate.bleu_score import sentence_bleu, SmoothingFunction
|
709 |
-
|
710 |
-
# 📌 Load Evaluators Once
|
711 |
-
@st.cache_resource
|
712 |
-
def load_evaluators():
|
713 |
-
rouge = evaluate.load("rouge")
|
714 |
-
bertscore = evaluate.load("bertscore")
|
715 |
-
return rouge, bertscore
|
716 |
-
|
717 |
-
rouge, bertscore = load_evaluators()
|
718 |
-
|
719 |
-
# 📌 Define Evaluation Functions
|
720 |
-
def evaluate_summary(generated_summary, ground_truth_summary):
|
721 |
-
"""Evaluate ROUGE and BERTScore."""
|
722 |
-
rouge_result = rouge.compute(predictions=[generated_summary], references=[ground_truth_summary])
|
723 |
-
bert_result = bertscore.compute(predictions=[generated_summary], references=[ground_truth_summary], lang="en")
|
724 |
-
return rouge_result, bert_result
|
725 |
-
|
726 |
-
def compute_bleu(prediction, ground_truth):
|
727 |
-
reference = [ground_truth.strip().split()]
|
728 |
-
candidate = prediction.strip().split()
|
729 |
-
smoothie = SmoothingFunction().method4
|
730 |
-
return sentence_bleu(reference, candidate, smoothing_function=smoothie)
|
731 |
-
|
732 |
-
def evaluate_metrics(prediction, ground_truth):
|
733 |
-
"""Only compute ROUGE, BLEU, and BERTScore."""
|
734 |
-
rouge_result, bert_result = evaluate_summary(prediction, ground_truth)
|
735 |
-
bleu_score = compute_bleu(prediction, ground_truth)
|
736 |
-
return {
|
737 |
-
"ROUGE": rouge_result,
|
738 |
-
"BERTScore": bert_result,
|
739 |
-
"BLEU Score": bleu_score
|
740 |
-
}
|
741 |
-
|
742 |
-
|
743 |
|
744 |
# Run this along with streamlit run app.py to evaluate the model's performance on a test set
|
745 |
# Otherwise, comment the below code
|
|
|
610 |
processing_time = round((time.time() - start_time) / 60, 2)
|
611 |
st.info(f"⏱️ Response generated in **{processing_time} minutes**.")
|
612 |
|
|
|
613 |
st.session_state.last_uploaded_hash = file_hash
|
614 |
st.session_state.processed = True
|
615 |
st.session_state.last_prompt_hash = None
|
|
|
702 |
|
703 |
######################################################################################################################
|
704 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
705 |
|
706 |
# Run this along with streamlit run app.py to evaluate the model's performance on a test set
|
707 |
# Otherwise, comment the below code
|