Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 21 additions & 10 deletions .streamlit/config.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# ===== These configurtions are for the cloud deployment through streamlit cloud
# Optimized configuration for Streamlit Cloud performance
[server]
headless = true
port = 8501

# Disable file watching (major performance gain in cloud)
fileWatcherType = "none"

Expand All @@ -12,14 +15,11 @@ runOnSave = false
# Memory and connection optimization
maxUploadSize = 10
maxMessageSize = 200
headless = true


# WebSocket settings for better responsiveness
enableWebsocketCompression = true

# Session management
cookieSecret = "your-secret-key-here"

[browser]
# Disable telemetry and stats collection
gatherUsageStats = false
Expand All @@ -40,10 +40,21 @@ magicEnabled = false
# Memory optimization - keep this as false to avoid serialization errors
enforceSerializableSessionState = false

[ui]
# Sidebar width configuration (default is 21rem, increase for wider sidebar)
sidebarWidth = 100

# [theme]
# # Clean theme for better perceived performance
# primaryColor = "#1f77b4"
# backgroundColor = "#ffffff"
# secondaryBackgroundColor = "#f0f2f6"
# textColor = "#262730"
# font = "sans serif"

[theme]
# Clean theme for better perceived performance
primaryColor = "#1f77b4"
backgroundColor = "#ffffff"
secondaryBackgroundColor = "#f0f2f6"
textColor = "#262730"
font = "sans serif"
base="light"
backgroundColor="#F3E8FF"
primaryColor="#6C4AB6" # Optional: accent color
secondaryBackgroundColor="#F8F1FF"
textColor="#1C1C1C"
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
<img src="photo.png" alt="Screenshot of the PDF Question Answering" width="1000"/>
*Figure: Screenshot of the PDF Question Answering System Dashboard.*

## 🚀 Live Demo

**Try the application live:** [https://bbkhosseini--two-stage-conrag-run.modal.run/](https://bbkhosseini--two-stage-conrag-run.modal.run/)

*Experience the Two-Stage Consecutive RAG system in action! Upload your PDFs and ask questions directly in your browser.*


## Table of Contents
- [Introduction](#introduction)
- [System Overview](#system-overview)
Expand Down
74 changes: 74 additions & 0 deletions modal/modal_app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import shlex
import subprocess
from pathlib import Path

import modal

parent_dir = Path(__file__).parent
project_root = parent_dir.parent
streamlit_script_local_path = parent_dir / "modal_streamlit.py"
streamlit_script_remote_path = "/root/modal_streamlit.py"

image = (
modal.Image.debian_slim(python_version="3.12")
.pip_install(
"chromadb>=1.0.0",
"langchain==0.3.25",
"langchain-chroma>=0.2.4",
"langchain-community>=0.3.25",
"langchain-groq>=0.3.2",
"langchain-huggingface==0.3.0",
"langchain-openai>=0.3.22",
"numpy>=2.0.0",
"omegaconf>=2.3.0",
"pandas>=2.3.0",
"protobuf==5.29.5",
"pydantic>=2.0.0",
"pypdf>=5.6.0",
"python-dotenv>=1.0.0",
"pysqlite3-binary>=0.5.2",
"rank-bm25>=0.2.2",
"sentence-transformers>=4.1.0",
"streamlit>=1.46.0",
"scikit-learn>=1.7.0",
)
.env({
"DEPLOYMENT_MODE": "cloud",
"IN_MEMORY": "true",
"DEBUG_MODE": "false",
"PYTHONPATH": "/root"
})
.add_local_file(
streamlit_script_local_path,
streamlit_script_remote_path,
)
.add_local_dir(project_root / "frontend", "/root/frontend")
.add_local_dir(project_root / "data/sample_pdfs", "/root/data/sample_pdfs")
.add_local_dir(project_root / "backend", "/root/backend")
.add_local_dir(project_root / "configs", "/root/configs")
.add_local_dir(project_root / ".streamlit", "/root/.streamlit")
.add_local_file(project_root / "frontend/static/image.jpeg", "/root/frontend/static/image.jpeg")
)

app = modal.App(name="two-stage-conrag", image=image)

if not streamlit_script_local_path.exists():
raise RuntimeError(
"modal_streamlit.py not found! Place the script with your streamlit app in the same directory."
)

@app.function(
gpu="A10G:1",
secrets=[modal.Secret.from_name("groq-secret")]
)
@modal.concurrent(max_inputs=100)
@modal.web_server(8000)
def run():
target = shlex.quote(streamlit_script_remote_path)
cmd = f"""streamlit run {target} \
--server.port 8000 \
--server.enableCORS=false \
--server.enableXsrfProtection=false \
--server.headless=true"""
subprocess.Popen(cmd, shell=True)

Loading