Spaces:
Running
on
L4
Running
on
L4
Commit
·
c1f91db
1
Parent(s):
f7429e0
refactor codes
Browse files- app.py +5 -4
- utils/help.py +5 -6
- utils/rag_utils.py +6 -0
app.py
CHANGED
@@ -10,7 +10,7 @@ import random
|
|
10 |
|
11 |
from utils.help import get_disclaimer
|
12 |
from utils.format import sec_to_time, fix_latex, get_youtube_embed
|
13 |
-
from utils.rag_utils import load_youtube_data, load_book_data, load_summary, fixed_knn_retrieval
|
14 |
from utils.system_prompts import get_expert_system_prompt, get_synthesis_system_prompt
|
15 |
from utils.openai_utils import embed_question_openai, openai_domain_specific_answer_generation, openai_context_integration
|
16 |
from utils.llama_utils import get_bnb_config, load_base_model, load_fine_tuned_model, generate_response
|
@@ -139,7 +139,6 @@ if "question" not in st.session_state:
|
|
139 |
st.session_state.question = ""
|
140 |
|
141 |
|
142 |
-
|
143 |
text_area_placeholder = st.empty()
|
144 |
question_help = "Including details or instructions improves the answer."
|
145 |
st.session_state.question = text_area_placeholder.text_area(
|
@@ -156,7 +155,7 @@ with col1:
|
|
156 |
with col2:
|
157 |
if st.button("Random Question"):
|
158 |
while True:
|
159 |
-
random_question = get_random_question()
|
160 |
if random_question != st.session_state.question:
|
161 |
break
|
162 |
st.session_state.question = random_question
|
@@ -170,9 +169,11 @@ with col2:
|
|
170 |
# Load YouTube and LaTeX data
|
171 |
text_data_YT, context_embeddings_YT = load_youtube_data(base_path, model_name, yt_chunk_tokens, yt_overlap_tokens)
|
172 |
text_data_Latex, context_embeddings_Latex = load_book_data(base_path, model_name, latex_chunk_tokens, latex_overlap_tokens)
|
173 |
-
|
174 |
summary = load_summary('data/KG_FEM_summary.json')
|
175 |
|
|
|
|
|
|
|
176 |
if 'question_answered' not in st.session_state:
|
177 |
st.session_state.question_answered = False
|
178 |
if 'context_by_video' not in st.session_state:
|
|
|
10 |
|
11 |
from utils.help import get_disclaimer
|
12 |
from utils.format import sec_to_time, fix_latex, get_youtube_embed
|
13 |
+
from utils.rag_utils import load_youtube_data, load_book_data, load_summary, fixed_knn_retrieval, get_random_question
|
14 |
from utils.system_prompts import get_expert_system_prompt, get_synthesis_system_prompt
|
15 |
from utils.openai_utils import embed_question_openai, openai_domain_specific_answer_generation, openai_context_integration
|
16 |
from utils.llama_utils import get_bnb_config, load_base_model, load_fine_tuned_model, generate_response
|
|
|
139 |
st.session_state.question = ""
|
140 |
|
141 |
|
|
|
142 |
text_area_placeholder = st.empty()
|
143 |
question_help = "Including details or instructions improves the answer."
|
144 |
st.session_state.question = text_area_placeholder.text_area(
|
|
|
155 |
with col2:
|
156 |
if st.button("Random Question"):
|
157 |
while True:
|
158 |
+
random_question = get_random_question(base_path + "/questions.txt")
|
159 |
if random_question != st.session_state.question:
|
160 |
break
|
161 |
st.session_state.question = random_question
|
|
|
169 |
# Load YouTube and LaTeX data
|
170 |
text_data_YT, context_embeddings_YT = load_youtube_data(base_path, model_name, yt_chunk_tokens, yt_overlap_tokens)
|
171 |
text_data_Latex, context_embeddings_Latex = load_book_data(base_path, model_name, latex_chunk_tokens, latex_overlap_tokens)
|
|
|
172 |
summary = load_summary('data/KG_FEM_summary.json')
|
173 |
|
174 |
+
|
175 |
+
|
176 |
+
|
177 |
if 'question_answered' not in st.session_state:
|
178 |
st.session_state.question_answered = False
|
179 |
if 'context_by_video' not in st.session_state:
|
utils/help.py
CHANGED
@@ -1,11 +1,10 @@
|
|
1 |
|
2 |
def get_disclaimer():
|
3 |
-
|
4 |
|
5 |
-
|
6 |
|
7 |
-
|
8 |
|
9 |
-
|
10 |
-
|
11 |
-
return disc
|
|
|
1 |
|
2 |
def get_disclaimer():
|
3 |
+
return """:gray[AI Teaching Assistant is developed at the University of Southern California by Mostafa Faghih Shojaei, Rahul Gulati, Benjamin Jasperson, Shangshang Wang, Simone Cimolato, Dangli Cao, Willie Neiswanger, and Krishna Garikipati.]
|
4 |
|
5 |
+
:gray[**Main Data Sources:**] [Introduction to Finite Element Methods (FEM) by Prof. Krishna Garikipati](https://www.youtube.com/playlist?list=PLJhG_d-Sp_JHKVRhfTgDqbic_4MHpltXZ) :gray[and] [The Finite Element Method: Linear Static and Dynamic Finite Element Analysis by Thomas J. R. Hughes](https://www.google.com/books/edition/_/cHH2n_qBK0IC?hl=en).
|
6 |
|
7 |
+
:gray[**Disclaimer and Copyright Notice:**] :gray[1. AI-Generated Responses: Answers are generated using AI and, while thorough, may not always be 100% accurate. Please verify the information independently. 2. Content Ownership: All video content and lecture material referenced belong to their original creators. We encourage users to view the original material on verified platforms to ensure authenticity and accuracy. 3. Educational Fair Use: This tool is intended solely for educational purposes and operates under the principles of fair use. It is not authorized for commercial applications.]
|
8 |
|
9 |
+
:gray[For any questions, concerns, or feedback about this application, please contact the development team directly.]
|
10 |
+
"""
|
|
utils/rag_utils.py
CHANGED
@@ -1,5 +1,6 @@
|
|
1 |
import json
|
2 |
import numpy as np
|
|
|
3 |
import streamlit as st
|
4 |
|
5 |
@st.cache_resource
|
@@ -43,3 +44,8 @@ def fixed_knn_retrieval(question_embedding, context_embeddings, top_k=5, min_k=1
|
|
43 |
selected_indices = sorted_indices[:max(top_k, min_k)].tolist()
|
44 |
return selected_indices
|
45 |
|
|
|
|
|
|
|
|
|
|
|
|
1 |
import json
|
2 |
import numpy as np
|
3 |
+
import random
|
4 |
import streamlit as st
|
5 |
|
6 |
@st.cache_resource
|
|
|
44 |
selected_indices = sorted_indices[:max(top_k, min_k)].tolist()
|
45 |
return selected_indices
|
46 |
|
47 |
+
|
48 |
+
def get_random_question(text_file):
|
49 |
+
with open(text_file, "r") as file:
|
50 |
+
questions = [line.strip() for line in file]
|
51 |
+
return random.choice(questions)
|