Spaces:
Sleeping
Sleeping
Commit
ยท
bfbca52
1
Parent(s):
223cdd7
updateapp
Browse files- .gitignore +2 -1
- app.py +45 -9
- rag.py +4 -6
.gitignore
CHANGED
|
@@ -1 +1,2 @@
|
|
| 1 |
-
**.env
|
|
|
|
|
|
| 1 |
+
**.env
|
| 2 |
+
embeddings_db/
|
app.py
CHANGED
|
@@ -10,6 +10,17 @@ st.set_page_config(
|
|
| 10 |
st.markdown(
|
| 11 |
"""
|
| 12 |
<style>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 13 |
.main {
|
| 14 |
background-color: #f8f9fa;
|
| 15 |
}
|
|
@@ -33,13 +44,28 @@ st.markdown(
|
|
| 33 |
padding: 2px 5px;
|
| 34 |
border-radius: 3px;
|
| 35 |
font-weight: bold;
|
| 36 |
-
color: #
|
| 37 |
}
|
| 38 |
.answer-text {
|
| 39 |
color: #000000;
|
| 40 |
font-size: 16px;
|
| 41 |
line-height: 1.6;
|
| 42 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
</style>
|
| 44 |
""",
|
| 45 |
unsafe_allow_html=True,
|
|
@@ -52,8 +78,8 @@ st.title("๐บ๐ธ Cory Booker's Historic Filibuster RAG")
|
|
| 52 |
st.markdown(
|
| 53 |
"""
|
| 54 |
<div style='background-color: #ffffff; padding: 20px; border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-top: 20px;'>
|
| 55 |
-
<h3
|
| 56 |
-
<p>The transcript is derived from videos in this playlist:
|
| 57 |
<a href='https://www.youtube.com/playlist?list=PLeifkaZBt4JtdT8DZ7aftJ0lU0Q6Hfnvz' target='_blank'>YouTube Playlist</a></p>
|
| 58 |
</div>
|
| 59 |
""",
|
|
@@ -63,8 +89,8 @@ st.markdown(
|
|
| 63 |
st.markdown(
|
| 64 |
"""
|
| 65 |
<div style='background-color: #ffffff; padding: 20px; border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-top: 20px;'>
|
| 66 |
-
<h2
|
| 67 |
-
<p>Ask questions about Senator Booker's historic <span class="highlight-text">25-hour filibuster</span> speech below:</p>
|
| 68 |
</div>
|
| 69 |
""",
|
| 70 |
unsafe_allow_html=True,
|
|
@@ -82,7 +108,7 @@ if st.button("Search", key="search_button"):
|
|
| 82 |
st.markdown(
|
| 83 |
"""
|
| 84 |
<div style='background-color: #ffffff; padding: 20px; border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-top: 20px;'>
|
| 85 |
-
<h3
|
| 86 |
<p class="answer-text">{}</p>
|
| 87 |
</div>
|
| 88 |
""".format(
|
|
@@ -91,12 +117,22 @@ if st.button("Search", key="search_button"):
|
|
| 91 |
unsafe_allow_html=True,
|
| 92 |
)
|
| 93 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
# Footer
|
| 95 |
st.markdown(
|
| 96 |
"""
|
| 97 |
-
<div style='text-align: center; margin-top: 40px;
|
| 98 |
-
<p>๐บ๐ธ Celebrating American Democracy and the Power of Speech ๐บ๐ธ</p>
|
| 99 |
-
<p style='font-size:
|
| 100 |
</div>
|
| 101 |
""",
|
| 102 |
unsafe_allow_html=True,
|
|
|
|
| 10 |
st.markdown(
|
| 11 |
"""
|
| 12 |
<style>
|
| 13 |
+
/* Force light mode */
|
| 14 |
+
[data-testid="stAppViewContainer"] {
|
| 15 |
+
background-color: #f8f9fa;
|
| 16 |
+
}
|
| 17 |
+
[data-testid="stSidebar"] {
|
| 18 |
+
background-color: #f8f9fa;
|
| 19 |
+
}
|
| 20 |
+
.stApp {
|
| 21 |
+
background-color: #f8f9fa;
|
| 22 |
+
color: #000000;
|
| 23 |
+
}
|
| 24 |
.main {
|
| 25 |
background-color: #f8f9fa;
|
| 26 |
}
|
|
|
|
| 44 |
padding: 2px 5px;
|
| 45 |
border-radius: 3px;
|
| 46 |
font-weight: bold;
|
| 47 |
+
color: #000000;
|
| 48 |
}
|
| 49 |
.answer-text {
|
| 50 |
color: #000000;
|
| 51 |
font-size: 16px;
|
| 52 |
line-height: 1.6;
|
| 53 |
}
|
| 54 |
+
.section-title {
|
| 55 |
+
color: #000000;
|
| 56 |
+
font-weight: bold;
|
| 57 |
+
}
|
| 58 |
+
.section-text {
|
| 59 |
+
color: #000000;
|
| 60 |
+
}
|
| 61 |
+
/* Override any dark mode styles */
|
| 62 |
+
.stMarkdown {
|
| 63 |
+
color: #000000;
|
| 64 |
+
}
|
| 65 |
+
.stTextInput>div>div>input {
|
| 66 |
+
background-color: #ffffff;
|
| 67 |
+
color: #000000;
|
| 68 |
+
}
|
| 69 |
</style>
|
| 70 |
""",
|
| 71 |
unsafe_allow_html=True,
|
|
|
|
| 78 |
st.markdown(
|
| 79 |
"""
|
| 80 |
<div style='background-color: #ffffff; padding: 20px; border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-top: 20px;'>
|
| 81 |
+
<h3 class="section-title">Source Material</h3>
|
| 82 |
+
<p class="section-text">The transcript is derived from videos in this playlist:
|
| 83 |
<a href='https://www.youtube.com/playlist?list=PLeifkaZBt4JtdT8DZ7aftJ0lU0Q6Hfnvz' target='_blank'>YouTube Playlist</a></p>
|
| 84 |
</div>
|
| 85 |
""",
|
|
|
|
| 89 |
st.markdown(
|
| 90 |
"""
|
| 91 |
<div style='background-color: #ffffff; padding: 20px; border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-top: 20px;'>
|
| 92 |
+
<h2 class="section-title">Explore the Filibuster</h2>
|
| 93 |
+
<p class="section-text">Ask questions about Senator Booker's historic <span class="highlight-text">25-hour filibuster</span> speech below:</p>
|
| 94 |
</div>
|
| 95 |
""",
|
| 96 |
unsafe_allow_html=True,
|
|
|
|
| 108 |
st.markdown(
|
| 109 |
"""
|
| 110 |
<div style='background-color: #ffffff; padding: 20px; border-radius: 10px; box-shadow: 0 2px 4px rgba(0,0,0,0.1); margin-top: 20px;'>
|
| 111 |
+
<h3 class="section-title">Answer:</h3>
|
| 112 |
<p class="answer-text">{}</p>
|
| 113 |
</div>
|
| 114 |
""".format(
|
|
|
|
| 117 |
unsafe_allow_html=True,
|
| 118 |
)
|
| 119 |
|
| 120 |
+
# Add disclaimer about LLM hallucinations
|
| 121 |
+
st.markdown(
|
| 122 |
+
"""
|
| 123 |
+
<div style='background-color: #fff3cd; padding: 15px; border-radius: 5px; margin-top: 20px; border: 1px solid #ffeeba;'>
|
| 124 |
+
<p style='color: #856404; margin: 0;'>Please verify important facts and consult primary sources when possible.</p>
|
| 125 |
+
</div>
|
| 126 |
+
""",
|
| 127 |
+
unsafe_allow_html=True,
|
| 128 |
+
)
|
| 129 |
+
|
| 130 |
# Footer
|
| 131 |
st.markdown(
|
| 132 |
"""
|
| 133 |
+
<div style='text-align: center; margin-top: 40px;'>
|
| 134 |
+
<p class="section-text">๐บ๐ธ Celebrating American Democracy and the Power of Speech ๐บ๐ธ</p>
|
| 135 |
+
<p class="section-text" style='font-size: 14px;'>Made with โค๏ธ by <a href="https://nkasmanoff.github.io/" target="_blank">Noah K</a></p>
|
| 136 |
</div>
|
| 137 |
""",
|
| 138 |
unsafe_allow_html=True,
|
rag.py
CHANGED
|
@@ -36,14 +36,12 @@ class COT_RAG(dspy.Module):
|
|
| 36 |
self.respond = dspy.ChainOfThought("context, question -> response")
|
| 37 |
|
| 38 |
def forward(self, question):
|
| 39 |
-
question_ =
|
| 40 |
-
|
| 41 |
-
)
|
| 42 |
-
question_ += f"\n\nQuestion: {question}"
|
| 43 |
-
docs = retrieve({"question": question_})
|
| 44 |
self.docs = docs
|
| 45 |
context = [doc.page_content for doc in docs]
|
| 46 |
-
return self.respond(context=context, question=
|
| 47 |
|
| 48 |
|
| 49 |
def answer_question(question):
|
|
|
|
| 36 |
self.respond = dspy.ChainOfThought("context, question -> response")
|
| 37 |
|
| 38 |
def forward(self, question):
|
| 39 |
+
question_ = "Given the context from Cory Booker's speech, please answer the question below."
|
| 40 |
+
question_ += f"\n\nQuestion: {question}\n\nStart your answer by specifying this was from Senator Booker."
|
| 41 |
+
docs = retrieve({"question": question})
|
|
|
|
|
|
|
| 42 |
self.docs = docs
|
| 43 |
context = [doc.page_content for doc in docs]
|
| 44 |
+
return self.respond(context=context, question=question_)
|
| 45 |
|
| 46 |
|
| 47 |
def answer_question(question):
|