Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files- Dockerfile +10 -0
- app.py +134 -0
- frontend/App.jsx +173 -0
- frontend/index.html +19 -0
- frontend/styles.css +275 -0
- requirements.txt +10 -0
Dockerfile
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.10-slim
|
| 2 |
+
|
| 3 |
+
WORKDIR /app
|
| 4 |
+
COPY requirements.txt .
|
| 5 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 6 |
+
|
| 7 |
+
COPY . .
|
| 8 |
+
|
| 9 |
+
EXPOSE 7860
|
| 10 |
+
CMD ["python", "app.py"]
|
app.py
ADDED
|
@@ -0,0 +1,134 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
import tempfile
|
| 3 |
+
import mimetypes
|
| 4 |
+
from flask import Flask, request, jsonify
|
| 5 |
+
from dotenv import load_dotenv
|
| 6 |
+
from langchain_community.document_loaders import PyMuPDFLoader
|
| 7 |
+
from langchain_text_splitters import RecursiveCharacterTextSplitter
|
| 8 |
+
from langchain_huggingface import HuggingFaceEmbeddings
|
| 9 |
+
from langchain_groq import ChatGroq
|
| 10 |
+
from langchain_community.vectorstores import FAISS
|
| 11 |
+
from langchain_classic.chains import create_retrieval_chain
|
| 12 |
+
from langchain_classic.chains.combine_documents import create_stuff_documents_chain
|
| 13 |
+
from langchain_core.prompts import ChatPromptTemplate
|
| 14 |
+
|
| 15 |
+
# --- FORCE MIME TYPES FOR WINDOWS ---
|
| 16 |
+
mimetypes.add_type('text/css', '.css')
|
| 17 |
+
mimetypes.add_type('application/javascript', '.jsx')
|
| 18 |
+
|
| 19 |
+
# --- FLASK APP INITIALIZATION ---
|
| 20 |
+
# By setting static_folder and static_url_path, Flask natively handles serving all files in the frontend folder.
|
| 21 |
+
app = Flask(__name__, static_folder='frontend', static_url_path='/')
|
| 22 |
+
|
| 23 |
+
# --- GLOBAL STATE (For local MVP / Basic HF Space) ---
|
| 24 |
+
global_vector_store = None
|
| 25 |
+
|
| 26 |
+
# --- LLM & EMBEDDING SETUP ---
|
| 27 |
+
load_dotenv()
|
| 28 |
+
groq_api_key = os.getenv("GROQ_API_KEY")
|
| 29 |
+
|
| 30 |
+
if not groq_api_key:
|
| 31 |
+
raise ValueError("🚨 CRITICAL ERROR: Groq API Key not found. Ensure your .env contains GROQ_API_KEY=gsk_...")
|
| 32 |
+
|
| 33 |
+
embeddings = HuggingFaceEmbeddings(model_name="BAAI/bge-small-en-v1.5")
|
| 34 |
+
llm = ChatGroq(
|
| 35 |
+
temperature=0.1,
|
| 36 |
+
model_name="llama-3.3-70b-versatile",
|
| 37 |
+
groq_api_key=groq_api_key
|
| 38 |
+
)
|
| 39 |
+
|
| 40 |
+
# --- ROUTES: SERVE FRONTEND FILES ---
|
| 41 |
+
@app.route('/')
|
| 42 |
+
def serve_index():
|
| 43 |
+
# Natively serve the index.html from the defined static_folder
|
| 44 |
+
return app.send_static_file('index.html')
|
| 45 |
+
|
| 46 |
+
# --- API ROUTE 1: UPLOAD & PROCESS PDF ---
|
| 47 |
+
@app.route('/upload', methods=['POST'])
|
| 48 |
+
def upload_file():
|
| 49 |
+
global global_vector_store
|
| 50 |
+
|
| 51 |
+
if 'file' not in request.files:
|
| 52 |
+
return jsonify({"error": "No file part"}), 400
|
| 53 |
+
|
| 54 |
+
file = request.files['file']
|
| 55 |
+
if file.filename == '':
|
| 56 |
+
return jsonify({"error": "No selected file"}), 400
|
| 57 |
+
|
| 58 |
+
try:
|
| 59 |
+
with tempfile.NamedTemporaryFile(delete=False, suffix=".pdf") as tmp_file:
|
| 60 |
+
file.save(tmp_file.name)
|
| 61 |
+
tmp_file_path = tmp_file.name
|
| 62 |
+
|
| 63 |
+
loader = PyMuPDFLoader(tmp_file_path)
|
| 64 |
+
documents = loader.load()
|
| 65 |
+
|
| 66 |
+
text_splitter = RecursiveCharacterTextSplitter(
|
| 67 |
+
separators=["\n\n", "\n", " ", ""],
|
| 68 |
+
chunk_size=1000,
|
| 69 |
+
chunk_overlap=200
|
| 70 |
+
)
|
| 71 |
+
chunks = text_splitter.split_documents(documents)
|
| 72 |
+
|
| 73 |
+
global_vector_store = FAISS.from_documents(chunks, embeddings)
|
| 74 |
+
|
| 75 |
+
intro_text = " ".join([doc.page_content for doc in chunks[:4]])
|
| 76 |
+
extraction_prompt = f"""
|
| 77 |
+
Based on the following introductory text from a research paper, provide:
|
| 78 |
+
1. A 2-sentence summary of the paper.
|
| 79 |
+
2. The core problem the authors are trying to solve.
|
| 80 |
+
3. The primary methodology or model architecture proposed.
|
| 81 |
+
|
| 82 |
+
Text: {intro_text}
|
| 83 |
+
"""
|
| 84 |
+
|
| 85 |
+
response = llm.invoke([("human", extraction_prompt)])
|
| 86 |
+
os.remove(tmp_file_path)
|
| 87 |
+
|
| 88 |
+
return jsonify({"insights": response.content}), 200
|
| 89 |
+
|
| 90 |
+
except Exception as e:
|
| 91 |
+
return jsonify({"error": str(e)}), 500
|
| 92 |
+
|
| 93 |
+
# --- API ROUTE 2: CHAT WITH PDF ---
|
| 94 |
+
@app.route('/chat', methods=['POST'])
|
| 95 |
+
def chat():
|
| 96 |
+
global global_vector_store
|
| 97 |
+
|
| 98 |
+
if not global_vector_store:
|
| 99 |
+
return jsonify({"error": "Please upload a document first."}), 400
|
| 100 |
+
|
| 101 |
+
data = request.json
|
| 102 |
+
user_message = data.get('message')
|
| 103 |
+
|
| 104 |
+
if not user_message:
|
| 105 |
+
return jsonify({"error": "No message provided."}), 400
|
| 106 |
+
|
| 107 |
+
try:
|
| 108 |
+
retriever = global_vector_store.as_retriever(search_kwargs={"k": 4})
|
| 109 |
+
|
| 110 |
+
system_prompt = (
|
| 111 |
+
"You are a highly technical AI assistant helping a machine learning engineer understand a research paper. "
|
| 112 |
+
"Use the following pieces of retrieved context to answer the question. "
|
| 113 |
+
"If the answer is not in the context, state clearly that the paper does not mention it. "
|
| 114 |
+
"Keep the answer concise and highly technical.\n\n"
|
| 115 |
+
"Context: {context}"
|
| 116 |
+
)
|
| 117 |
+
|
| 118 |
+
prompt = ChatPromptTemplate.from_messages([
|
| 119 |
+
("system", system_prompt),
|
| 120 |
+
("human", "{input}"),
|
| 121 |
+
])
|
| 122 |
+
|
| 123 |
+
question_answer_chain = create_stuff_documents_chain(llm, prompt)
|
| 124 |
+
rag_chain = create_retrieval_chain(retriever, question_answer_chain)
|
| 125 |
+
|
| 126 |
+
response = rag_chain.invoke({"input": user_message})
|
| 127 |
+
|
| 128 |
+
return jsonify({"answer": response["answer"]}), 200
|
| 129 |
+
|
| 130 |
+
except Exception as e:
|
| 131 |
+
return jsonify({"error": str(e)}), 500
|
| 132 |
+
|
| 133 |
+
if __name__ == '__main__':
|
| 134 |
+
app.run(host='0.0.0.0', port=7860, debug=True)
|
frontend/App.jsx
ADDED
|
@@ -0,0 +1,173 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
const { useState, useRef, useEffect } = React;
|
| 2 |
+
|
| 3 |
+
function App() {
|
| 4 |
+
const [file, setFile] = useState(null);
|
| 5 |
+
const [insights, setInsights] = useState(null);
|
| 6 |
+
const [chatHistory, setChatHistory] = useState([]);
|
| 7 |
+
const [inputValue, setInputValue] = useState('');
|
| 8 |
+
const [isProcessing, setIsProcessing] = useState(false);
|
| 9 |
+
const [uploadSuccess, setUploadSuccess] = useState(false);
|
| 10 |
+
const chatEndRef = useRef(null);
|
| 11 |
+
const fileInputRef = useRef(null);
|
| 12 |
+
|
| 13 |
+
useEffect(() => {
|
| 14 |
+
chatEndRef.current?.scrollIntoView({ behavior: 'smooth' });
|
| 15 |
+
}, [chatHistory, insights]);
|
| 16 |
+
|
| 17 |
+
const handleFileChange = (e) => {
|
| 18 |
+
if (e.target.files && e.target.files.length > 0) {
|
| 19 |
+
setFile(e.target.files[0]);
|
| 20 |
+
setUploadSuccess(false);
|
| 21 |
+
}
|
| 22 |
+
};
|
| 23 |
+
|
| 24 |
+
const handleUpload = async () => {
|
| 25 |
+
if (!file) return;
|
| 26 |
+
setIsProcessing(true);
|
| 27 |
+
setInsights(null);
|
| 28 |
+
setChatHistory([]);
|
| 29 |
+
setUploadSuccess(false);
|
| 30 |
+
|
| 31 |
+
const formData = new FormData();
|
| 32 |
+
formData.append('file', file);
|
| 33 |
+
|
| 34 |
+
try {
|
| 35 |
+
const response = await fetch('/upload', {
|
| 36 |
+
method: 'POST',
|
| 37 |
+
body: formData,
|
| 38 |
+
});
|
| 39 |
+
const data = await response.json();
|
| 40 |
+
if (data.insights) {
|
| 41 |
+
setInsights(data.insights);
|
| 42 |
+
setUploadSuccess(true);
|
| 43 |
+
} else {
|
| 44 |
+
alert("Error: " + data.error);
|
| 45 |
+
}
|
| 46 |
+
} catch (error) {
|
| 47 |
+
console.error("Upload failed:", error);
|
| 48 |
+
} finally {
|
| 49 |
+
setIsProcessing(false);
|
| 50 |
+
}
|
| 51 |
+
};
|
| 52 |
+
|
| 53 |
+
const handleSendMessage = async (e) => {
|
| 54 |
+
if (e.key === 'Enter' && inputValue.trim() !== '') {
|
| 55 |
+
const userMessage = inputValue;
|
| 56 |
+
setInputValue('');
|
| 57 |
+
setChatHistory(prev => [...prev, { role: 'user', content: userMessage }]);
|
| 58 |
+
|
| 59 |
+
try {
|
| 60 |
+
const response = await fetch('/chat', {
|
| 61 |
+
method: 'POST',
|
| 62 |
+
headers: { 'Content-Type': 'application/json' },
|
| 63 |
+
body: JSON.stringify({ message: userMessage }),
|
| 64 |
+
});
|
| 65 |
+
const data = await response.json();
|
| 66 |
+
|
| 67 |
+
if (data.answer) {
|
| 68 |
+
setChatHistory(prev => [...prev, { role: 'assistant', content: data.answer }]);
|
| 69 |
+
} else {
|
| 70 |
+
alert("Error: " + data.error);
|
| 71 |
+
}
|
| 72 |
+
} catch (error) {
|
| 73 |
+
console.error("Chat failed:", error);
|
| 74 |
+
}
|
| 75 |
+
}
|
| 76 |
+
};
|
| 77 |
+
|
| 78 |
+
return (
|
| 79 |
+
<div className="app-container">
|
| 80 |
+
{/* SIDEBAR */}
|
| 81 |
+
<div className="sidebar">
|
| 82 |
+
<h2>Upload Paper</h2>
|
| 83 |
+
<p className="subtext">Upload a PDF research paper</p>
|
| 84 |
+
|
| 85 |
+
{/* Streamlit Custom File Uploader */}
|
| 86 |
+
<div className="upload-box" onClick={() => fileInputRef.current.click()}>
|
| 87 |
+
<span className="upload-label">Drag and drop file here</span>
|
| 88 |
+
<span className="upload-limit">Limit 200MB per file • PDF</span>
|
| 89 |
+
<button className="browse-btn">Browse files</button>
|
| 90 |
+
<input
|
| 91 |
+
type="file"
|
| 92 |
+
accept=".pdf"
|
| 93 |
+
ref={fileInputRef}
|
| 94 |
+
onChange={handleFileChange}
|
| 95 |
+
/>
|
| 96 |
+
</div>
|
| 97 |
+
|
| 98 |
+
{file && (
|
| 99 |
+
<div className="file-selected">
|
| 100 |
+
📄 {file.name.substring(0, 20)}{file.name.length > 20 ? '...' : ''}
|
| 101 |
+
<span style={{cursor: 'pointer'}} onClick={() => setFile(null)}>✖</span>
|
| 102 |
+
</div>
|
| 103 |
+
)}
|
| 104 |
+
|
| 105 |
+
<button
|
| 106 |
+
className="process-btn"
|
| 107 |
+
onClick={handleUpload}
|
| 108 |
+
disabled={!file || isProcessing}
|
| 109 |
+
>
|
| 110 |
+
{isProcessing ? "Processing..." : "Process Paper"}
|
| 111 |
+
</button>
|
| 112 |
+
|
| 113 |
+
{uploadSuccess && (
|
| 114 |
+
<div className="success-banner">Paper processed successfully!</div>
|
| 115 |
+
)}
|
| 116 |
+
</div>
|
| 117 |
+
|
| 118 |
+
{/* MAIN CONTENT */}
|
| 119 |
+
<div className="main-content">
|
| 120 |
+
<div className="header">
|
| 121 |
+
<h1>📄 Research Paper Deconstructor</h1>
|
| 122 |
+
</div>
|
| 123 |
+
|
| 124 |
+
{!insights && !isProcessing && (
|
| 125 |
+
<div className="placeholder-info">
|
| 126 |
+
👈 Please upload a PDF research paper in the sidebar to begin.
|
| 127 |
+
</div>
|
| 128 |
+
)}
|
| 129 |
+
|
| 130 |
+
{isProcessing && (
|
| 131 |
+
<div className="spinner">Ingesting and analyzing document...</div>
|
| 132 |
+
)}
|
| 133 |
+
|
| 134 |
+
{insights && (
|
| 135 |
+
<div className="insights-container">
|
| 136 |
+
<h3>🔍 Core Paper Insights</h3>
|
| 137 |
+
<div className="insights-box">
|
| 138 |
+
<pre>{insights}</pre>
|
| 139 |
+
</div>
|
| 140 |
+
</div>
|
| 141 |
+
)}
|
| 142 |
+
|
| 143 |
+
<div className="chat-container">
|
| 144 |
+
{chatHistory.map((msg, index) => (
|
| 145 |
+
<div key={index} className={`chat-message ${msg.role}`}>
|
| 146 |
+
<div className="avatar">{msg.role === 'user' ? 'U' : 'AI'}</div>
|
| 147 |
+
<div className="message-content"><pre>{msg.content}</pre></div>
|
| 148 |
+
</div>
|
| 149 |
+
))}
|
| 150 |
+
<div ref={chatEndRef} />
|
| 151 |
+
</div>
|
| 152 |
+
</div>
|
| 153 |
+
|
| 154 |
+
{/* FLOATING CHAT INPUT */}
|
| 155 |
+
{insights && (
|
| 156 |
+
<div className="input-wrapper">
|
| 157 |
+
<div className="input-container">
|
| 158 |
+
<input
|
| 159 |
+
type="text"
|
| 160 |
+
placeholder="Ask about hyperparameters, layers, loss functions..."
|
| 161 |
+
value={inputValue}
|
| 162 |
+
onChange={(e) => setInputValue(e.target.value)}
|
| 163 |
+
onKeyDown={handleSendMessage}
|
| 164 |
+
/>
|
| 165 |
+
</div>
|
| 166 |
+
</div>
|
| 167 |
+
)}
|
| 168 |
+
</div>
|
| 169 |
+
);
|
| 170 |
+
}
|
| 171 |
+
|
| 172 |
+
const root = ReactDOM.createRoot(document.getElementById('root'));
|
| 173 |
+
root.render(<App />);
|
frontend/index.html
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="en">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8">
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
| 6 |
+
<title>Research Decoder</title>
|
| 7 |
+
<link href="https://fonts.googleapis.com/css2?family=Source+Sans+Pro:wght@400;600;700&display=swap" rel="stylesheet">
|
| 8 |
+
|
| 9 |
+
<link rel="stylesheet" href="/styles.css?v=3">
|
| 10 |
+
|
| 11 |
+
<script crossorigin src="https://unpkg.com/react@18/umd/react.production.min.js"></script>
|
| 12 |
+
<script crossorigin src="https://unpkg.com/react-dom@18/umd/react-dom.production.min.js"></script>
|
| 13 |
+
<script src="https://unpkg.com/@babel/standalone/babel.min.js"></script>
|
| 14 |
+
</head>
|
| 15 |
+
<body>
|
| 16 |
+
<div id="root"></div>
|
| 17 |
+
<script type="text/babel" src="/App.jsx?v=3"></script>
|
| 18 |
+
</body>
|
| 19 |
+
</html>
|
frontend/styles.css
ADDED
|
@@ -0,0 +1,275 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
/* --- GLOBAL RESETS & TYPOGRAPHY --- */
|
| 2 |
+
* { box-sizing: border-box; margin: 0; padding: 0; }
|
| 3 |
+
|
| 4 |
+
body {
|
| 5 |
+
font-family: 'Source Sans Pro', sans-serif;
|
| 6 |
+
background-color: #0e1117;
|
| 7 |
+
color: #fafafa;
|
| 8 |
+
overflow: hidden;
|
| 9 |
+
}
|
| 10 |
+
|
| 11 |
+
.app-container { display: flex; height: 100vh; width: 100vw; }
|
| 12 |
+
|
| 13 |
+
/* --- SIDEBAR --- */
|
| 14 |
+
.sidebar {
|
| 15 |
+
width: 336px;
|
| 16 |
+
background-color: #262730;
|
| 17 |
+
padding: 3rem 1.5rem;
|
| 18 |
+
display: flex;
|
| 19 |
+
flex-direction: column;
|
| 20 |
+
gap: 1.5rem;
|
| 21 |
+
box-shadow: 2px 0 10px rgba(0,0,0,0.2);
|
| 22 |
+
z-index: 10;
|
| 23 |
+
}
|
| 24 |
+
|
| 25 |
+
.sidebar h2 { font-size: 1.5rem; font-weight: 600; }
|
| 26 |
+
.subtext { font-size: 0.9rem; color: #fafafa; opacity: 0.8; margin-top: -0.8rem; }
|
| 27 |
+
|
| 28 |
+
/* --- INTERACTIVE FILE UPLOADER --- */
|
| 29 |
+
.upload-box {
|
| 30 |
+
background-color: #0e1117;
|
| 31 |
+
border: 2px dashed rgba(250, 250, 250, 0.2);
|
| 32 |
+
border-radius: 0.75rem;
|
| 33 |
+
padding: 2.5rem 1rem;
|
| 34 |
+
display: flex;
|
| 35 |
+
flex-direction: column;
|
| 36 |
+
align-items: center;
|
| 37 |
+
justify-content: center;
|
| 38 |
+
text-align: center;
|
| 39 |
+
gap: 0.8rem;
|
| 40 |
+
cursor: pointer;
|
| 41 |
+
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
|
| 42 |
+
}
|
| 43 |
+
|
| 44 |
+
.upload-box:hover {
|
| 45 |
+
border-color: #ff4b4b;
|
| 46 |
+
background-color: rgba(255, 75, 75, 0.05);
|
| 47 |
+
transform: translateY(-2px);
|
| 48 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.15);
|
| 49 |
+
}
|
| 50 |
+
|
| 51 |
+
.upload-box input[type="file"] { display: none; }
|
| 52 |
+
.upload-label { font-size: 1rem; font-weight: 600; cursor: pointer; }
|
| 53 |
+
.upload-limit { font-size: 0.8rem; color: rgba(250, 250, 250, 0.5); }
|
| 54 |
+
|
| 55 |
+
.browse-btn {
|
| 56 |
+
background-color: #262730;
|
| 57 |
+
border: 1px solid rgba(250, 250, 250, 0.2);
|
| 58 |
+
color: #fafafa;
|
| 59 |
+
padding: 0.4rem 1rem;
|
| 60 |
+
border-radius: 0.25rem;
|
| 61 |
+
font-size: 0.9rem;
|
| 62 |
+
margin-top: 0.5rem;
|
| 63 |
+
cursor: pointer;
|
| 64 |
+
transition: background-color 0.2s, color 0.2s;
|
| 65 |
+
}
|
| 66 |
+
|
| 67 |
+
.upload-box:hover .browse-btn {
|
| 68 |
+
background-color: #ff4b4b;
|
| 69 |
+
color: white;
|
| 70 |
+
border-color: #ff4b4b;
|
| 71 |
+
}
|
| 72 |
+
|
| 73 |
+
.file-selected {
|
| 74 |
+
background-color: rgba(255, 75, 75, 0.1);
|
| 75 |
+
border: 1px solid rgba(255, 75, 75, 0.3);
|
| 76 |
+
padding: 0.75rem;
|
| 77 |
+
border-radius: 0.5rem;
|
| 78 |
+
font-size: 0.9rem;
|
| 79 |
+
display: flex;
|
| 80 |
+
justify-content: space-between;
|
| 81 |
+
align-items: center;
|
| 82 |
+
animation: slideIn 0.3s ease-out forwards;
|
| 83 |
+
}
|
| 84 |
+
|
| 85 |
+
.remove-file {
|
| 86 |
+
cursor: pointer;
|
| 87 |
+
opacity: 0.6;
|
| 88 |
+
transition: opacity 0.2s, transform 0.2s;
|
| 89 |
+
}
|
| 90 |
+
.remove-file:hover {
|
| 91 |
+
opacity: 1;
|
| 92 |
+
color: #ff4b4b;
|
| 93 |
+
transform: scale(1.2);
|
| 94 |
+
}
|
| 95 |
+
|
| 96 |
+
/* --- ANIMATED PROCESS BUTTON --- */
|
| 97 |
+
.process-btn {
|
| 98 |
+
background-color: #262730;
|
| 99 |
+
border: 1px solid rgba(250, 250, 250, 0.2);
|
| 100 |
+
color: #fafafa;
|
| 101 |
+
padding: 0.8rem 1rem;
|
| 102 |
+
border-radius: 0.5rem;
|
| 103 |
+
font-size: 1.05rem;
|
| 104 |
+
font-weight: 600;
|
| 105 |
+
cursor: pointer;
|
| 106 |
+
transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
|
| 107 |
+
}
|
| 108 |
+
|
| 109 |
+
/* The state when a file is selected but not clicked yet */
|
| 110 |
+
.process-btn.ready {
|
| 111 |
+
background: linear-gradient(135deg, #ff4b4b 0%, #ff7676 100%);
|
| 112 |
+
border: none;
|
| 113 |
+
color: white;
|
| 114 |
+
box-shadow: 0 4px 15px rgba(255, 75, 75, 0.3);
|
| 115 |
+
animation: pulseGlow 2s infinite;
|
| 116 |
+
}
|
| 117 |
+
|
| 118 |
+
.process-btn.ready:hover {
|
| 119 |
+
transform: translateY(-2px);
|
| 120 |
+
box-shadow: 0 6px 20px rgba(255, 75, 75, 0.5);
|
| 121 |
+
animation: none; /* stop pulsing when hovering to feel solid */
|
| 122 |
+
}
|
| 123 |
+
|
| 124 |
+
.process-btn.ready:active {
|
| 125 |
+
transform: translateY(1px) scale(0.98);
|
| 126 |
+
}
|
| 127 |
+
|
| 128 |
+
.process-btn:disabled {
|
| 129 |
+
opacity: 0.4;
|
| 130 |
+
cursor: not-allowed;
|
| 131 |
+
background-color: #1a1c23;
|
| 132 |
+
border-color: transparent;
|
| 133 |
+
}
|
| 134 |
+
|
| 135 |
+
.process-btn.processing {
|
| 136 |
+
background: #3b82f6;
|
| 137 |
+
border: none;
|
| 138 |
+
animation: pulseBlue 1.5s infinite;
|
| 139 |
+
}
|
| 140 |
+
|
| 141 |
+
.success-banner {
|
| 142 |
+
background-color: rgba(61, 213, 109, 0.1);
|
| 143 |
+
color: #3dd56d;
|
| 144 |
+
padding: 1rem;
|
| 145 |
+
border-radius: 0.5rem;
|
| 146 |
+
border-left: 4px solid #3dd56d;
|
| 147 |
+
font-size: 0.9rem;
|
| 148 |
+
animation: slideIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
|
| 149 |
+
}
|
| 150 |
+
|
| 151 |
+
/* --- KEYFRAMES --- */
|
| 152 |
+
@keyframes slideIn {
|
| 153 |
+
from { opacity: 0; transform: translateY(-10px); }
|
| 154 |
+
to { opacity: 1; transform: translateY(0); }
|
| 155 |
+
}
|
| 156 |
+
|
| 157 |
+
@keyframes pulseGlow {
|
| 158 |
+
0% { box-shadow: 0 0 0 0 rgba(255, 75, 75, 0.4); }
|
| 159 |
+
70% { box-shadow: 0 0 0 10px rgba(255, 75, 75, 0); }
|
| 160 |
+
100% { box-shadow: 0 0 0 0 rgba(255, 75, 75, 0); }
|
| 161 |
+
}
|
| 162 |
+
|
| 163 |
+
@keyframes pulseBlue {
|
| 164 |
+
0% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0.4); }
|
| 165 |
+
70% { box-shadow: 0 0 0 10px rgba(59, 130, 246, 0); }
|
| 166 |
+
100% { box-shadow: 0 0 0 0 rgba(59, 130, 246, 0); }
|
| 167 |
+
}
|
| 168 |
+
|
| 169 |
+
/* --- MAIN CONTENT & CHAT (Remaining layout) --- */
|
| 170 |
+
.main-content {
|
| 171 |
+
flex: 1;
|
| 172 |
+
display: flex;
|
| 173 |
+
flex-direction: column;
|
| 174 |
+
padding: 3rem 5rem 100px 5rem;
|
| 175 |
+
overflow-y: auto;
|
| 176 |
+
position: relative;
|
| 177 |
+
scroll-behavior: smooth;
|
| 178 |
+
}
|
| 179 |
+
|
| 180 |
+
.header h1 { font-size: 2.5rem; font-weight: 700; margin-bottom: 2rem; display: flex; align-items: center; gap: 10px; }
|
| 181 |
+
|
| 182 |
+
.placeholder-info {
|
| 183 |
+
background-color: #262730;
|
| 184 |
+
padding: 1.2rem 1.5rem;
|
| 185 |
+
border-radius: 0.5rem;
|
| 186 |
+
border-left: 4px solid #3b82f6;
|
| 187 |
+
font-size: 1.05rem;
|
| 188 |
+
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
| 189 |
+
}
|
| 190 |
+
|
| 191 |
+
.spinner {
|
| 192 |
+
margin-top: 2rem;
|
| 193 |
+
color: rgba(250, 250, 250, 0.8);
|
| 194 |
+
display: flex;
|
| 195 |
+
align-items: center;
|
| 196 |
+
gap: 1rem;
|
| 197 |
+
font-size: 1.1rem;
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
/* Simple CSS Loader */
|
| 201 |
+
.loader {
|
| 202 |
+
border: 3px solid rgba(255,255,255,0.1);
|
| 203 |
+
border-top: 3px solid #3b82f6;
|
| 204 |
+
border-radius: 50%;
|
| 205 |
+
width: 24px;
|
| 206 |
+
height: 24px;
|
| 207 |
+
animation: spin 1s linear infinite;
|
| 208 |
+
}
|
| 209 |
+
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }
|
| 210 |
+
|
| 211 |
+
.insights-container h3 { font-size: 1.5rem; margin-bottom: 1rem; display: flex; align-items: center; gap: 8px; }
|
| 212 |
+
|
| 213 |
+
.insights-box {
|
| 214 |
+
background-color: rgba(59, 130, 246, 0.05);
|
| 215 |
+
border: 1px solid rgba(59, 130, 246, 0.3);
|
| 216 |
+
padding: 1.5rem;
|
| 217 |
+
border-radius: 0.5rem;
|
| 218 |
+
color: #93c5fd;
|
| 219 |
+
margin-bottom: 2rem;
|
| 220 |
+
box-shadow: 0 4px 12px rgba(0,0,0,0.1);
|
| 221 |
+
}
|
| 222 |
+
|
| 223 |
+
.insights-box pre, .message-content pre {
|
| 224 |
+
white-space: pre-wrap;
|
| 225 |
+
font-family: inherit;
|
| 226 |
+
font-size: 1.05rem;
|
| 227 |
+
line-height: 1.6;
|
| 228 |
+
}
|
| 229 |
+
|
| 230 |
+
.chat-container { display: flex; flex-direction: column; gap: 1.2rem; }
|
| 231 |
+
|
| 232 |
+
.chat-message { display: flex; gap: 1rem; padding: 1.5rem; border-radius: 0.5rem; transition: background-color 0.2s; }
|
| 233 |
+
.chat-message.user { background-color: #262730; box-shadow: 0 2px 8px rgba(0,0,0,0.1); }
|
| 234 |
+
.chat-message.assistant { background-color: transparent; border-left: 2px solid transparent; }
|
| 235 |
+
.chat-message.assistant:hover { background-color: rgba(255,255,255,0.02); border-left-color: #3b82f6; }
|
| 236 |
+
|
| 237 |
+
.avatar {
|
| 238 |
+
width: 36px;
|
| 239 |
+
height: 36px;
|
| 240 |
+
border-radius: 6px;
|
| 241 |
+
background-color: #ff4b4b;
|
| 242 |
+
display: flex;
|
| 243 |
+
align-items: center;
|
| 244 |
+
justify-content: center;
|
| 245 |
+
font-weight: 700;
|
| 246 |
+
flex-shrink: 0;
|
| 247 |
+
box-shadow: 0 2px 6px rgba(0,0,0,0.2);
|
| 248 |
+
}
|
| 249 |
+
.chat-message.assistant .avatar { background-color: #3b82f6; }
|
| 250 |
+
|
| 251 |
+
.input-wrapper {
|
| 252 |
+
position: fixed;
|
| 253 |
+
bottom: 0;
|
| 254 |
+
left: 336px;
|
| 255 |
+
right: 0;
|
| 256 |
+
padding: 1.5rem 5rem;
|
| 257 |
+
background: linear-gradient(180deg, rgba(14, 17, 23, 0) 0%, rgba(14, 17, 23, 0.9) 30%, #0e1117 100%);
|
| 258 |
+
}
|
| 259 |
+
|
| 260 |
+
.input-container input {
|
| 261 |
+
width: 100%;
|
| 262 |
+
background-color: #262730;
|
| 263 |
+
border: 1px solid rgba(250, 250, 250, 0.2);
|
| 264 |
+
color: #fafafa;
|
| 265 |
+
padding: 1.2rem 1.5rem;
|
| 266 |
+
border-radius: 0.75rem;
|
| 267 |
+
font-size: 1.05rem;
|
| 268 |
+
outline: none;
|
| 269 |
+
box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
|
| 270 |
+
transition: border-color 0.3s, box-shadow 0.3s;
|
| 271 |
+
}
|
| 272 |
+
.input-container input:focus {
|
| 273 |
+
border-color: #ff4b4b;
|
| 274 |
+
box-shadow: 0 6px 20px rgba(255, 75, 75, 0.15);
|
| 275 |
+
}
|
requirements.txt
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
streamlit
|
| 2 |
+
langchain
|
| 3 |
+
langchain-community
|
| 4 |
+
langchain-huggingface
|
| 5 |
+
langchain-groq
|
| 6 |
+
pymupdf
|
| 7 |
+
faiss-cpu
|
| 8 |
+
python-dotenv
|
| 9 |
+
sentence-transformers
|
| 10 |
+
flask
|