File size: 2,928 Bytes
f67181d
1b04b96
1d3e5ce
1b04b96
2d5dee0
a523549
f67181d
ad53611
14c95e8
f67181d
3309fe6
 
99afa50
3309fe6
 
1d3e5ce
3309fe6
 
1d3e5ce
2d5dee0
 
 
1b04b96
2d5dee0
1b04b96
ad53611
14c95e8
00dc0db
f67181d
f78495c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
ad53611
 
a523549
f78495c
 
a523549
f78495c
f67181d
f78495c
ad53611
f78495c
b6c820d
ad53611
b6c820d
f78495c
ad53611
 
f78495c
ad53611
 
b6c820d
ad53611
3309fe6
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import streamlit as st
from generator import generate_response_from_document
from retrieval import retrieve_documents_hybrid
from evaluation import calculate_metrics
#from data_processing import load_data_from_faiss
import time

# Page Title
st.title("RAG7 - Real World RAG System")

# global retrieved_documents
# retrieved_documents = []

# global response 
# response = ""

# global time_taken_for_response
# time_taken_for_response = 'N/A'

# @st.cache_data
# def load_data():
#     load_data_from_faiss()

# data_status = load_data()

# Question Section
st.subheader("Hi, What do you want to know today?")
question = st.text_area("Enter your question:", placeholder="Type your question here...", height=100)

# # Submit Button
# if st.button("Submit"):
#     start_time = time.time()
#     retrieved_documents = retrieve_documents_hybrid(question, 10)  
#     response = generate_response_from_document(question, retrieved_documents)
#     end_time = time.time()
#     time_taken_for_response = end_time-start_time
# else:
#     response = ""

# # Response Section
# st.subheader("Response")
# st.text_area("Generated Response:", value=response, height=150, disabled=True)

# # Metrics Section
# st.subheader("Metrics")

# col1, col2 = st.columns([1, 3])  # Creating two columns for button and metrics display

# with col1:
#     if st.button("Calculate Metrics"):
#         metrics = calculate_metrics(question, response, retrieved_documents, time_taken_for_response)
#     else:
#         metrics = ""

# with col2:
#     st.text_area("Metrics:", value=metrics, height=100, disabled=True)

if "retrieved_documents" not in st.session_state:
    st.session_state.retrieved_documents = []
if "response" not in st.session_state:
    st.session_state.response = ""
if "time_taken_for_response" not in st.session_state:
    st.session_state.time_taken_for_response = "N/A"

# Submit Button
if st.button("Submit"):
    start_time = time.time()
    st.session_state.retrieved_documents = retrieve_documents_hybrid(question, 10)  
    st.session_state.response = generate_response_from_document(question, st.session_state.retrieved_documents)
    end_time = time.time()
    st.session_state.time_taken_for_response = end_time - start_time

# Display stored response
st.subheader("Response")
st.text_area("Generated Response:", value=st.session_state.response, height=150, disabled=True)

col1, col2 = st.columns([1, 3])  # Creating two columns for button and metrics display

# Calculate Metrics Button
with col1:
    if st.button("Calculate Metrics"):
        metrics = calculate_metrics(question, st.session_state.response, st.session_state.retrieved_documents, st.session_state.time_taken_for_response)
    else:
        metrics = ""

with col2:
    #st.text_area("Metrics:", value=metrics, height=100, disabled=True)
    st.json(metrics)