ZarTShe commited on
Commit
77253fa
·
0 Parent(s):

Clean version for HF Space

Browse files
.streamlit/secrets.toml.txt ADDED
@@ -0,0 +1 @@
 
 
1
+ GOOGLE_API_KEY= "AIzaSyBIfGJRoet_wzzYXIiWXxStkIigEOzSR2o"
README.md ADDED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ title: ScientificChatbot
3
+ emoji: 🏃
4
+ colorFrom: gray
5
+ colorTo: purple
6
+ sdk: streamlit
7
+ sdk_version: 1.44.1
8
+ app_file: app.py
9
+ pinned: false
10
+ ---
11
+
12
+ Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
evaluation.py ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import io
3
+ import pandas as pd
4
+ from datasets import load_dataset
5
+ from dotenv import load_dotenv
6
+ from nltk.translate.bleu_score import corpus_bleu
7
+ from rouge_score import rouge_scorer
8
+ from bert_score import score
9
+ from modtran_gemini import (
10
+ handle_user_query,
11
+ initialize_chatbot_agent,
12
+ get_uploaded_text,
13
+ get_text_chunks,
14
+ get_vectorstore,
15
+ set_global_vectorstore
16
+ )
17
+ import string
18
+ import re
19
+
20
+ load_dotenv()
21
+
22
+ # Load SQuAD dataset for benchmark
23
+ ds = load_dataset("squad", split="validation[:100]")
24
+
25
+ # Extract context, questions, and answers
26
+ contexts = [item["context"] for item in ds]
27
+ questions = [item["question"] for item in ds]
28
+ answers = [item["answers"]["text"][0] for item in ds]
29
+
30
+ # Create dataframe
31
+ df = pd.DataFrame({"context": contexts, "question": questions, "answer": answers})
32
+
33
+ # Save contexts to disk to simulate file uploads
34
+ os.makedirs("squad_contexts", exist_ok=True)
35
+ for i, context in enumerate(df["context"].unique()):
36
+ with open(f"squad_contexts/context_{i}.txt", "w", encoding="utf-8") as f:
37
+ f.write(context)
38
+
39
+ # Simulate file uploads (Streamlit-like file objects)
40
+ uploaded_files = []
41
+ for filename in os.listdir("squad_contexts"):
42
+ if filename.endswith(".txt"):
43
+ with open(os.path.join("squad_contexts", filename), "rb") as f:
44
+ file_obj = io.BytesIO(f.read())
45
+ file_obj.name = filename
46
+ uploaded_files.append(file_obj)
47
+
48
+ # Initialize vectorstore and agent
49
+ raw_text = get_uploaded_text(uploaded_files)
50
+ text_chunks = get_text_chunks(raw_text)
51
+ vectorstore = get_vectorstore(text_chunks)
52
+ set_global_vectorstore(vectorstore)
53
+
54
+ agent = initialize_chatbot_agent()
55
+
56
+ # Run chatbot predictions
57
+ df["chatbot_answer"] = df["question"].apply(lambda q: handle_user_query(q, agent))
58
+
59
+ # BLEU Evaluation
60
+ references = [[ans.split()] for ans in df["answer"]]
61
+ hypotheses = [pred.split() for pred in df["chatbot_answer"]]
62
+ bleu_score = corpus_bleu(references, hypotheses)
63
+
64
+ # ROUGE Evaluation
65
+ scorer = rouge_scorer.RougeScorer(['rouge1', 'rougeL'], use_stemmer=True)
66
+ rouge_scores = [scorer.score(ref, hyp) for ref, hyp in zip(df["answer"], df["chatbot_answer"])]
67
+ rouge1 = sum(score["rouge1"].fmeasure for score in rouge_scores) / len(rouge_scores)
68
+ rougeL = sum(score["rougeL"].fmeasure for score in rouge_scores) / len(rouge_scores)
69
+
70
+ # BERTScore Evaluation
71
+ P, R, F1 = score(df["chatbot_answer"].tolist(), df["answer"].tolist(),model_type='distilbert-base-uncased', batch_size=4,lang="en", verbose=True)
72
+ mean_precision = P.mean().item()
73
+ mean_recall = R.mean().item()
74
+ mean_f1 = F1.mean().item()
75
+
76
+ # SQuAD F1 Evaluation
77
+ def normalize_answer(s):
78
+ def remove_articles(text):
79
+ return re.sub(r'\b(a|an|the)\b', ' ', text)
80
+
81
+ def white_space_fix(text):
82
+ return ' '.join(text.split())
83
+
84
+ def remove_punctuation(text):
85
+ return ''.join(ch for ch in text if ch not in set(string.punctuation))
86
+
87
+ def lowercase(text):
88
+ return text.lower()
89
+
90
+ return white_space_fix(remove_articles(remove_punctuation(lowercase(s))))
91
+
92
+ def compute_f1(a_gold, a_pred):
93
+ gold_toks = normalize_answer(a_gold).split()
94
+ pred_toks = normalize_answer(a_pred).split()
95
+ common = set(gold_toks) & set(pred_toks)
96
+
97
+ if len(common) == 0:
98
+ return 0.0
99
+
100
+ precision = len(common) / len(pred_toks)
101
+ recall = len(common) / len(gold_toks)
102
+ return (2 * precision * recall) / (precision + recall)
103
+
104
+ df["squad_f1_score"] = df.apply(lambda row: compute_f1(row["answer"], row["chatbot_answer"]), axis=1)
105
+ mean_squad_f1 = df["squad_f1_score"].mean()
106
+
107
+ # Print evaluation results
108
+ print(f"BLEU Score: {bleu_score:.3f}")
109
+ print(f"ROUGE-1: {rouge1:.3f}")
110
+ print(f"ROUGE-L: {rougeL:.3f}")
111
+ # BERTScore Evaluation
112
+ P, R, F1 = score(df["chatbot_answer"].tolist(), df["answer"].tolist(), lang="en")
113
+ df["BERTScore_F1"] = F1.numpy()
114
+ print(f"Mean BERTScore F1: {F1.mean().item():.3f}")
115
+ # Save evaluation results
116
+ df.to_csv('evaluation_results.csv', index=False)
evaluation_modtran.py ADDED
@@ -0,0 +1,146 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os, io, re
2
+ import pandas as pd
3
+ from sklearn.metrics import accuracy_score
4
+ from bert_score import score as bert_score
5
+ import google.generativeai as genai
6
+
7
+ from modtran_gemini import (
8
+ handle_user_query,
9
+ initialize_chatbot_agent,
10
+ get_uploaded_text,
11
+ get_text_chunks,
12
+ get_vectorstore,
13
+ set_global_vectorstore,
14
+ self_reasoning,
15
+ faiss_search_with_keywords,
16
+ faiss_search_with_reasoning
17
+ )
18
+
19
+ from langchain_openai import ChatOpenAI
20
+
21
+ class GeminiLLM:
22
+ def __init__(self, model_name="models/gemini-1.5-pro-latest", api_key=None):
23
+ api_key = api_key or os.getenv("GOOGLE_API_KEY")
24
+ if not api_key:
25
+ raise ValueError("Missing GOOGLE_API_KEY")
26
+ genai.configure(api_key=api_key)
27
+ self.model = genai.GenerativeModel(model_name)
28
+
29
+ def predict(self, prompt: str) -> str:
30
+ response = self.model.generate_content(prompt)
31
+ return response.text.strip()
32
+
33
+ # Load CSV dataset (ensure columns are 'question', 'answer' with no extra spaces)
34
+ df = pd.read_csv("modtran_dataset.csv")
35
+ df.columns = df.columns.str.strip() # Strip whitespace from column names
36
+
37
+ # Load the MODTRAN user manual
38
+ with open("MODTRAN 6 User's Manual.pdf", "rb") as f:
39
+ file_obj = io.BytesIO(f.read())
40
+ file_obj.name = "MODTRAN 6 User's Manual.pdf"
41
+ uploaded_files = [file_obj]
42
+
43
+ # Document processing
44
+ raw_text = get_uploaded_text(uploaded_files)
45
+ text_chunks = get_text_chunks(raw_text)
46
+ vectorstore = get_vectorstore(text_chunks)
47
+ set_global_vectorstore(vectorstore)
48
+ llm = GeminiLLM()
49
+
50
+ # Direct retrieval + answer generation
51
+ def direct_llm_rag_response(question):
52
+ from modtran_gemini import vectorstore_global
53
+ if vectorstore_global is None:
54
+ raise ValueError("Vectorstore is not initialized.")
55
+
56
+ # Retrieve relevant documents
57
+ retriever = vectorstore_global.as_retriever(search_kwargs={"k": 20})
58
+ docs = retriever.get_relevant_documents(question)
59
+
60
+ # Build a simple prompt with raw context
61
+ context = "\n\n".join([doc.page_content for doc in docs])
62
+
63
+ prompt = f"""
64
+ You are an AI assistant that analyzes the context provided to answer the user's query comprehensively and clearly.
65
+ Answer in a concise, factual way using the terminology from the context. Avoid extra explanation unless explicitly asked.
66
+ If asked for the page number,YOU MUST mention the page number.
67
+ ### Example 1:
68
+ **Question:** What is the purpose of the MODTRAN GUI?
69
+ **Context:**
70
+ [Page 10 of the docuemnt] The MODTRAN GUI helps users set parameters and visualize the model's output.
71
+ **Answer:** The MODTRAN GUI assists users in parameter setup and output visualization. You can find the answer at Page 10 of the document provided.
72
+
73
+ ### Example 2:
74
+ **Question:** How do you run MODTRAN on Linux? Answer with page number.
75
+ **Context:**
76
+ [Page 15 of the docuemnt] On Linux systems, MODTRAN can be run using the `mod6c` binary via terminal.
77
+ **Answer:** Use the `mod6c` binary via terminal. (Page 15)
78
+
79
+ ### Now answer:
80
+ **Question:** {question}
81
+ **Context:**
82
+ {context}
83
+
84
+ **Answer:**
85
+ """
86
+ return llm.predict(prompt)
87
+
88
+ # Predict answers
89
+ df["predicted"] = df["question"].apply(direct_llm_rag_response)
90
+
91
+ # Clean up answers
92
+ true_answers = df["answer"].str.lower().str.strip()
93
+ pred_answers = df["predicted"].str.lower().str.strip()
94
+
95
+ # Normalize answers
96
+ def normalize_text(s):
97
+ s = s.lower()
98
+ s = re.sub(r'\b(a|an|the)\b', ' ', s)
99
+ s = re.sub(r'[^a-z0-9]', ' ', s)
100
+ return ' '.join(s.split())
101
+
102
+ normalized_preds = [normalize_text(p) for p in pred_answers]
103
+ normalized_refs = [normalize_text(r) for r in true_answers]
104
+
105
+ # Token-level F1
106
+ def compute_f1(pred, ref):
107
+ pred_tokens = pred.split()
108
+ ref_tokens = ref.split()
109
+ common = set(pred_tokens) & set(ref_tokens)
110
+ if not common:
111
+ return 0.0
112
+ precision = len(common) / len(pred_tokens)
113
+ recall = len(common) / len(ref_tokens)
114
+ return 2 * precision * recall / (precision + recall)
115
+
116
+
117
+ def manual_tool_routing(question):
118
+ if "how" in question.lower():
119
+ context = faiss_search_with_reasoning(question)
120
+ else:
121
+ context = faiss_search_with_keywords(question)
122
+ return self_reasoning(question, context)
123
+
124
+ # Create predictions using different strategies
125
+ df["agent_predicted"] = df["question"].apply(manual_tool_routing)
126
+ df["keyword_predicted"] = df["question"].apply(faiss_search_with_keywords)
127
+ df["reasoning_predicted"] = df["question"].apply(faiss_search_with_reasoning)
128
+
129
+ refs = df["answer"].str.lower().str.strip()
130
+
131
+ for col in ["agent_predicted", "keyword_predicted", "reasoning_predicted"]:
132
+ preds = df[col].str.lower().str.strip()
133
+ normalized_preds = [normalize_text(p) for p in preds]
134
+ normalized_refs = [normalize_text(r) for r in refs]
135
+
136
+ em = sum([int(p == r) for p, r in zip(normalized_preds, normalized_refs)]) / len(refs)
137
+ f1 = sum([compute_f1(p, r) for p, r in zip(normalized_preds, normalized_refs)]) / len(refs)
138
+ P, R, F1_bert = bert_score(preds.tolist(), refs.tolist(), lang="en", verbose=True)
139
+ bert_f1 = F1_bert.mean().item()
140
+
141
+ print(f"\n🔹 Evaluation for: {col}")
142
+ print(f" - Exact Match: {em:.3f}")
143
+ print(f" - F1 Score: {f1:.3f}")
144
+ print(f" - BERTScore F1: {bert_f1:.3f}")
145
+
146
+ df[f"{col}_bert_f1"] = F1_bert.numpy()
evaluation_qasper.py ADDED
@@ -0,0 +1,75 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from datasets import load_dataset
2
+ import pandas as pd
3
+ import os, io
4
+ from bert_score import score
5
+ from sklearn.metrics import accuracy_score, f1_score
6
+ from modtran import (
7
+ handle_user_query,
8
+ initialize_chatbot_agent,
9
+ get_uploaded_text,
10
+ get_text_chunks,
11
+ get_vectorstore,
12
+ set_global_vectorstore,
13
+ )
14
+
15
+ # Load SciQ
16
+ ds = load_dataset("sciq", split="validation[:100]")
17
+
18
+ # Extract supports as context, question, and correct answer
19
+ contexts = [item["support"] for item in ds]
20
+ questions = [item["question"] for item in ds]
21
+ answers = [item["correct_answer"] for item in ds]
22
+ predictions = []
23
+
24
+ # Create dataframe
25
+ df = pd.DataFrame({"context": contexts, "question": questions, "answer": answers})
26
+
27
+ # Save contexts to disk to simulate file uploads
28
+ os.makedirs("sciq_contexts", exist_ok=True)
29
+ for i, context in enumerate(df["context"].unique()):
30
+ with open(f"sciq_contexts/context_{i}.txt", "w", encoding="utf-8") as f:
31
+ f.write(context)
32
+
33
+ # Simulate file uploads
34
+ uploaded_files = []
35
+ for filename in os.listdir("sciq_contexts"):
36
+ if filename.endswith(".txt"):
37
+ with open(os.path.join("sciq_contexts", filename), "rb") as f:
38
+ file_obj = io.BytesIO(f.read())
39
+ file_obj.name = filename
40
+ uploaded_files.append(file_obj)
41
+
42
+ print("Total uploaded files:", len(uploaded_files))
43
+
44
+ # Vectorstore pipeline
45
+ raw_text = get_uploaded_text(uploaded_files)
46
+ text_chunks = get_text_chunks(raw_text)
47
+ vectorstore = get_vectorstore(text_chunks)
48
+ set_global_vectorstore(vectorstore)
49
+
50
+ # Initialize chatbot agent
51
+ agent = initialize_chatbot_agent()
52
+
53
+
54
+ # Predict answers
55
+ df["chatbot_answer"] = df["question"].apply(lambda q: handle_user_query(q, agent))
56
+
57
+ # BERTScore Evaluation
58
+ P, R, F1 = score(df["chatbot_answer"].tolist(), df["answer"].tolist(), lang="en")
59
+ df["BERTScore_F1"] = F1.numpy()
60
+
61
+ print(f"Mean BERTScore F1: {F1.mean().item():.3f}")
62
+ for q in questions:
63
+ pred = handle_user_query(q, agent)
64
+ predictions.append(pred)
65
+
66
+ # Compute Accuracy
67
+ acc = accuracy_score(answers, predictions)
68
+ print(f"Accuracy: {acc:.3f}")
69
+
70
+ # Compute F1 (macro average - good for open-ended QA)
71
+ f1 = f1_score(answers, predictions, average='macro')
72
+ print(f"F1 Score (macro): {f1:.3f}")
73
+
74
+ # Save results
75
+ df.to_csv("sciq_evaluation_results.csv", index=False)
evaluation_results.csv ADDED
@@ -0,0 +1,101 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ context,question,answer,chatbot_answer,squad_f1_score,BERTScore_F1
2
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",Which NFL team represented the AFC at Super Bowl 50?,Denver Broncos,The Denver Broncos represented the AFC at Super Bowl 50.,0.4,0.8831762
3
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",Which NFL team represented the NFC at Super Bowl 50?,Carolina Panthers,The Carolina Panthers represented the NFC at Super Bowl 50.,0.4,0.88892263
4
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",Where did Super Bowl 50 take place?,"Santa Clara, California","Super Bowl 50 took place at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California.",0.3,0.86463374
5
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",Which NFL team won Super Bowl 50?,Denver Broncos,The Denver Broncos won Super Bowl 50.,0.5,0.8863907
6
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What color was used to emphasize the 50th anniversary of the Super Bowl?,gold,Gold was used to emphasize the 50th anniversary of the Super Bowl.,0.18181818181818182,0.8246054
7
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What was the theme of Super Bowl 50?,"""golden anniversary""","The theme of Super Bowl 50 was the ""golden anniversary"".",0.4,0.88012564
8
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What day was the game played on?,"February 7, 2016",The question lacks specific details about which game is being referred to. Please provide more information.,0.0,0.8093692
9
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What is the AFC short for?,American Football Conference,"In the context of the National Football League (NFL), AFC stands for American Football Conference.",0.375,0.8462678
10
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What was the theme of Super Bowl 50?,"""golden anniversary""","The theme of Super Bowl 50 was the ""golden anniversary"".",0.4,0.88012564
11
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What does AFC stand for?,American Football Conference,"In the context of the NFL, AFC stands for American Football Conference.",0.4615384615384615,0.85463834
12
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What day was the Super Bowl played on?,"February 7, 2016","I'm sorry, I am unable to provide the date of the most recent Super Bowl at this time.",0.0,0.8131411
13
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",Who won Super Bowl 50?,Denver Broncos,The Denver Broncos won Super Bowl 50.,0.5,0.8863907
14
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What venue did Super Bowl 50 take place in?,Levi's Stadium,"Super Bowl 50 took place at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California.",0.21052631578947367,0.815798
15
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What city did Super Bowl 50 take place in?,Santa Clara,"Super Bowl 50 took place in the San Francisco Bay Area at Santa Clara, California.",0.25,0.8431589
16
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.","If Roman numerals were used, what would Super Bowl 50 have been called?",Super Bowl L,"If Roman numerals were used, Super Bowl 50 would have been called ""Super Bowl L"".",0.33333333333333337,0.840755
17
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",Super Bowl 50 decided the NFL champion for what season?,2015,Super Bowl 50 decided the NFL champion for the 2015 season.,0.19999999999999998,0.8175393
18
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What year did the Denver Broncos secure a Super Bowl title for the third time?,2015,The Denver Broncos secured their third Super Bowl title in the year 2016.,0.0,0.8254469
19
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What city did Super Bowl 50 take place in?,Santa Clara,"Super Bowl 50 took place in the San Francisco Bay Area at Santa Clara, California.",0.25,0.8431589
20
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What stadium did Super Bowl 50 take place in?,Levi's Stadium,"Super Bowl 50 took place at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California.",0.21052631578947367,0.815798
21
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What was the final score of Super Bowl 50? ,24–10,"The final score of Super Bowl 50 was Denver Broncos 24, Carolina Panthers 10.",0.0,0.8035014
22
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.","What month, day and year did Super Bowl 50 take place? ","February 7, 2016","Super Bowl 50 took place on February 7, 2016.",0.5,0.87301385
23
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What year was Super Bowl 50?,2015,Super Bowl 50 was in the year 2016.,0.0,0.8231886
24
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What team was the AFC champion?,Denver Broncos,The AFC champion for the 2015 season was the Denver Broncos. Could you please specify the year you are interested in?,0.21052631578947367,0.8456418
25
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What team was the NFC champion?,Carolina Panthers,"I'm sorry, I don't have the most recent information on the NFC champion.",0.0,0.8142391
26
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",Who won Super Bowl 50?,Denver Broncos,The Denver Broncos won Super Bowl 50.,0.5,0.8863907
27
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",Super Bowl 50 determined the NFL champion for what season?,2015,Super Bowl 50 determined the NFL champion for the 2015 season.,0.19999999999999998,0.81693447
28
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",Which team won Super Bowl 50.,Denver Broncos,The Denver Broncos won Super Bowl 50.,0.5,0.8863907
29
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",Where was Super Bowl 50 held?,"Santa Clara, California.","Super Bowl 50 was held at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California.",0.3,0.8843575
30
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",The name of the NFL championship game is?,Super Bowl,The name of the NFL championship game is the Super Bowl.,0.4,0.8565423
31
+ "Super Bowl 50 was an American football game to determine the champion of the National Football League (NFL) for the 2015 season. The American Football Conference (AFC) champion Denver Broncos defeated the National Football Conference (NFC) champion Carolina Panthers 24–10 to earn their third Super Bowl title. The game was played on February 7, 2016, at Levi's Stadium in the San Francisco Bay Area at Santa Clara, California. As this was the 50th Super Bowl, the league emphasized the ""golden anniversary"" with various gold-themed initiatives, as well as temporarily suspending the tradition of naming each Super Bowl game with Roman numerals (under which the game would have been known as ""Super Bowl L""), so that the logo could prominently feature the Arabic numerals 50.",What 2015 NFL team one the AFC playoff?,Denver Broncos,The Denver Broncos won the AFC playoff in 2015.,0.4444444444444445,0.88645095
32
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Which Carolina Panthers player was named Most Valuable Player?,Cam Newton,Cam Newton was named the NFL Most Valuable Player while playing for the Carolina Panthers.,0.2666666666666667,0.8782701
33
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",How many appearances have the Denver Broncos made in the Super Bowl?,8,The Denver Broncos have made eight appearances in the Super Bowl.,0.0,0.8227126
34
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",What year was the Carolina Panthers franchise founded?,1995,The Carolina Panthers franchise was founded in 1995.,0.25,0.8233834
35
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",What team did the Panthers defeat?,Arizona Cardinals,The Panthers defeated the Arizona Cardinals.,0.6666666666666666,0.90900004
36
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who did the Broncos prevent from going to the Super Bowl?,New England Patriots,The Broncos prevented the New England Patriots from going to the Super Bowl.,0.4615384615384615,0.8878024
37
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who did the Panthers beat in the NFC Championship Game?,Arizona Cardinals,The Panthers beat the Arizona Cardinals in the NFC Championship Game.,0.4,0.8863175
38
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who lost to the Broncos in the AFC Championship?,New England Patriots,The New England Patriots lost to the Broncos in the AFC Championship.,0.5,0.9091872
39
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who were the defending Super Bowl champions?,New England Patriots,The Denver Broncos were the defending Super Bowl champions.,0.0,0.8717444
40
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",How many teams have been in the Super Bowl eight times?,four,"Four teams have been in the Super Bowl eight times. These are the Denver Broncos, New England Patriots, Dallas Cowboys, and Pittsburgh Steelers.",0.0909090909090909,0.79814947
41
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who was this season's NFL MVP?,Cam Newton,The MVP of the most recent NFL season mentioned in the context was Cam Newton.,0.2857142857142857,0.86420196
42
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",What was the win/loss ratio in 2015 for the Carolina Panthers during their regular season?,15–1,The Carolina Panthers had a win/loss ratio of 15-1 during their 2015 regular season.,0.0,0.83852804
43
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Which Carolina Panthers team member was picked as the team's MVP in 2015? ,Cam Newton,Cam Newton was picked as the Carolina Panthers' team MVP in 2015.,0.3076923076923077,0.8891575
44
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",What were the win/loss game stats for the Denver Bronco's regular season in 2015?,12–4,The Denver Broncos finished the regular season with a 12–4 record in 2015.,0.18181818181818182,0.83720595
45
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",How many teams have played in the Super Bowl eight times?,4,"The teams that have played in the Super Bowl eight times are the Patriots, Dallas Cowboys, Pittsburgh Steelers, and the Denver Broncos.",0.0,0.801293
46
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Which team did not get a chance to defend their Super Bowl XLIX win in Super Bowl 50?,New England Patriots,The New England Patriots.,1.0,0.9574103
47
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who is the quarterback for the Panthers?,Cam Newton,"I'm sorry, I couldn't find the current information about the quarterback for the Carolina Panthers.",0.0,0.81419134
48
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who did Carolina beat in the NFC championship game?,Arizona Cardinals,Carolina beat the Arizona Cardinals in the NFC championship game.,0.4,0.8821087
49
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",How many times have the Panthers been in the Super Bowl?,2,The Panthers have been in the Super Bowl twice.,0.0,0.83318734
50
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who did Denver beat in the AFC championship?,New England Patriots,The Denver Broncos beat the New England Patriots in the AFC championship.,0.5,0.89412516
51
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who was the Most Valuable Player for the 2015 NFL season?,Cam Newton,The Most Valuable Player for the 2015 NFL season was Cam Newton.,0.33333333333333337,0.862852
52
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who did Denver beat in the 2015 AFC Championship game?,New England Patriots,Denver beat the New England Patriots in the 2015 AFC Championship game.,0.4615384615384615,0.8849049
53
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who did the Carolina Panthers beat in the 2015 NFC Championship game?,Arizona Cardinals,The Carolina Panthers beat the Arizona Cardinals in the 2015 NFC Championship game.,0.33333333333333337,0.8737707
54
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who was the 2015 NFL MVP?,Cam Newton,The 2015 NFL MVP was Cam Newton.,0.5,0.8813283
55
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",Who did the Panthers beat to become the NFC champs?,Arizona Cardinals,The Panthers beat the Arizona Cardinals to become the NFC champs.,0.4,0.876848
56
+ "The Panthers finished the regular season with a 15–1 record, and quarterback Cam Newton was named the NFL Most Valuable Player (MVP). They defeated the Arizona Cardinals 49–15 in the NFC Championship Game and advanced to their second Super Bowl appearance since the franchise was founded in 1995. The Broncos finished the regular season with a 12–4 record, and denied the New England Patriots a chance to defend their title from Super Bowl XLIX by defeating them 20–18 in the AFC Championship Game. They joined the Patriots, Dallas Cowboys, and Pittsburgh Steelers as one of four teams that have made eight appearances in the Super Bowl.",What year did the Carolina Panthers form?,1995.,The Carolina Panthers were formed in 1995.,0.2857142857142857,0.87928814
57
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",Who was the Super Bowl 50 MVP?,Von Miller,The Super Bowl 50 MVP was Von Miller.,0.4444444444444445,0.85164344
58
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many fumbles did Von Miller force in Super Bowl 50?,2,Von Miller forced two fumbles in Super Bowl 50.,0.0,0.8216288
59
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",Which team held the scoring lead throughout the entire game?,Broncos,The Denver Broncos.,0.6666666666666666,0.8619311
60
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",Which Denver linebacker was named Super Bowl MVP?,linebacker Von Miller,The Denver linebacker who was named Super Bowl MVP is Von Miller.,0.42857142857142855,0.88970226
61
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many solo tackles did Von Miller make at Super Bowl 50?,five solo tackles,Von Miller made five solo tackles at Super Bowl 50.,0.4615384615384615,0.8914581
62
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",Who was limited by Denver's defense?,Newton was limited by Denver's defense,Cam Newton was limited by Denver's defense.,0.923076923076923,0.95191014
63
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many times was Cam Newton sacked?,seven,"I'm sorry, I couldn't find the specific information on how many times Cam Newton was sacked in his career.",0.0,0.80530393
64
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",Who won the Super Bowl MVP?,Von Miller,"I'm sorry, I am unable to provide the most recent Super Bowl MVP at this time.",0.0,0.7907247
65
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many turnovers did Cam Newton have?,three,"I'm sorry, I couldn't find the specific number of total turnovers Cam Newton has had in his career.",0.0,0.8055697
66
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many fumbles did Von Miller force?,two,"I'm sorry, I couldn't find the exact number of career forced fumbles by Von Miller.",0.0,0.80948853
67
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",Who was given the esteemed status of MVP for Super Bowl 50?,Von Miller,The MVP for Super Bowl 50 was Denver Broncos linebacker Von Miller.,0.3076923076923077,0.84020406
68
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",What position does Von Miller play for the Denver Broncos?,linebacker,Von Miller plays the position of linebacker for the Denver Broncos.,0.19999999999999998,0.8042575
69
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",What was the number of solo tackles that Von Miller had in Super Bowl 50?,5,Von Miller had five solo tackles in Super Bowl 50.,0.0,0.8285005
70
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many forced fumbles did Von Miller have during the Super Bowl 50 game?,2,Von Miller had two forced fumbles during the Super Bowl 50 game.,0.0,0.8272358
71
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",Who won the MVP for the Super Bowl?,Von Miller,"I'm sorry, I am unable to provide the most recent Super Bowl MVP at this time.",0.0,0.7907247
72
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many tackles did Von Miller get during the game?,5,Von Miller made five tackles during the game.,0.0,0.83889985
73
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many times was Cam Newton sacked in Super Bowl 50?,seven,Cam Newton was sacked seven times in Super Bowl 50.,0.18181818181818182,0.8137235
74
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many times did the Denver defense force Newton into turnovers?,three,The Denver defense forced Newton into three turnovers.,0.25,0.82676935
75
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",Which Newton turnover resulted in seven points for Denver?,a fumble,The Newton turnover that resulted in seven points for Denver was a fumble that Denver recovered for a touchdown during Super Bowl 50.,0.09523809523809523,0.8525294
76
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",Who was the Most Valuable Player of Super Bowl 50?,Von Miller,The Most Valuable Player of Super Bowl 50 was Denver linebacker Von Miller.,0.2857142857142857,0.82736576
77
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",What position does Von Miller play?,linebacker,Von Miller plays the position of linebacker.,0.2857142857142857,0.8274767
78
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many times was the Panthers' quarterback sacked?,seven,"Cam Newton, the Panthers' quarterback, was sacked seven times in Super Bowl 50.",0.15384615384615385,0.813856
79
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many times did the Broncos cause turnovers in the game?,three,The Broncos caused three turnovers in the game.,0.2857142857142857,0.8297505
80
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",What Denver player caused two fumbles for the Panthers?,Von Miller,Von Miller was the Denver player who caused two fumbles for the Panthers.,0.3076923076923077,0.8870876
81
+ "The Broncos took an early lead in Super Bowl 50 and never trailed. Newton was limited by Denver's defense, which sacked him seven times and forced him into three turnovers, including a fumble which they recovered for a touchdown. Denver linebacker Von Miller was named Super Bowl MVP, recording five solo tackles, 2½ sacks, and two forced fumbles.",How many tackles did Von Miller accomlish by himself in the game?,five,Von Miller accomplished five solo tackles in the game.,0.2222222222222222,0.8373196
82
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",Which network broadcasted Super Bowl 50 in the U.S.?,CBS,CBS broadcasted Super Bowl 50 in the U.S.,0.25,0.83527106
83
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",What was the average cost for a 30 second commercial during Super Bowl 50?,$5 million,The average cost for a 30 second commercial during Super Bowl 50 was $5 million.,0.2666666666666667,0.8531522
84
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",Which group headlined the Super Bowl 50 halftime show?,Coldplay,The British rock group Coldplay headlined the Super Bowl 50 halftime show.,0.18181818181818182,0.8169567
85
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",Which performers joined the headliner during the Super Bowl 50 halftime show?,Beyoncé and Bruno Mars,The performers who joined the headliner during the Super Bowl 50 halftime show were Beyoncé and Bruno Mars.,0.4210526315789474,0.88569283
86
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",At which Super Bowl did Beyonce headline the halftime show?,Super Bowl XLVII,Beyonce headlined the halftime show at Super Bowl XLVII.,0.5454545454545454,0.90231645
87
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",Who was the broadcaster for Super Bowl 50 in the United States?,CBS,CBS was the broadcaster for Super Bowl 50 in the United States.,0.18181818181818182,0.81726897
88
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",What was the average cost of a 30-second commercial?,$5 million,"I'm sorry, I couldn't find the specific information on the average cost of a 30-second TV commercial in general. However, for high-profile events like the Super Bowl, the cost can go up to $5 million for a 30-second slot. The cost can vary greatly depending on the time, channel, and program during which the commercial is aired.",0.07999999999999999,0.82230425
89
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",What halftime performer previously headlined Super Bowl XLVII?,Beyoncé,Beyoncé.,1.0,0.98789775
90
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",What halftime performer previously headlined Super Bowl XLVIII?,Bruno Mars,Bruno Mars.,1.0,0.98733324
91
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",Who was the main performer at this year's halftime show?,Coldplay,The most recent Super Bowl halftime show performer in the context provided was the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars.,0.08333333333333333,0.8075878
92
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",Which network broadcasted the 50th Super Bowl game? ,CBS,CBS broadcasted the 50th Super Bowl game in the U.S.,0.2222222222222222,0.82476676
93
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",What was the average cost for a TV ad lasting 30 seconds during Super Bowl 50?,$5 million,The average cost for a 30-second TV ad during Super Bowl 50 was $5 million.,0.2666666666666667,0.8501834
94
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",Who was the male singer who performed as a special guest during Super Bowl 50?,Bruno Mars,The male singer who performed as a special guest during Super Bowl 50 was Bruno Mars.,0.25,0.8465806
95
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",What ranking does the Super Bowl 50 halftime show have on the list of most watched TV broadcasts?,third,The Super Bowl 50 halftime show ranks third on the list of most watched TV broadcasts in the U.S.,0.11764705882352941,0.8186487
96
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",What station aired the Super Bowl?,CBS,CBS aired the Super Bowl.,0.4,0.84404844
97
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",How much money did a 1/2 minute commercial cost?,$5 million,The cost of a 1/2 minute commercial can vary greatly depending on the platform and event during which it is aired. Could you please provide more details?,0.0,0.8010742
98
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",What band headlined half-time during Super Bowl 50?,Coldplay,The band that headlined the half-time show during Super Bowl 50 was the British rock group Coldplay.,0.13333333333333333,0.8181728
99
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",What two artists came out with Coldplay during the half-time show?,Beyoncé and Bruno Mars,The two artists that came out with Coldplay during the half-time show were Beyoncé and Bruno Mars.,0.4210526315789474,0.887571
100
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",Who broadcast the Super Bowl on TV?,CBS,"I'm sorry, I couldn't find the specific information on which network broadcasted the Super Bowl in 2021.",0.0,0.8034885
101
+ "CBS broadcast Super Bowl 50 in the U.S., and charged an average of $5 million for a 30-second commercial during the game. The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars, who headlined the Super Bowl XLVII and Super Bowl XLVIII halftime shows, respectively. It was the third-most watched U.S. broadcast ever.",Who headlined the halftime show for Super Bowl 50?,Coldplay,The Super Bowl 50 halftime show was headlined by the British rock group Coldplay with special guest performers Beyoncé and Bruno Mars.,0.09523809523809523,0.80412585
model.py ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import google.generativeai as genai
3
+
4
+ genai.configure(api_key="AIzaSyBIfGJRoet_wzzYXIiWXxStkIigEOzSR2o")
5
+
6
+ models = genai.list_models()
7
+
8
+ for model in models:
9
+ print(f"Name: {model.name} | Methods: {model.supported_generation_methods}")
modtran.py ADDED
@@ -0,0 +1,222 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import subprocess
4
+ import pdfplumber
5
+ from lxml import etree
6
+ from bs4 import BeautifulSoup
7
+ from PyPDF2 import PdfReader
8
+ from langchain_community.vectorstores import FAISS
9
+ from langchain_community.embeddings import OpenAIEmbeddings
10
+ from langchain_community.embeddings import HuggingFaceBgeEmbeddings
11
+ from langchain_openai import ChatOpenAI
12
+ from langchain.agents import initialize_agent, AgentType
13
+ from langchain.agents import Tool
14
+ from langchain.memory import ConversationBufferMemory
15
+ from langchain.text_splitter import CharacterTextSplitter
16
+ from dotenv import load_dotenv
17
+ from keybert import KeyBERT
18
+ from sentence_transformers import CrossEncoder
19
+ reranker = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2')
20
+
21
+ # Initialize global variable
22
+ vectorstore_global = None
23
+
24
+ # Load OpenAI API key
25
+ def load_environment():
26
+ load_dotenv()
27
+
28
+ # PDF to XML Conversion
29
+ def convert_pdf_to_xml(pdf_file, xml_path):
30
+ os.makedirs("temp", exist_ok=True)
31
+ pdf_path = os.path.join("temp", pdf_file.name)
32
+ with open(pdf_path, 'wb') as f:
33
+ f.write(pdf_file.getbuffer())
34
+ subprocess.run(["pdftohtml", "-xml", pdf_path, xml_path], check=True)
35
+ return xml_path
36
+
37
+ # Extract text from XML
38
+ def extract_text_from_xml(xml_path, document_name):
39
+ from lxml import etree
40
+ tree = etree.parse(xml_path)
41
+ text_chunks = []
42
+ for page in tree.xpath("//page"):
43
+ page_num = int(page.get("number", 0))
44
+ texts = [text.text for text in page.xpath('.//text') if text.text]
45
+ combined_text = '\n'.join(texts)
46
+ text_chunks.append({"text": combined_text, "page": page_num, "document": document_name})
47
+ return text_chunks
48
+
49
+ # Process uploaded files
50
+ def get_uploaded_text(uploaded_files):
51
+ raw_text = []
52
+ print(f"Total uploaded files: {len(uploaded_files)}")
53
+ for uploaded_file in uploaded_files:
54
+ document_name = uploaded_file.name
55
+ if document_name.endswith(".pdf"):
56
+ xml_path = os.path.join("temp", document_name.replace(".pdf", ".xml"))
57
+ text_chunks = extract_text_from_xml(convert_pdf_to_xml(uploaded_file, xml_path), document_name)
58
+ raw_text.extend(text_chunks)
59
+ elif uploaded_file.name.endswith((".html", ".htm")):
60
+ soup = BeautifulSoup(uploaded_file.getvalue(), 'lxml')
61
+ raw_text.append({"text": soup.get_text(), "page": None, "document": document_name})
62
+ elif uploaded_file.name.endswith((".txt")):
63
+ content = uploaded_file.getvalue().decode("utf-8")
64
+ raw_text.append({"text": content, "page": None, "document": document_name})
65
+ return raw_text
66
+
67
+ # Text Chunking
68
+ def get_text_chunks(raw_text):
69
+ splitter = CharacterTextSplitter(separator='\n', chunk_size=500, chunk_overlap=100)
70
+ final_chunks = []
71
+ for chunk in raw_text:
72
+ for split_text in splitter.split_text(chunk["text"]):
73
+ final_chunks.append({"text": split_text, "page": chunk["page"], "document": chunk["document"]})
74
+ return final_chunks
75
+
76
+ # Vectorstore Initialization
77
+ def get_vectorstore(text_chunks):
78
+ if not text_chunks:
79
+ raise ValueError("text_chunks is empty. Cannot initialize FAISS vectorstore.")
80
+
81
+ #model_name = "BAAI/bge-large-en-v1.5"
82
+ #encode_kwargs = {'normalize_embeddings': True}
83
+ embeddings = OpenAIEmbeddings(model="text-embedding-3-large")
84
+ texts = [chunk["text"] for chunk in text_chunks]
85
+ metadatas = [{"page": chunk["page"], "document": chunk["document"]} for chunk in text_chunks]
86
+
87
+ return FAISS.from_texts(texts, embedding=embeddings, metadatas=metadatas)
88
+
89
+ def set_global_vectorstore(vectorstore):
90
+ global vectorstore_global
91
+ vectorstore_global = vectorstore
92
+
93
+ kw_model = KeyBERT()
94
+
95
+ def faiss_search_with_keywords(query):
96
+ global vectorstore_global
97
+ if vectorstore_global is None:
98
+ raise ValueError("FAISS vectorstore is not initialized.")
99
+
100
+ # Extract keywords from the query
101
+ keywords = kw_model.extract_keywords(query, keyphrase_ngram_range=(1,2), stop_words='english', top_n=5)
102
+ refined_query = " ".join([keyword[0] for keyword in keywords])
103
+
104
+ retriever = vectorstore_global.as_retriever(search_kwargs={"k": 13})
105
+ docs = retriever.get_relevant_documents(refined_query)
106
+
107
+ return '\n\n'.join([f"[Page {doc.metadata.get('page', 'Unknown')}] {doc.page_content}" for doc in docs])
108
+
109
+ def self_reasoning(query, context):
110
+ llm = ChatOpenAI(model="gpt-4", temperature=0.3)
111
+ reasoning_prompt = f"""
112
+ You are an AI assistant that analyzes the context provided to answer the user's query comprehensively and clearly.
113
+ Answer in a concise, factual way using the terminology from the context. Avoid extra explanation unless explicitly asked.
114
+ If asked for the page number, mention that the provided page number is for the document, not the labeled page number.
115
+ ### Example 1:
116
+ **Question:** What is the purpose of the MODTRAN GUI?
117
+ **Context:**
118
+ [Page 10 of the docuemnt] The MODTRAN GUI helps users set parameters and visualize the model's output.
119
+ **Answer:** The MODTRAN GUI assists users in parameter setup and output visualization. You can find the answer at Page 10 of the document provided.
120
+
121
+ ### Example 2:
122
+ **Question:** How do you run MODTRAN on Linux?
123
+ **Context:**
124
+ [Page 15 of the docuemnt] On Linux systems, MODTRAN can be run using the `mod6c` binary via terminal.
125
+ **Answer:** Use the `mod6c` binary via terminal. (Page 15)
126
+
127
+ ### Now answer:
128
+ **Question:** {query}
129
+ **Context:**
130
+ {context}
131
+
132
+ **Answer:**
133
+ """
134
+ response = llm.predict(reasoning_prompt)
135
+ return response
136
+
137
+ def faiss_search_with_reasoning(query):
138
+ global vectorstore_global
139
+ if vectorstore_global is None:
140
+ raise ValueError("FAISS vectorstore is not initialized.")
141
+
142
+ retriever = vectorstore_global.as_retriever(search_kwargs={"k": 13})
143
+ docs = retriever.get_relevant_documents(query)
144
+
145
+ # Rerank using cross-encoder
146
+ #pairs = [(query, doc.page_content) for doc in docs]
147
+ #scores = reranker.predict(pairs)
148
+ #reranked_docs = sorted(zip(scores, docs), key=lambda x: x[0], reverse=True)
149
+ #top_docs = [doc for _, doc in reranked_docs[:5]]
150
+
151
+ context = '\n\n'.join([f"[Page {doc.metadata.get('page', 'Unknown')}] {doc.page_content.strip()}" for doc in docs])
152
+ return self_reasoning(query, context)
153
+
154
+
155
+ faiss_keyword_tool = Tool(
156
+ name="FAISS Keyword Search",
157
+ func=faiss_search_with_keywords,
158
+ description="Searches FAISS with a keyword-based approach to retrieve context."
159
+ )
160
+
161
+ faiss_reasoning_tool = Tool(
162
+ name="FAISS Reasoning Search",
163
+ func=faiss_search_with_reasoning,
164
+ description="Searches FAISS with detailed reasoning to retrieve context."
165
+ )
166
+
167
+ # Agent Initialization
168
+ def initialize_chatbot_agent():
169
+ llm = ChatOpenAI(model="gpt-4", temperature=0.3)
170
+ memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
171
+ tools = [faiss_keyword_tool, faiss_reasoning_tool]
172
+ agent = initialize_agent(
173
+ tools=tools,
174
+ llm=llm,
175
+ agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
176
+ memory=memory,
177
+ verbose=False,
178
+ handle_parsing_errors=True)
179
+ return agent
180
+
181
+ # Query Handler
182
+ def handle_user_query(query, agent):
183
+ response = agent.run(query)
184
+ return response
185
+
186
+ # Main Streamlit App
187
+ def main():
188
+ global vectorstore_global
189
+ load_environment()
190
+
191
+ if "agent" not in st.session_state:
192
+ st.session_state.agent = None
193
+ if "chat_history" not in st.session_state:
194
+ st.session_state.chat_history = []
195
+
196
+ st.header("Chat with MODTRAN Documents :satellite:")
197
+ user_question = st.text_input("Ask a question about your uploaded files:")
198
+
199
+ with st.sidebar:
200
+ uploaded_files = st.file_uploader("Upload PDF, HTML, or MODTRAN output files:", accept_multiple_files=True)
201
+ if st.button("Process") and uploaded_files:
202
+ with st.spinner("Processing..."):
203
+ raw_text = get_uploaded_text(uploaded_files)
204
+ print(f"Total text chunks: {len(raw_text)}")
205
+ if raw_text:
206
+ print("Example chunk:", raw_text[0])
207
+ text_chunks = get_text_chunks(raw_text)
208
+ vectorstore_global = get_vectorstore(text_chunks)
209
+ st.session_state.agent = initialize_chatbot_agent()
210
+ st.success("Files processed successfully!")
211
+
212
+ if st.session_state.agent and user_question:
213
+ response = handle_user_query(user_question, st.session_state.agent)
214
+ st.session_state.chat_history.append({"user": user_question, "bot": response})
215
+
216
+ for chat in st.session_state.chat_history:
217
+ st.write(f"**You:** {chat['user']}")
218
+ st.write(f"**Bot:** {chat['bot']}")
219
+
220
+ if __name__ == "__main__":
221
+ load_environment()
222
+ main()
modtran_dataset.csv ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ question,answer
2
+ What atmospheric models are included with MODTRAN?,"Tropical, mid-latitude summer, mid-latitude winter, sub-arctic summer, sub-arctic winter, U.S. standard"
3
+ Can you tell me the page number where I can find this-What atmospheric models are included with MODTRAN?,Page 19
4
+ How do I set the atmospheric water vapor content to the standard atmosphere?,Set H2OSTR to 1.0
5
+ Can you tell me the page number where I can find this-How do I set the atmospheric water vapor content to the standard atmosphere?,Page 52
6
+ How do I set the surface temperature to 279 K?,Set TPTEMP to 279
7
+ Can you tell me the page number where I can find this-How do I set the surface temperature to 279 K?,Page 156
8
+ "If I want to specify the amount of oxygen in the atmosphere, what field is relevant?",PROF_O2
9
+ "Can you tell me the page number where I can find this-If I want to specify the amount of oxygen in the atmosphere, what field is relevant?",Page 56
10
+ How do I set the the aerosol visibility to urban?,Set field [MODTRANINPUT][AEROSOLS][IHAZE] to AER_URBAN
11
+ Can you tell me the page number where I can find this-How do I set the the aerosol visibility to urban?,Page 60
12
+ "In the configuration file, how do I set surface reflectivity to 60%.",Set field [MODTRANINPUT][SURFACE][SURREF] to 0.6
13
+ "Can you tell me the page number where I can find this-In the configuration file, how do I set surface reflectivity to 60%.","Page 37, 81"
14
+ How do you call the MODTRAN GUI from the command line?,mod6gui
15
+ Can you tell me the page number where I can find this-How do you call the MODTRAN GUI from the command line?,Page 15
16
+ "If you want to run MODTRAN from the command line using an input json file, what is the command?",mod6c_cons
17
+ "Can you tell me the page number where I can find this-If you want to run MODTRAN from the command line using an input json file, what is the command?","Page 13, 14"
18
+ What file includes the full radiance data?,tp7
19
+ Can you tell me the page number where I can find this-What file includes the full radiance data?,Page 88
20
+ What file includes the radiance data convolved with a user-supplied SRF?,chn
21
+ Can you tell me the page number where I can find this- What file includes the radiance data convolved with a user-supplied SRF?,Page 11
22
+ What range of solar zenith angle are allowed?,0 to 180
23
+ Can you tell me the page number where I can find this-What range of solar zenith angle are allowed?,Page 78
24
+ "How to set a surface ground temperature, distinct from the surface air temperature, for lines-of-sight not terminating at the ground?",Set SURFACE keyword SURREF to either ?LAMBER? or ?BRDF?; set SURFACE keyword NSURF to 2 and set SURFACE keyword AATEMP to the desired surface ground temperature in degrees Kelvin.
25
+ "Can you tell me the page number where I can find this-How to set a surface ground temperature, distinct from the surface air temperature, for lines-of-sight not terminating at the ground?",Page 156
26
+ "If I want to specify the amount of nitrous oxide in the atmosphere, what field is relevant?",PROF_N2O
27
+ "Can you tell me the page number where I can find this-If I want to specify the amount of oxygen in the atmosphere, what field is relevant?",Page 56
28
+ What is the meaning of CHKRES Warning? ,DV is being increased from 3.000000 to 15.000000 CM-1. The output step size cannot be smaller than the band model resolution
29
+ Can you tell me the page number where I can find this- What is the meaning of CHKRES Warning? ,Page 96
30
+ What is the keyword used for JSONObject for spectral bandpass and related inputs?,SPECTRAL
31
+ Can you tell me the page number where I can find this - What is the keyword used for JSONObject for spectral bandpass and related inputs?,Page 45
modtran_eval_results.csv ADDED
@@ -0,0 +1,38 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ question,answer,predicted,BERTScore_F1
2
+ What atmospheric models are included with MODTRAN?,"Tropical, mid-latitude summer, mid-latitude winter, sub-arctic summer, sub-arctic winter, U.S. standard","MODTRAN provides 6 built-in model atmospheres: Tropical, Mid-latitude summer, Mid-latitude winter, Sub-arctic summer, Sub-arctic winter, and US Standard 1976. Users can also enter their own profiles. (Page 89)",0.89045244
3
+ Can you tell me the page number where I can find this-What atmospheric models are included with MODTRAN?,Page 19,"Tropical, Mid-latitude summer, Mid-latitude winter, Sub-arctic summer, Sub-arctic winter, and US Standard 1976 are included with MODTRAN. (Page 89)",0.8110852
4
+ How do I set the atmospheric water vapor content to the standard atmosphere?,Set H2OSTR to 1.0,"Select ""US Standard 1976"" from the ""Model"" dropdown menu in the Atmosphere tab.",0.82688975
5
+ Can you tell me the page number where I can find this-How do I set the atmospheric water vapor content to the standard atmosphere?,Page 52,"To set the atmospheric water vapor content to the standard atmosphere, select one of the six built-in model atmospheres, which include the ""US Standard 1976,"" using the ""Model"" options in the Atmosphere tab (Page 11). You can also create user-defined profiles (Page 11). Another option is to use the 'MODEL' keyword within the 'ATMOSPHERE' JSONObject (Page 28).",0.7879687
6
+ How do I set the surface temperature to 279 K?,Set TPTEMP to 279,"Uncheck the ""Default Temperature"" box in the Surfaces tab and enter 279 in the adjacent box. Ensure the units are set to Kelvin.",0.82670957
7
+ Can you tell me the page number where I can find this-How do I set the surface temperature to 279 K?,Page 156,"Remove the check on the **Default** box following **Temperature**. Then enter the desired ground temperature (279 K), using radio buttons to choose between Kelvin and Celsius units. (Page 21)",0.8073552
8
+ "If I want to specify the amount of oxygen in the atmosphere, what field is relevant?",PROF_O2,"To specify the amount of oxygen, use the `O2STR` keyword within the `ATMOSPHERE` JSONObject. If using a user-defined profile (`MODEL` = `ATM_USER_ALT_PROFILE`), oxygen values are specified within the `""PROFILES""` array using `""TYPE"":""PROF_OXYGEN""`. (Pages 41, 47-48, 89, 91)",0.8142033
9
+ "Can you tell me the page number where I can find this-If I want to specify the amount of oxygen in the atmosphere, what field is relevant?",Page 56,"Any of the molecular profiles can be scaled. A scale factor of 0.0000 is interpreted as no scaling, equivalent to 1.0000. (Page 11)",0.82349986
10
+ How do I set the the aerosol visibility to urban?,Set field [MODTRANINPUT][AEROSOLS][IHAZE] to AER_URBAN,"Select ""Urban"" from the *Model* drop-down menu in the *Aerosols* section of the *Clouds & Aerosols* window. (Page 13)",0.8157179
11
+ Can you tell me the page number where I can find this-How do I set the the aerosol visibility to urban?,Page 60,"Page 13: MODTRAN includes 9 built-in aerosol models, one of which is ""Urban"". You can select it from the *Model* drop-down menu in the *Aerosols* section of the *Clouds & Aerosols* Window.",0.82025063
12
+ "In the configuration file, how do I set surface reflectivity to 60%.",Set field [MODTRANINPUT][SURFACE][SURREF] to 0.6,"To set a constant surface reflectivity to 60%, set `SURFTYPE` to `REFL_CONSTANT` and enter `0.6` in the `REFLECTANCE` box. Additionally, page 21 describes setting constant reflectance, and page 35 shows a configuration snippet with `SURFTYPE` and reflectivity values.",0.8203288
13
+ "Can you tell me the page number where I can find this-In the configuration file, how do I set surface reflectivity to 60%.","Page 37, 81","To set the surface reflectivity to 60%, set the value of the `SURREF` keyword to 0.6 when `SURFTYPE` is set to `REFL_CONSTANT`. (Page 23)",0.7944811
14
+ How do you call the MODTRAN GUI from the command line?,mod6gui,"To run the MODTRAN GUI in Windows, click the ""MODTRAN6 GUI"" shortcut. For Linux and Mac, run the script `<path>/bin/linux/mod6gui` or `<path>/bin/macos/mod6gui` respectively, where `<path>` is the MODTRAN6 directory. (Page 6)",0.8081023
15
+ Can you tell me the page number where I can find this-How do you call the MODTRAN GUI from the command line?,Page 15,"For Linux and Mac users, the GUI is initialized by running a script: `<...>/bin/linux/mod6gui` or `<...>/bin/macos/mod6gui` where `<...>` is the full or relative path to the MODTRAN6 directory. (Page 6)",0.77987325
16
+ "If you want to run MODTRAN from the command line using an input json file, what is the command?",mod6c_cons,The provided text describes how to run MODTRAN using the GUI or by converting .tp5 files to .json files. It does not contain the command to run MODTRAN from the command line using a .json input file.,0.7959351
17
+ "Can you tell me the page number where I can find this-If you want to run MODTRAN from the command line using an input json file, what is the command?","Page 13, 14","To run MODTRAN from the command line using an input JSON file, see instructions mentioned on Page 27.",0.80603164
18
+ What file includes the full radiance data?,tp7,"The files containing full radiance data are denoted by `.r_k` (r_kdis.dat) and `_b.r_k` (r_kdis.bin). (Page 4.7) Additionally, spectral radiance data can be found in `.tp7` (tape7),`_b.tp7` (tape7b), `.plt` (pltout), `_b.plt` (pltoutb), and within the ""FLUXES"" JSONObject when multiple scattering calculations are performed. (Pages 4.3, 4.5, and 81)",0.7743452
19
+ Can you tell me the page number where I can find this-What file includes the full radiance data?,Page 88,"The files with the full radiance data are specified as ""*.r_k"" and ""*_b.r_k"". (Page 4.7)",0.8054742
20
+ What file includes the radiance data convolved with a user-supplied SRF?,chn,The file `<ROOTNAME>_scan.csv` includes the radiance data convolved with a user-supplied SRF. (Page 71),0.7839959
21
+ Can you tell me the page number where I can find this- What file includes the radiance data convolved with a user-supplied SRF?,Page 11,r_kdis.dat (Page 4.7),0.83215964
22
+ What range of solar zenith angle are allowed?,0 to 180 ,The allowed solar zenith angles range from 0° to 180°. (Page 55),0.83336747
23
+ Can you tell me the page number where I can find this-What range of solar zenith angle are allowed?,Page 78,"Solar zenith angles are defined between 0° and 180°. This information can be found across multiple pages, including those discussing geometry inputs and solar scattering angles, such as page 55 (where specific examples of 30° are given). There is no single page that states the allowed range.",0.79898494
24
+ "How to set a surface ground temperature, distinct from the surface air temperature, for lines-of-sight not terminating at the ground?",Set SURFACE keyword SURREF to either ?LAMBER? or ?BRDF?; set SURFACE keyword NSURF to 2 and set SURFACE keyword AATEMP to the desired surface ground temperature in degrees Kelvin.,"To set a surface ground temperature different from the surface air temperature for lines-of-sight not terminating at the ground:
25
+
26
+ 1. Set the `SURFACE` keyword `LAMBER` or `BRDF`.
27
+ 2. Set the `SURFACE` keyword `NSURF` to 2.
28
+ 3. Set the `SURFACE` keyword `AATEMP` to the desired ground temperature in Kelvin.
29
+
30
+
31
+ If a temperature is specified using the ""Temperature"" box in the GUI and the ""Default Temperature"" box is unchecked, grey-body surface emission will be included even if the LOS doesn't intersect the ground.",0.87613213
32
+ "Can you tell me the page number where I can find this-How to set a surface ground temperature, distinct from the surface air temperature, for lines-of-sight not terminating at the ground?",Page 156,"To define the ground surface temperature for lines-of-sight not terminating at the ground, set SURFACE keyword LAMBER or BRDF; set SURFACE keyword NSURF to 2; and set SURFACE keyword AATEMP to the desired temperature in Kelvin. (Page 98)",0.79768395
33
+ "If I want to specify the amount of nitrous oxide in the atmosphere, what field is relevant?",PROF_N2O,The `PROF_N2O` or `PROF_NITROUS_OXIDE` field is relevant for specifying the amount of nitrous oxide. (Page 47),0.8499733
34
+ "Can you tell me the page number where I can find this-If I want to specify the amount of oxygen in the atmosphere, what field is relevant?",Page 56,"Any of the molecular profiles can be scaled, including O3. A scale factor of 0.0000 is interpreted as no scaling. If you want to zero out the O3 profile, use the drop-down boxes to replace ""Scaled"" with column density units of either g/cm^2 or atm-cm. (Page 11)",0.80292183
35
+ What is the meaning of CHKRES Warning? ,DV is being increased from 3.000000 to 15.000000 CM-1. The output step size cannot be smaller than the band model resolution,"CHKRES warnings are generated when spectral response functions do not drop to zero at their endpoints. MODTRAN models the responses as zero outside the spectral range, generating the warning. Also, super refractive conditions, where the line of sight turns downward, can cause a CHKRES warning, but only for non-vertical paths. It is important to note that warnings generally do not indicate faulty calculations. (Pages 38, 46)",0.82513857
36
+ Can you tell me the page number where I can find this- What is the meaning of CHKRES Warning? ,Page 96,"The meaning of CHKRES warning is explained on page 46. It occurs when the output spectral step size exceeds the spectral resolution, resulting in gaps in spectral coverage.",0.81771094
37
+ What is the keyword used for JSONObject for spectral bandpass and related inputs?,SPECTRAL,SPECTRAL (Page 30),0.94234455
38
+ Can you tell me the page number where I can find this - What is the keyword used for JSONObject for spectral bandpass and related inputs?,Page 45,"SPECTRAL is the keyword used for JSONObject for spectral bandpass and related inputs. (Page 30, 31, 78)",0.8083677
modtran_gemini.py ADDED
@@ -0,0 +1,271 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import subprocess
4
+ import pdfplumber
5
+ from lxml import etree
6
+ from bs4 import BeautifulSoup
7
+ from PyPDF2 import PdfReader
8
+ from langchain_community.vectorstores import FAISS
9
+ from langchain.embeddings.base import Embeddings
10
+ from langchain_openai import ChatOpenAI
11
+ from langchain.agents import initialize_agent, AgentType
12
+ from langchain.agents import Tool
13
+ from langchain.memory import ConversationBufferMemory
14
+ from langchain.text_splitter import CharacterTextSplitter
15
+ from dotenv import load_dotenv
16
+ from keybert import KeyBERT
17
+ from sentence_transformers import CrossEncoder
18
+ import google.generativeai as genai
19
+ from typing import List
20
+ from langchain_core.language_models import BaseLanguageModel
21
+
22
+ import google.generativeai as genai
23
+
24
+
25
+ class GeminiLLM(BaseLanguageModel):
26
+ def __init__(self, model_name="models/gemini-1.5-pro-latest", api_key=None):
27
+ self.api_key = api_key or st.secrets["GOOGLE_API_KEY"]
28
+ if not self.api_key:
29
+ raise ValueError("GOOGLE_API_KEY not found in Streamlit secrets.")
30
+ genai.configure(api_key=self.api_key)
31
+ self.model = genai.GenerativeModel(model_name)
32
+
33
+ def _call(self, prompt, stop=None):
34
+ response = self.model.generate_content(prompt)
35
+ return response.text
36
+
37
+ @property
38
+ def _llm_type(self):
39
+ return "custom_gemini"
40
+
41
+ class GeminiEmbeddings(Embeddings):
42
+ def __init__(self, model_name="models/embedding-001", api_key=None):
43
+ api_key = "AIzaSyBIfGJRoet_wzzYXIiWXxStkIigEOzSR2o"
44
+ if not api_key:
45
+ raise ValueError("GOOGLE_API_KEY not found in environment variables.")
46
+ os.environ["GOOGLE_API_KEY"] = api_key
47
+ genai.configure(api_key=api_key)
48
+ self.model_name = model_name
49
+
50
+ def embed_documents(self, texts: List[str]) -> List[List[float]]:
51
+ return [
52
+ genai.embed_content(
53
+ model=self.model_name,
54
+ content=text,
55
+ task_type="retrieval_document"
56
+ )["embedding"]
57
+ for text in texts
58
+ ]
59
+
60
+ def embed_query(self, text: str) -> List[float]:
61
+ return genai.embed_content(
62
+ model=self.model_name,
63
+ content=text,
64
+ task_type="retrieval_query"
65
+ )["embedding"]
66
+
67
+
68
+ class GeminiLLM:
69
+ def __init__(self, model_name="models/gemini-1.5-pro-latest", api_key=None):
70
+ api_key = api_key or os.getenv("GOOGLE_API_KEY")
71
+ if not api_key:
72
+ raise ValueError("Missing GOOGLE_API_KEY")
73
+ genai.configure(api_key=api_key)
74
+ self.model = genai.GenerativeModel(model_name)
75
+
76
+ def predict(self, prompt: str) -> str:
77
+ response = self.model.generate_content(prompt)
78
+ return response.text.strip()
79
+
80
+ reranker = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2')
81
+
82
+ vectorstore_global = None
83
+
84
+ def load_environment():
85
+ load_dotenv()
86
+ genai.configure(api_key=os.getenv("GOOGLE_API_KEY"))
87
+
88
+
89
+ def convert_pdf_to_xml(pdf_file, xml_path):
90
+ os.makedirs("temp", exist_ok=True)
91
+ pdf_path = os.path.join("temp", pdf_file.name)
92
+ with open(pdf_path, 'wb') as f:
93
+ f.write(pdf_file.getbuffer())
94
+ subprocess.run(["pdftohtml", "-xml", pdf_path, xml_path], check=True)
95
+ return xml_path
96
+
97
+ def extract_text_from_xml(xml_path, document_name):
98
+ tree = etree.parse(xml_path)
99
+ text_chunks = []
100
+ for page in tree.xpath("//page"):
101
+ page_num = int(page.get("number", 0))
102
+ texts = [text.text for text in page.xpath('.//text') if text.text]
103
+ combined_text = '\n'.join(texts)
104
+ text_chunks.append({"text": combined_text, "page": page_num, "document": document_name})
105
+ return text_chunks
106
+
107
+ def get_uploaded_text(uploaded_files):
108
+ raw_text = []
109
+ for uploaded_file in uploaded_files:
110
+ document_name = uploaded_file.name
111
+ if document_name.endswith(".pdf"):
112
+ xml_path = os.path.join("temp", document_name.replace(".pdf", ".xml"))
113
+ text_chunks = extract_text_from_xml(convert_pdf_to_xml(uploaded_file, xml_path), document_name)
114
+ raw_text.extend(text_chunks)
115
+ elif uploaded_file.name.endswith((".html", ".htm")):
116
+ soup = BeautifulSoup(uploaded_file.getvalue(), 'lxml')
117
+ raw_text.append({"text": soup.get_text(), "page": None, "document": document_name})
118
+ elif uploaded_file.name.endswith((".txt")):
119
+ content = uploaded_file.getvalue().decode("utf-8")
120
+ raw_text.append({"text": content, "page": None, "document": document_name})
121
+ return raw_text
122
+
123
+ def get_text_chunks(raw_text):
124
+ splitter = CharacterTextSplitter(separator='\n', chunk_size=500, chunk_overlap=100)
125
+ final_chunks = []
126
+ for chunk in raw_text:
127
+ for split_text in splitter.split_text(chunk["text"]):
128
+ final_chunks.append({"text": split_text, "page": chunk["page"], "document": chunk["document"]})
129
+ return final_chunks
130
+
131
+ def get_vectorstore(text_chunks):
132
+ if not text_chunks:
133
+ raise ValueError("text_chunks is empty. Cannot initialize FAISS vectorstore.")
134
+
135
+ embeddings = GeminiEmbeddings()
136
+ texts = [chunk["text"] for chunk in text_chunks]
137
+ metadatas = [{"page": chunk["page"], "document": chunk["document"]} for chunk in text_chunks]
138
+
139
+ return FAISS.from_texts(texts, embedding=embeddings, metadatas=metadatas)
140
+
141
+ def set_global_vectorstore(vectorstore):
142
+ global vectorstore_global
143
+ vectorstore_global = vectorstore
144
+
145
+ kw_model = KeyBERT()
146
+
147
+ def self_reasoning(query, context):
148
+ llm = GeminiLLM()
149
+ reasoning_prompt = f"""
150
+ You are an AI assistant that analyzes the context provided to answer the user's query comprehensively and clearly.
151
+ Answer in a concise, factual way using the terminology from the context. Avoid extra explanation unless explicitly asked.
152
+ YOU MUST mention the page number.
153
+ ### Example 1:
154
+ **Question:** What is the purpose of the MODTRAN GUI?
155
+ **Context:**
156
+ [Page 10 of the docuemnt] The MODTRAN GUI helps users set parameters and visualize the model's output.
157
+ **Answer:** The MODTRAN GUI assists users in parameter setup and output visualization. You can find the answer at Page 10 of the document provided.
158
+
159
+ ### Example 2:
160
+ **Question:** How do you run MODTRAN on Linux? Answer with page number.
161
+ **Context:**
162
+ [Page 15 of the docuemnt] On Linux systems, MODTRAN can be run using the `mod6c` binary via terminal.
163
+ **Answer:** Use the `mod6c` binary via terminal. (Page 15 of the document)
164
+
165
+ ### Now answer:
166
+ **Question:** {query}
167
+ **Context:**
168
+ {context}
169
+
170
+ **Answer:**
171
+ """
172
+ return llm.predict(reasoning_prompt)
173
+
174
+ def faiss_search_with_keywords(query):
175
+ global vectorstore_global
176
+ if vectorstore_global is None:
177
+ raise ValueError("FAISS vectorstore is not initialized.")
178
+ keywords = kw_model.extract_keywords(query, keyphrase_ngram_range=(1,2), stop_words='english', top_n=5)
179
+ refined_query = " ".join([keyword[0] for keyword in keywords])
180
+ retriever = vectorstore_global.as_retriever(search_kwargs={"k": 13})
181
+ docs = retriever.get_relevant_documents(refined_query)
182
+ context= '\n\n'.join([f"[Page {doc.metadata.get('page', 'Unknown')}] {doc.page_content}" for doc in docs])
183
+ return self_reasoning(query, context)
184
+
185
+ def faiss_search_with_reasoning(query):
186
+ global vectorstore_global
187
+ if vectorstore_global is None:
188
+ raise ValueError("FAISS vectorstore is not initialized.")
189
+ retriever = vectorstore_global.as_retriever(search_kwargs={"k": 13})
190
+ docs = retriever.get_relevant_documents(query)
191
+ pairs = [(query, doc.page_content) for doc in docs]
192
+ scores = reranker.predict(pairs)
193
+ reranked_docs = sorted(zip(scores, docs), key=lambda x: x[0], reverse=True)
194
+ top_docs = [doc for _, doc in reranked_docs[:5]]
195
+ context = '\n\n'.join([f"[Page {doc.metadata.get('page', 'Unknown')}] {doc.page_content.strip()}" for doc in top_docs])
196
+ return self_reasoning(query, context)
197
+
198
+ faiss_keyword_tool = Tool(
199
+ name="FAISS Keyword Search",
200
+ func=faiss_search_with_keywords,
201
+ description="Searches FAISS with a keyword-based approach to retrieve context."
202
+ )
203
+
204
+ faiss_reasoning_tool = Tool(
205
+ name="FAISS Reasoning Search",
206
+ func=faiss_search_with_reasoning,
207
+ description="Searches FAISS with detailed reasoning to retrieve context."
208
+ )
209
+
210
+ def initialize_chatbot_agent():
211
+ llm = GeminiLLM() # <-- Gemini instead of OpenAI
212
+ memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
213
+ tools = [faiss_keyword_tool, faiss_reasoning_tool]
214
+ agent = initialize_agent(
215
+ tools=tools,
216
+ llm=llm,
217
+ agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
218
+ memory=memory,
219
+ verbose=False,
220
+ handle_parsing_errors=True
221
+ )
222
+ return agent
223
+
224
+ def handle_user_query(query):
225
+ # Same routing logic as in evaluation.py
226
+ global vectorstore_global
227
+ if vectorstore_global is None:
228
+ raise ValueError("Vectorstore is not initialized.")
229
+
230
+ if "how" in query.lower():
231
+ context = faiss_search_with_reasoning(query)
232
+ else:
233
+ context = faiss_search_with_keywords(query)
234
+ return self_reasoning(query, context)
235
+ def main():
236
+ load_environment()
237
+
238
+ if "chat_ready" not in st.session_state:
239
+ st.session_state.chat_ready = False
240
+ if "chat_history" not in st.session_state:
241
+ st.session_state.chat_history = []
242
+ if "vectorstore" not in st.session_state:
243
+ st.session_state.vectorstore = None
244
+
245
+ st.header("Chat with MODTRAN Documents :satellite:")
246
+ user_question = st.text_input("Ask a question about your uploaded files:")
247
+
248
+ with st.sidebar:
249
+ uploaded_files = st.file_uploader("Upload PDF, HTML, or MODTRAN output files:", accept_multiple_files=True)
250
+ if st.button("Process") and uploaded_files:
251
+ with st.spinner("Processing..."):
252
+ raw_text = get_uploaded_text(uploaded_files)
253
+ text_chunks = get_text_chunks(raw_text)
254
+ st.session_state.vectorstore = get_vectorstore(text_chunks)
255
+ set_global_vectorstore(st.session_state.vectorstore)
256
+ st.session_state.chat_ready = True
257
+ st.success("Files processed successfully!")
258
+
259
+ if st.session_state.chat_ready and user_question:
260
+ # Restore the global vectorstore reference
261
+ set_global_vectorstore(st.session_state.vectorstore)
262
+ response = handle_user_query(user_question)
263
+ st.session_state.chat_history.append({"user": user_question, "bot": response})
264
+
265
+ for chat in st.session_state.chat_history:
266
+ st.write(f"**You:** {chat['user']}")
267
+ st.write(f"**Bot:** {chat['bot']}")
268
+
269
+ if __name__ == "__main__":
270
+ load_environment()
271
+ main()
modtran_groq.py ADDED
@@ -0,0 +1,236 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import os
3
+ import subprocess
4
+ import pdfplumber
5
+ from lxml import etree
6
+ from bs4 import BeautifulSoup
7
+ from PyPDF2 import PdfReader
8
+ from langchain_community.vectorstores import FAISS
9
+ from langchain_community.embeddings import OpenAIEmbeddings
10
+ from langchain_community.embeddings import HuggingFaceBgeEmbeddings
11
+ from langchain_openai import ChatOpenAI
12
+ from langchain.agents import initialize_agent, AgentType
13
+ from langchain.agents import Tool
14
+ from langchain.memory import ConversationBufferMemory
15
+ from langchain.text_splitter import CharacterTextSplitter
16
+ from dotenv import load_dotenv
17
+ from keybert import KeyBERT
18
+ from sentence_transformers import CrossEncoder
19
+ from langchain_groq import ChatGroq
20
+ import sys
21
+ import asyncio
22
+
23
+ # Windows fix for asyncio compatibility
24
+ if sys.platform.startswith('win') and sys.version_info >= (3, 8):
25
+ asyncio.set_event_loop_policy(asyncio.WindowsSelectorEventLoopPolicy())
26
+
27
+ reranker = CrossEncoder('cross-encoder/ms-marco-MiniLM-L-6-v2')
28
+
29
+ # Initialize global variable
30
+ vectorstore_global = None
31
+
32
+ # Load OpenAI API key
33
+ def load_environment():
34
+ load_dotenv()
35
+
36
+ # PDF to XML Conversion
37
+ def convert_pdf_to_xml(pdf_file, xml_path):
38
+ os.makedirs("temp", exist_ok=True)
39
+ pdf_path = os.path.join("temp", pdf_file.name)
40
+ with open(pdf_path, 'wb') as f:
41
+ f.write(pdf_file.getbuffer())
42
+ subprocess.run(["pdftohtml", "-xml", pdf_path, xml_path], check=True)
43
+ return xml_path
44
+
45
+ # Extract text from XML
46
+ def extract_text_from_xml(xml_path, document_name):
47
+ from lxml import etree
48
+ tree = etree.parse(xml_path)
49
+ text_chunks = []
50
+ for page in tree.xpath("//page"):
51
+ page_num = int(page.get("number", 0))
52
+ texts = [text.text for text in page.xpath('.//text') if text.text]
53
+ combined_text = '\n'.join(texts)
54
+ text_chunks.append({"text": combined_text, "page": page_num, "document": document_name})
55
+ return text_chunks
56
+
57
+ # Process uploaded files
58
+ def get_uploaded_text(uploaded_files):
59
+ raw_text = []
60
+ print(f"Total uploaded files: {len(uploaded_files)}")
61
+ for uploaded_file in uploaded_files:
62
+ document_name = uploaded_file.name
63
+ if document_name.endswith(".pdf"):
64
+ xml_path = os.path.join("temp", document_name.replace(".pdf", ".xml"))
65
+ text_chunks = extract_text_from_xml(convert_pdf_to_xml(uploaded_file, xml_path), document_name)
66
+ raw_text.extend(text_chunks)
67
+ elif uploaded_file.name.endswith((".html", ".htm")):
68
+ soup = BeautifulSoup(uploaded_file.getvalue(), 'lxml')
69
+ raw_text.append({"text": soup.get_text(), "page": None, "document": document_name})
70
+ elif uploaded_file.name.endswith((".txt")):
71
+ content = uploaded_file.getvalue().decode("utf-8")
72
+ raw_text.append({"text": content, "page": None, "document": document_name})
73
+ return raw_text
74
+
75
+ # Text Chunking
76
+ def get_text_chunks(raw_text):
77
+ splitter = CharacterTextSplitter(separator='\n', chunk_size=500, chunk_overlap=100)
78
+ final_chunks = []
79
+ for chunk in raw_text:
80
+ for split_text in splitter.split_text(chunk["text"]):
81
+ final_chunks.append({"text": split_text, "page": chunk["page"], "document": chunk["document"]})
82
+ return final_chunks
83
+
84
+ # Vectorstore Initialization
85
+ def get_vectorstore(text_chunks):
86
+ if not text_chunks:
87
+ raise ValueError("text_chunks is empty. Cannot initialize FAISS vectorstore.")
88
+
89
+ #model_name = "BAAI/bge-large-en-v1.5"
90
+ #encode_kwargs = {'normalize_embeddings': True}
91
+ #embeddings = OpenAIEmbeddings(model="text-embedding-3-large")
92
+ embeddings = HuggingFaceBgeEmbeddings(
93
+ model_name="BAAI/bge-base-en-v1.5",
94
+ encode_kwargs={"normalize_embeddings": True}
95
+ )
96
+ texts = [chunk["text"] for chunk in text_chunks]
97
+ metadatas = [{"page": chunk["page"], "document": chunk["document"]} for chunk in text_chunks]
98
+
99
+ return FAISS.from_texts(texts, embedding=embeddings, metadatas=metadatas)
100
+
101
+ def set_global_vectorstore(vectorstore):
102
+ global vectorstore_global
103
+ vectorstore_global = vectorstore
104
+
105
+ kw_model = KeyBERT()
106
+
107
+ def faiss_search_with_keywords(query):
108
+ global vectorstore_global
109
+ if vectorstore_global is None:
110
+ raise ValueError("FAISS vectorstore is not initialized.")
111
+
112
+ # Extract keywords from the query
113
+ keywords = kw_model.extract_keywords(query, keyphrase_ngram_range=(1,2), stop_words='english', top_n=5)
114
+ refined_query = " ".join([keyword[0] for keyword in keywords])
115
+
116
+ retriever = vectorstore_global.as_retriever(search_kwargs={"k": 13})
117
+ docs = retriever.get_relevant_documents(refined_query)
118
+
119
+ return '\n\n'.join([f"[Page {doc.metadata.get('page', 'Unknown')}] {doc.page_content}" for doc in docs])
120
+
121
+ def self_reasoning(query, context):
122
+ llm = ChatOpenAI(model="gpt-4", temperature=0.3)
123
+ #llm = ChatGroq(temperature=0.3, model_name="llama3-8b-8192")
124
+ reasoning_prompt = f"""
125
+ You are an AI assistant that analyzes the context provided to answer the user's query comprehensively and clearly.
126
+ Answer in a concise, factual way using the terminology from the context. Avoid extra explanation unless explicitly asked.
127
+ If asked for the page number,YOU MUST mention the page number.
128
+ ### Example 1:
129
+ **Question:** What is the purpose of the MODTRAN GUI?
130
+ **Context:**
131
+ [Page 10 of the docuemnt] The MODTRAN GUI helps users set parameters and visualize the model's output.
132
+ **Answer:** The MODTRAN GUI assists users in parameter setup and output visualization. You can find the answer at Page 10 of the document provided.
133
+
134
+ ### Example 2:
135
+ **Question:** How do you run MODTRAN on Linux? Answer with page number.
136
+ **Context:**
137
+ [Page 15 of the docuemnt] On Linux systems, MODTRAN can be run using the `mod6c` binary via terminal.
138
+ **Answer:** Use the `mod6c` binary via terminal. (Page 15)
139
+
140
+ ### Now answer:
141
+ **Question:** {query}
142
+ **Context:**
143
+ {context}
144
+
145
+ **Answer:**
146
+ """
147
+ response = llm.predict(reasoning_prompt)
148
+ return response
149
+
150
+ def faiss_search_with_reasoning(query):
151
+ global vectorstore_global
152
+ if vectorstore_global is None:
153
+ raise ValueError("FAISS vectorstore is not initialized.")
154
+
155
+ retriever = vectorstore_global.as_retriever(search_kwargs={"k": 13})
156
+ docs = retriever.get_relevant_documents(query)
157
+
158
+ # Rerank using cross-encoder
159
+ #pairs = [(query, doc.page_content) for doc in docs]
160
+ #scores = reranker.predict(pairs)
161
+ #reranked_docs = sorted(zip(scores, docs), key=lambda x: x[0], reverse=True)
162
+ #top_docs = [doc for _, doc in reranked_docs[:5]]
163
+
164
+ context = '\n\n'.join([f"[Page {doc.metadata.get('page', 'Unknown')}] {doc.page_content.strip()}" for doc in docs])
165
+ return self_reasoning(query, context)
166
+
167
+
168
+ faiss_keyword_tool = Tool(
169
+ name="FAISS Keyword Search",
170
+ func=faiss_search_with_keywords,
171
+ description="Searches FAISS with a keyword-based approach to retrieve context."
172
+ )
173
+
174
+ faiss_reasoning_tool = Tool(
175
+ name="FAISS Reasoning Search",
176
+ func=faiss_search_with_reasoning,
177
+ description="Searches FAISS with detailed reasoning to retrieve context."
178
+ )
179
+
180
+ # Agent Initialization
181
+ def initialize_chatbot_agent():
182
+ llm = ChatOpenAI(model="gpt-4", temperature=0.3)
183
+ #llm = ChatGroq(temperature=0.3, model_name="llama3-8b-8192")
184
+ memory = ConversationBufferMemory(memory_key="chat_history", return_messages=True)
185
+ tools = [faiss_keyword_tool, faiss_reasoning_tool]
186
+ agent = initialize_agent(
187
+ tools=tools,
188
+ llm=llm,
189
+ agent=AgentType.ZERO_SHOT_REACT_DESCRIPTION,
190
+ memory=memory,
191
+ verbose=False,
192
+ handle_parsing_errors=True)
193
+ return agent
194
+
195
+ # Query Handler
196
+ def handle_user_query(query, agent):
197
+ response = agent.run(query)
198
+ return response
199
+
200
+ # Main Streamlit App
201
+ def main():
202
+ global vectorstore_global
203
+ load_environment()
204
+
205
+ if "agent" not in st.session_state:
206
+ st.session_state.agent = None
207
+ if "chat_history" not in st.session_state:
208
+ st.session_state.chat_history = []
209
+
210
+ st.header("Chat with MODTRAN Documents :satellite:")
211
+ user_question = st.text_input("Ask a question about your uploaded files:")
212
+
213
+ with st.sidebar:
214
+ uploaded_files = st.file_uploader("Upload PDF, HTML, or MODTRAN output files:", accept_multiple_files=True)
215
+ if st.button("Process") and uploaded_files:
216
+ with st.spinner("Processing..."):
217
+ raw_text = get_uploaded_text(uploaded_files)
218
+ print(f"Total text chunks: {len(raw_text)}")
219
+ if raw_text:
220
+ print("Example chunk:", raw_text[0])
221
+ text_chunks = get_text_chunks(raw_text)
222
+ vectorstore_global = get_vectorstore(text_chunks)
223
+ st.session_state.agent = initialize_chatbot_agent()
224
+ st.success("Files processed successfully!")
225
+
226
+ if st.session_state.agent and user_question:
227
+ response = handle_user_query(user_question, st.session_state.agent)
228
+ st.session_state.chat_history.append({"user": user_question, "bot": response})
229
+
230
+ for chat in st.session_state.chat_history:
231
+ st.write(f"**You:** {chat['user']}")
232
+ st.write(f"**Bot:** {chat['bot']}")
233
+
234
+ if __name__ == "__main__":
235
+ load_environment()
236
+ main()
requirements.txt ADDED
@@ -0,0 +1,17 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ streamlit
2
+ pandas
3
+ scikit-learn
4
+ pdfplumber
5
+ PyPDF2
6
+ beautifulsoup4
7
+ lxml
8
+ python-dotenv
9
+ keybert
10
+ sentence-transformers
11
+ langchain
12
+ langchain-community
13
+ langchain-openai
14
+ google-generativeai
15
+ transformers
16
+ torch
17
+ bert-score