Spaces:
Paused
Paused
change doc used for searching
Browse files
app.py
CHANGED
|
@@ -11,13 +11,13 @@ API_KEY = os.getenv("COLIVARA_API_KEY")
|
|
| 11 |
if "search_results" not in st.session_state:
|
| 12 |
st.session_state["search_results"] = []
|
| 13 |
|
| 14 |
-
client = Colivara(
|
| 15 |
# Add badges at the top of the page
|
| 16 |
st.markdown(
|
| 17 |
"""
|
| 18 |
<div style="display: flex; gap: 10px; margin-bottom: 20px;">
|
| 19 |
<a href="https://discord.gg/DtGRxWuj8y" target="_blank">
|
| 20 |
-
<img src="https://
|
| 21 |
</a>
|
| 22 |
<a href="https://www.colivara.com" target="_blank">
|
| 23 |
<img src="https://img.shields.io/badge/Website-0078D7?style=for-the-badge&logo=internetexplorer&logoColor=white" alt="Website">
|
|
@@ -40,16 +40,28 @@ st.title("Colivara Demo")
|
|
| 40 |
st.markdown(
|
| 41 |
"""
|
| 42 |
### Welcome to the Colivara Search Demo
|
| 43 |
-
This demo allows you to search through
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
- Enter a search query in the input box below.
|
| 46 |
- Retrieve the most relevant pages from the document.
|
| 47 |
|
| 48 |
**Example Queries:**
|
| 49 |
```
|
| 50 |
-
1. What
|
| 51 |
-
2.
|
| 52 |
-
3.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
```
|
| 54 |
|
| 55 |
Try it out and see how the AI retrieves the information you need efficiently.
|
|
@@ -60,16 +72,19 @@ st.markdown(
|
|
| 60 |
st.markdown(
|
| 61 |
"""
|
| 62 |
#### Document Overview:
|
| 63 |
-
**Title:**
|
|
|
|
| 64 |
**Type:** PDF
|
| 65 |
-
**Pages:**
|
| 66 |
-
|
|
|
|
|
|
|
|
|
|
| 67 |
<img src="https://img.shields.io/badge/View%20PDF-EF8D21?style=for-the-badge&logo=adobeacrobatreader&logoColor=white" alt="View PDF">
|
| 68 |
</a>
|
| 69 |
""",
|
| 70 |
unsafe_allow_html=True,
|
| 71 |
)
|
| 72 |
-
|
| 73 |
# Search and retrieve documents
|
| 74 |
st.subheader("Search and Retrieve Documents")
|
| 75 |
|
|
@@ -85,7 +100,7 @@ top_k = st.slider(
|
|
| 85 |
help="Select the number of top pages to retrieve.",
|
| 86 |
)
|
| 87 |
|
| 88 |
-
collection_name = "
|
| 89 |
if st.button("Search"):
|
| 90 |
if not query:
|
| 91 |
st.error("Please enter a search query to retrieve results.")
|
|
@@ -100,19 +115,28 @@ if st.button("Search"):
|
|
| 100 |
st.error(f"Error during search: {str(e)}")
|
| 101 |
|
| 102 |
# Display search results
|
|
|
|
| 103 |
if "search_results" in st.session_state and st.session_state["search_results"]:
|
| 104 |
st.write("### Search Results")
|
| 105 |
-
|
| 106 |
for idx, result in enumerate(st.session_state["search_results"]):
|
| 107 |
img_base64 = result.img_base64
|
| 108 |
page_number = result.page_number
|
| 109 |
document_name = result.document_name
|
| 110 |
img = Image.open(BytesIO(base64.b64decode(img_base64)))
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
st.success("Search completed successfully.")
|
| 116 |
|
| 117 |
st.markdown("----")
|
| 118 |
-
st.markdown("Developed by Abdulhaleem
|
|
|
|
| 11 |
if "search_results" not in st.session_state:
|
| 12 |
st.session_state["search_results"] = []
|
| 13 |
|
| 14 |
+
client = Colivara(api_key=API_KEY)
|
| 15 |
# Add badges at the top of the page
|
| 16 |
st.markdown(
|
| 17 |
"""
|
| 18 |
<div style="display: flex; gap: 10px; margin-bottom: 20px;">
|
| 19 |
<a href="https://discord.gg/DtGRxWuj8y" target="_blank">
|
| 20 |
+
<img src="https://img.shields.io/badge/Join%20Discord-7289DA?style=for-the-badge&logo=discord&logoColor=white" alt="Discord">
|
| 21 |
</a>
|
| 22 |
<a href="https://www.colivara.com" target="_blank">
|
| 23 |
<img src="https://img.shields.io/badge/Website-0078D7?style=for-the-badge&logo=internetexplorer&logoColor=white" alt="Website">
|
|
|
|
| 40 |
st.markdown(
|
| 41 |
"""
|
| 42 |
### Welcome to the Colivara Search Demo
|
| 43 |
+
This demo allows you to search through the Competitive Programmer's Handbook by Antti Laaksonen.
|
| 44 |
+
We included 12 chapters from the handbook in this demo to help you understand how Colivara works.
|
| 45 |
+
**Chapters Covered:**
|
| 46 |
+
`Introduction` `Time Complexity` `Sorting` `Data Structures` `Complete Search` `Greedy Algorithms` `Dynamic Programming` `Amortized Analysis` `Range Queries` `Bit Manipulation` `Basics of Graphs` `Graph Traversal`
|
| 47 |
|
| 48 |
- Enter a search query in the input box below.
|
| 49 |
- Retrieve the most relevant pages from the document.
|
| 50 |
|
| 51 |
**Example Queries:**
|
| 52 |
```
|
| 53 |
+
1. What is set theory?
|
| 54 |
+
2. How to analyze complexity using Big O notation?
|
| 55 |
+
3. Explain Binary Search Algorithm and provide implementation of lower bound.
|
| 56 |
+
4. How to use Stack, Queue and Deque?
|
| 57 |
+
5. Explain generating permutations and subsets in Complete Search.
|
| 58 |
+
6. What makes an algorithm greedy?
|
| 59 |
+
7. How to solve the coin change problem using Dynamic Programming?
|
| 60 |
+
8. What is amortized analysis?
|
| 61 |
+
9. How to implement prefix sum array?
|
| 62 |
+
10. Explain basic bitwise operations.
|
| 63 |
+
11. Show graph representation using matrix and adjacency list.
|
| 64 |
+
12. How to implement DFS and BFS traversal?
|
| 65 |
```
|
| 66 |
|
| 67 |
Try it out and see how the AI retrieves the information you need efficiently.
|
|
|
|
| 72 |
st.markdown(
|
| 73 |
"""
|
| 74 |
#### Document Overview:
|
| 75 |
+
**Title:** Competitive Programmer's Handbook
|
| 76 |
+
**Author:** Antti Laaksonen
|
| 77 |
**Type:** PDF
|
| 78 |
+
**Included Pages:** 100+
|
| 79 |
+
**Included Chapters Count:** 12
|
| 80 |
+
**Full Book Chapters Count:** 30
|
| 81 |
+
|
| 82 |
+
<a href="https://cses.fi/book/book.pdf" target="_blank">
|
| 83 |
<img src="https://img.shields.io/badge/View%20PDF-EF8D21?style=for-the-badge&logo=adobeacrobatreader&logoColor=white" alt="View PDF">
|
| 84 |
</a>
|
| 85 |
""",
|
| 86 |
unsafe_allow_html=True,
|
| 87 |
)
|
|
|
|
| 88 |
# Search and retrieve documents
|
| 89 |
st.subheader("Search and Retrieve Documents")
|
| 90 |
|
|
|
|
| 100 |
help="Select the number of top pages to retrieve.",
|
| 101 |
)
|
| 102 |
|
| 103 |
+
collection_name = "Algorithm"
|
| 104 |
if st.button("Search"):
|
| 105 |
if not query:
|
| 106 |
st.error("Please enter a search query to retrieve results.")
|
|
|
|
| 115 |
st.error(f"Error during search: {str(e)}")
|
| 116 |
|
| 117 |
# Display search results
|
| 118 |
+
|
| 119 |
if "search_results" in st.session_state and st.session_state["search_results"]:
|
| 120 |
st.write("### Search Results")
|
| 121 |
+
# Remove the columns and display images one by one
|
| 122 |
for idx, result in enumerate(st.session_state["search_results"]):
|
| 123 |
img_base64 = result.img_base64
|
| 124 |
page_number = result.page_number
|
| 125 |
document_name = result.document_name
|
| 126 |
img = Image.open(BytesIO(base64.b64decode(img_base64)))
|
| 127 |
+
|
| 128 |
+
# Create a container for each result
|
| 129 |
+
with st.container():
|
| 130 |
+
# Display the image with increased width
|
| 131 |
+
st.image(
|
| 132 |
+
img,
|
| 133 |
+
caption=f"Document: {document_name}, Page: {page_number}",
|
| 134 |
+
use_container_width=True, # This makes the image use full column width
|
| 135 |
+
)
|
| 136 |
+
# Add some spacing between images
|
| 137 |
+
st.markdown("---")
|
| 138 |
+
|
| 139 |
st.success("Search completed successfully.")
|
| 140 |
|
| 141 |
st.markdown("----")
|
| 142 |
+
st.markdown("Developed by Abdulhaleem @ TJM Labs.")
|