Spaces:
Sleeping
Sleeping
ohh
Browse files- app.py +36 -0
- templates/index.html +220 -129
app.py
CHANGED
|
@@ -65,6 +65,21 @@ def build_qa_for_pdf(path: str) -> RetrievalQA:
|
|
| 65 |
retriever = store.as_retriever(search_type="mmr", search_kwargs={"k": 5})
|
| 66 |
return RetrievalQA.from_chain_type(llm=get_llm(), retriever=retriever)
|
| 67 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 68 |
@app.route("/healthz")
|
| 69 |
def healthz():
|
| 70 |
return "ok", 200
|
|
@@ -109,6 +124,27 @@ def ask_question():
|
|
| 109 |
return jsonify({"answer": answer}), 200
|
| 110 |
except Exception as e:
|
| 111 |
return jsonify({"error": f"Error: {e}"}), 500
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 112 |
|
| 113 |
if __name__ == "__main__":
|
| 114 |
app.run(debug=True)
|
|
|
|
| 65 |
retriever = store.as_retriever(search_type="mmr", search_kwargs={"k": 5})
|
| 66 |
return RetrievalQA.from_chain_type(llm=get_llm(), retriever=retriever)
|
| 67 |
|
| 68 |
+
def summarize_pdf(path: str) -> str:
|
| 69 |
+
"""Summarize an entire PDF using the LLM."""
|
| 70 |
+
text = extract_text_from_pdf(path)
|
| 71 |
+
|
| 72 |
+
# Limit text size (avoid overloading model)
|
| 73 |
+
if len(text) > 5000:
|
| 74 |
+
text = text[:5000] # truncate long docs for quick summarization
|
| 75 |
+
|
| 76 |
+
llm = get_llm()
|
| 77 |
+
prompt = f"Summarize the following legal document in a clear and concise way:\n\n{text}"
|
| 78 |
+
result = llm.invoke(prompt)
|
| 79 |
+
|
| 80 |
+
return result.content if hasattr(result, "content") else str(result)
|
| 81 |
+
|
| 82 |
+
|
| 83 |
@app.route("/healthz")
|
| 84 |
def healthz():
|
| 85 |
return "ok", 200
|
|
|
|
| 124 |
return jsonify({"answer": answer}), 200
|
| 125 |
except Exception as e:
|
| 126 |
return jsonify({"error": f"Error: {e}"}), 500
|
| 127 |
+
|
| 128 |
+
@app.post("/summarize")
|
| 129 |
+
def summarize():
|
| 130 |
+
data = request.get_json(force=True)
|
| 131 |
+
file_id = data.get("file_id")
|
| 132 |
+
|
| 133 |
+
if not file_id:
|
| 134 |
+
return jsonify({"error": "Missing file_id."}), 400
|
| 135 |
+
|
| 136 |
+
# locate the uploaded file from /tmp/uploads
|
| 137 |
+
path = os.path.join(app.config["UPLOAD_FOLDER"], file_id)
|
| 138 |
+
if not os.path.exists(path):
|
| 139 |
+
return jsonify({"error": "File not found or expired."}), 404
|
| 140 |
+
|
| 141 |
+
try:
|
| 142 |
+
summary = summarize_pdf(path)
|
| 143 |
+
gc.collect()
|
| 144 |
+
return jsonify({"summary": summary}), 200
|
| 145 |
+
except Exception as e:
|
| 146 |
+
return jsonify({"error": f"Error summarizing: {e}"}), 500
|
| 147 |
+
|
| 148 |
|
| 149 |
if __name__ == "__main__":
|
| 150 |
app.run(debug=True)
|
templates/index.html
CHANGED
|
@@ -13,34 +13,57 @@
|
|
| 13 |
|
| 14 |
<body class="m-0 bg-white">
|
| 15 |
<div class="bg-gradient-to-b from-indigo-200 via-white to-indigo-100">
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
| 25 |
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
<a href="#tech" class="text-gray-600 hover:text-indigo-600 transition">Tech</a>
|
| 30 |
-
<a href="#connect" class="text-gray-600 hover:text-indigo-600 transition">Connect</a>
|
| 31 |
-
</nav>
|
| 32 |
-
|
| 33 |
-
<button class="sm:hidden inline-flex items-center justify-center h-8 w-8 text-gray-600 hover:text-indigo-600">
|
| 34 |
-
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 35 |
-
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
|
| 36 |
-
</svg>
|
| 37 |
-
</button>
|
| 38 |
</div>
|
| 39 |
-
|
| 40 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 41 |
|
| 42 |
|
| 43 |
-
|
| 44 |
<section>
|
| 45 |
<div class="bg-white">
|
| 46 |
<!-- <div class="relative isolate overflow-hidden bg-gradient-to-b from-gray-200/50"> -->
|
|
@@ -57,124 +80,123 @@
|
|
| 57 |
</div>
|
| 58 |
|
| 59 |
<div class="mt-20 lg:mt-0 flex justify-center items-center">
|
| 60 |
-
<img
|
| 61 |
-
src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751450446/giphy_sab0e8.webp"
|
| 62 |
class="drop-shadow-2xl" height="350" width="550" alt="chatbot image">
|
| 63 |
</div>
|
| 64 |
</div>
|
| 65 |
</div>
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
<!-- Chat Section -->
|
| 70 |
-
<section id="chat" class="py-20">
|
| 71 |
-
<div class="max-w-6xl mx-auto px-6">
|
| 72 |
-
|
| 73 |
-
<div class="text-center mb-10">
|
| 74 |
-
<h2 class="text-3xl font-bold text-gray-800">Chat With Your PDF</h2>
|
| 75 |
-
<p class="mt-2 text-gray-600 text-sm">Upload a research paper and ask any question. Powered by AI.</p>
|
| 76 |
-
</div>
|
| 77 |
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
<label for="pdfFile"
|
| 82 |
-
class="cursor-pointer bg-indigo-500 hover:bg-indigo-600 text-white px-6 py-2 rounded shadow text-sm transition">
|
| 83 |
-
Choose PDF
|
| 84 |
-
</label>
|
| 85 |
-
<span id="fileNameDisplayText" class="text-sm text-gray-600 italic">No file chosen</span>
|
| 86 |
-
<input id="pdfFile" type="file" accept=".pdf" class="hidden">
|
| 87 |
-
</div>
|
| 88 |
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
</div>
|
| 93 |
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 100 |
</button>
|
| 101 |
</div>
|
| 102 |
|
| 103 |
-
<!-- Chat
|
| 104 |
-
<div id="
|
| 105 |
-
class="
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 106 |
</div>
|
|
|
|
| 107 |
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
</button>
|
| 114 |
-
</form>
|
| 115 |
</div>
|
| 116 |
-
|
| 117 |
|
| 118 |
-
<!-- Result -->
|
| 119 |
-
{% if results %}
|
| 120 |
-
<div class="mt-6 bg-white p-6 rounded-lg shadow border border-gray-200">
|
| 121 |
-
<h2 class="text-lg font-semibold text-gray-800 mb-2">Answer:</h2>
|
| 122 |
-
<p class="text-gray-700 whitespace-pre-wrap">{{ results }}</p>
|
| 123 |
</div>
|
| 124 |
-
|
| 125 |
|
| 126 |
-
|
| 127 |
-
|
|
|
|
| 128 |
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
|
|
|
| 132 |
|
| 133 |
-
|
| 134 |
-
<h2 class="text-3xl font-bold text-gray-800">Features</h2>
|
| 135 |
-
<p class="mt-2 text-gray-600 text-sm">What makes our PDF Chatbot stand out</p>
|
| 136 |
-
</div>
|
| 137 |
|
| 138 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 139 |
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
|
|
|
| 159 |
|
| 160 |
-
<!-- AI-Powered Accuracy -->
|
| 161 |
-
<div
|
| 162 |
-
class="bg-white bg-opacity-80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 163 |
-
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751357580/feature_img_3_qeecda.jpg"
|
| 164 |
-
alt="Feature 3" class="mx-auto h-28 mb-4 object-contain" />
|
| 165 |
-
<h3 class="text-xl font-semibold text-gray-800 mb-2">AI-Powered Accuracy</h3>
|
| 166 |
-
<p class="text-sm text-gray-600">Built with powerful AI models to understand complex contexts, summaries,
|
| 167 |
-
and
|
| 168 |
-
in-depth queries.</p>
|
| 169 |
</div>
|
| 170 |
-
|
| 171 |
</div>
|
| 172 |
-
</
|
| 173 |
-
</section>
|
| 174 |
|
| 175 |
|
| 176 |
-
|
| 177 |
-
|
| 178 |
<div class="max-w-7xl mx-auto px-6">
|
| 179 |
<div class="text-center mb-12">
|
| 180 |
<h2 class="text-3xl font-bold text-gray-800">Tech Stack & AI Models</h2>
|
|
@@ -183,8 +205,8 @@
|
|
| 183 |
</p>
|
| 184 |
</div> -->
|
| 185 |
|
| 186 |
-
|
| 187 |
-
|
| 188 |
<div
|
| 189 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 190 |
<img src="https://cdn-icons-png.flaticon.com/512/5968/5968350.png" alt="Python Flask"
|
|
@@ -193,8 +215,8 @@
|
|
| 193 |
<p class="text-sm text-gray-600">Handles backend, file uploads & AI Responses.</p>
|
| 194 |
</div> -->
|
| 195 |
|
| 196 |
-
|
| 197 |
-
|
| 198 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 199 |
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751439498/download_wabh02.png" alt="LangChain"
|
| 200 |
class="mx-auto h-20 mb-4 object-contain" />
|
|
@@ -202,17 +224,17 @@
|
|
| 202 |
<p class="text-sm text-gray-600">LangChain manages PDF processing & LLM calls.</p>
|
| 203 |
</div> -->
|
| 204 |
|
| 205 |
-
|
| 206 |
-
|
| 207 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 208 |
<img src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg" alt="MiniLM Embeddings"
|
| 209 |
class="mx-auto h-20 mb-4 object-contain" />
|
| 210 |
<h3 class="text-xl font-semibold text-gray-800 mb-2">Embedding Model: all-MiniLM-L6-v2 </h3>
|
| 211 |
<p class="text-sm text-gray-600">Converts Text into Numerical Vectors.</p>
|
| 212 |
</div> -->
|
| 213 |
-
|
| 214 |
-
|
| 215 |
-
|
| 216 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 217 |
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751439632/download_so6va6.png" alt="FAISS"
|
| 218 |
class="mx-auto h-20 mb-4 object-contain" />
|
|
@@ -221,8 +243,8 @@
|
|
| 221 |
</div> -->
|
| 222 |
|
| 223 |
|
| 224 |
-
|
| 225 |
-
|
| 226 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 227 |
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751520819/download_cbh1yx.jpg" alt="Mixtral LLM"
|
| 228 |
class="mx-auto h-20 mb-4 object-contain" />
|
|
@@ -230,8 +252,8 @@
|
|
| 230 |
<p class="text-sm text-gray-600">Generates correct answers from extracted PDF chunks.</p>
|
| 231 |
</div> -->
|
| 232 |
|
| 233 |
-
|
| 234 |
-
|
| 235 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 236 |
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751439818/download_qgtwpn.png"
|
| 237 |
alt="Tailwind CSS" class="mx-auto h-20 mb-4 object-contain" />
|
|
@@ -241,7 +263,7 @@
|
|
| 241 |
</div>
|
| 242 |
</div>
|
| 243 |
</section> -->
|
| 244 |
-
|
| 245 |
</div>
|
| 246 |
|
| 247 |
<!-- ========== Connect / Footer Section ========== -->
|
|
@@ -381,6 +403,75 @@
|
|
| 381 |
btnUpload.disabled = true;
|
| 382 |
btnUpload.textContent = "Upload PDF";
|
| 383 |
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 384 |
</script>
|
| 385 |
|
| 386 |
</body>
|
|
|
|
| 13 |
|
| 14 |
<body class="m-0 bg-white">
|
| 15 |
<div class="bg-gradient-to-b from-indigo-200 via-white to-indigo-100">
|
| 16 |
+
<div class="bg-gradient-to-b from-indigo-50 via-white to-indigo-100">
|
| 17 |
+
|
| 18 |
+
<!-- Sidebar -->
|
| 19 |
+
<div id="sidebar"
|
| 20 |
+
class="fixed top-0 left-0 h-full w-64 bg-white shadow-xl border-r border-gray-200 transform -translate-x-full transition-transform duration-300 z-40">
|
| 21 |
+
<div class="p-6">
|
| 22 |
+
<h2 class="text-lg font-semibold text-gray-800 mb-4">Uploaded PDF</h2>
|
| 23 |
+
<div id="sidebarFileName" class="text-sm text-gray-600 italic mb-6">No file uploaded</div>
|
| 24 |
+
|
| 25 |
+
<button id="btnSummarize"
|
| 26 |
+
class="w-full bg-indigo-500 hover:bg-indigo-600 text-white py-2 rounded disabled:opacity-50" disabled>
|
| 27 |
+
Summarize
|
| 28 |
+
</button>
|
| 29 |
|
| 30 |
+
<div id="summaryBox"
|
| 31 |
+
class="mt-6 max-h-64 overflow-y-auto text-sm text-gray-700 p-3 border rounded bg-gray-50 hidden"></div>
|
| 32 |
+
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
</div>
|
| 34 |
+
|
| 35 |
+
<!-- Sidebar Toggle Button -->
|
| 36 |
+
<button id="sidebarToggle"
|
| 37 |
+
class="fixed top-4 left-4 z-50 bg-indigo-500 hover:bg-indigo-600 text-white p-2 rounded shadow">
|
| 38 |
+
☰
|
| 39 |
+
</button>
|
| 40 |
+
|
| 41 |
+
<!-- Header -->
|
| 42 |
+
<header class="fixed inset-x-0 top-0 z-50 bg-white/70 backdrop-blur-md shadow-sm">
|
| 43 |
+
<div class="max-w-7xl mx-auto px-6 py-3 flex items-center justify-between">
|
| 44 |
+
|
| 45 |
+
<a href="/" class="text-xl sm:text-2xl font-bold tracking-tight text-indigo-600">
|
| 46 |
+
AskBot.AI
|
| 47 |
+
</a>
|
| 48 |
+
|
| 49 |
+
<nav class="hidden sm:flex items-center space-x-6 text-sm font-medium">
|
| 50 |
+
<a href="#chat" class="text-gray-600 hover:text-indigo-600 transition">Chat</a>
|
| 51 |
+
<a href="#features" class="text-gray-600 hover:text-indigo-600 transition">Features</a>
|
| 52 |
+
<a href="#tech" class="text-gray-600 hover:text-indigo-600 transition">Tech</a>
|
| 53 |
+
<a href="#connect" class="text-gray-600 hover:text-indigo-600 transition">Connect</a>
|
| 54 |
+
</nav>
|
| 55 |
+
|
| 56 |
+
<button class="sm:hidden inline-flex items-center justify-center h-8 w-8 text-gray-600 hover:text-indigo-600">
|
| 57 |
+
<svg fill="none" viewBox="0 0 24 24" stroke="currentColor">
|
| 58 |
+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16" />
|
| 59 |
+
</svg>
|
| 60 |
+
</button>
|
| 61 |
+
</div>
|
| 62 |
+
</header>
|
| 63 |
+
<!-- /Header -->
|
| 64 |
|
| 65 |
|
| 66 |
+
<!-- <main class=""> -->
|
| 67 |
<section>
|
| 68 |
<div class="bg-white">
|
| 69 |
<!-- <div class="relative isolate overflow-hidden bg-gradient-to-b from-gray-200/50"> -->
|
|
|
|
| 80 |
</div>
|
| 81 |
|
| 82 |
<div class="mt-20 lg:mt-0 flex justify-center items-center">
|
| 83 |
+
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751450446/giphy_sab0e8.webp"
|
|
|
|
| 84 |
class="drop-shadow-2xl" height="350" width="550" alt="chatbot image">
|
| 85 |
</div>
|
| 86 |
</div>
|
| 87 |
</div>
|
| 88 |
+
</div>
|
| 89 |
+
</section>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
+
<!-- Chat Section -->
|
| 92 |
+
<section id="chat" class="py-20">
|
| 93 |
+
<div class="max-w-6xl mx-auto px-6">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 94 |
|
| 95 |
+
<div class="text-center mb-10">
|
| 96 |
+
<h2 class="text-3xl font-bold text-gray-800">Chat With Your PDF</h2>
|
| 97 |
+
<p class="mt-2 text-gray-600 text-sm">Upload a research paper and ask any question. Powered by AI.</p>
|
| 98 |
</div>
|
| 99 |
|
| 100 |
+
<div id="uploadChatCard" class="bg-white shadow-xl border border-gray-200 rounded-xl p-6 space-y-6">
|
| 101 |
+
<div id="uploader" class="space-y-4 text-center">
|
| 102 |
+
<div class="flex items-center justify-center gap-4 flex-col sm:flex-row">
|
| 103 |
+
<label for="pdfFile"
|
| 104 |
+
class="cursor-pointer bg-indigo-500 hover:bg-indigo-600 text-white px-6 py-2 rounded shadow text-sm transition">
|
| 105 |
+
Choose PDF
|
| 106 |
+
</label>
|
| 107 |
+
<span id="fileNameDisplayText" class="text-sm text-gray-600 italic">No file chosen</span>
|
| 108 |
+
<input id="pdfFile" type="file" accept=".pdf" class="hidden">
|
| 109 |
+
</div>
|
| 110 |
+
|
| 111 |
+
<button id="btnUpload" disabled class="bg-indigo-500 hover:bg-indigo-600 text-white px-6 py-2 rounded">
|
| 112 |
+
Upload PDF
|
| 113 |
</button>
|
| 114 |
</div>
|
| 115 |
|
| 116 |
+
<!-- Chat Interface -->
|
| 117 |
+
<div id="chatInterface" class="hidden space-y-4">
|
| 118 |
+
<div class="flex justify-between items-center max-w-3xl mx-auto">
|
| 119 |
+
<div id="fileNameDisplay" class="text-sm text-gray-600 font-medium italic"></div>
|
| 120 |
+
<button id="reuploadBtn" class="text-sm text-indigo-600 hover:underline">
|
| 121 |
+
Upload Another PDF
|
| 122 |
+
</button>
|
| 123 |
+
</div>
|
| 124 |
+
|
| 125 |
+
<!-- Chat Box -->
|
| 126 |
+
<div id="chatBox"
|
| 127 |
+
class="space-y-3 max-w-3xl max-h-96 overflow-y-auto px-4 py-4 border rounded-lg bg-white shadow-inner mx-auto">
|
| 128 |
+
</div>
|
| 129 |
+
|
| 130 |
+
<form id="chatForm" class="flex max-w-3xl mx-auto">
|
| 131 |
+
<input id="msgInput" autocomplete="off" placeholder="Ask a question..."
|
| 132 |
+
class="flex-1 rounded-l-lg border-gray-300 px-4 py-3 shadow" />
|
| 133 |
+
<button class="bg-indigo-500 hover:bg-indigo-600 text-white px-6 rounded-r-lg">
|
| 134 |
+
Send
|
| 135 |
+
</button>
|
| 136 |
+
</form>
|
| 137 |
</div>
|
| 138 |
+
</div>
|
| 139 |
|
| 140 |
+
<!-- Result -->
|
| 141 |
+
{% if results %}
|
| 142 |
+
<div class="mt-6 bg-white p-6 rounded-lg shadow border border-gray-200">
|
| 143 |
+
<h2 class="text-lg font-semibold text-gray-800 mb-2">Answer:</h2>
|
| 144 |
+
<p class="text-gray-700 whitespace-pre-wrap">{{ results }}</p>
|
|
|
|
|
|
|
| 145 |
</div>
|
| 146 |
+
{% endif %}
|
| 147 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 148 |
</div>
|
| 149 |
+
</section>
|
| 150 |
|
| 151 |
+
<!-- Features Section -->
|
| 152 |
+
<section id="features" class="py-20">
|
| 153 |
+
<div class="max-w-7xl mx-auto px-6">
|
| 154 |
|
| 155 |
+
<div class="text-center mb-12">
|
| 156 |
+
<h2 class="text-3xl font-bold text-gray-800">Features</h2>
|
| 157 |
+
<p class="mt-2 text-gray-600 text-sm">What makes our PDF Chatbot stand out</p>
|
| 158 |
+
</div>
|
| 159 |
|
| 160 |
+
<div class="grid grid-cols-1 md:grid-cols-3 gap-8">
|
|
|
|
|
|
|
|
|
|
| 161 |
|
| 162 |
+
<!-- Instant PDF Reading -->
|
| 163 |
+
<div
|
| 164 |
+
class="bg-white bg-opacity-80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 165 |
+
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751357240/feature_img_1_nhlopv.jpg"
|
| 166 |
+
alt="Feature 1" class="mx-auto h-28 mb-4 object-contain" />
|
| 167 |
+
<h3 class="text-xl font-semibold text-gray-800 mb-2">Instant PDF Understanding</h3>
|
| 168 |
+
<p class="text-sm text-gray-600">Ask any question and get accurate responses
|
| 169 |
+
based on the uploaded PDF content in seconds.</p>
|
| 170 |
+
</div>
|
| 171 |
|
| 172 |
+
<!-- Multiple File-Type Support -->
|
| 173 |
+
<div
|
| 174 |
+
class="bg-white bg-opacity-80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 175 |
+
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751357240/feature_img_2_b8feaa.jpg"
|
| 176 |
+
alt="Feature 2" class="mx-auto h-28 mb-4 object-contain" />
|
| 177 |
+
<h3 class="text-xl font-semibold text-gray-800 mb-2">Multiple File-Type Support</h3>
|
| 178 |
+
<p class="text-sm text-gray-600">Upload research papers, eBooks, or reports —
|
| 179 |
+
the chatbot can handle various types of academic PDFs.</p>
|
| 180 |
+
</div>
|
| 181 |
|
| 182 |
+
<!-- AI-Powered Accuracy -->
|
| 183 |
+
<div
|
| 184 |
+
class="bg-white bg-opacity-80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 185 |
+
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751357580/feature_img_3_qeecda.jpg"
|
| 186 |
+
alt="Feature 3" class="mx-auto h-28 mb-4 object-contain" />
|
| 187 |
+
<h3 class="text-xl font-semibold text-gray-800 mb-2">AI-Powered Accuracy</h3>
|
| 188 |
+
<p class="text-sm text-gray-600">Built with powerful AI models to understand complex contexts, summaries,
|
| 189 |
+
and
|
| 190 |
+
in-depth queries.</p>
|
| 191 |
+
</div>
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
</div>
|
|
|
|
| 194 |
</div>
|
| 195 |
+
</section>
|
|
|
|
| 196 |
|
| 197 |
|
| 198 |
+
<!-- ========== Tech Stack & AI Models ========== -->
|
| 199 |
+
<!-- <section id="tech" class="py-20">
|
| 200 |
<div class="max-w-7xl mx-auto px-6">
|
| 201 |
<div class="text-center mb-12">
|
| 202 |
<h2 class="text-3xl font-bold text-gray-800">Tech Stack & AI Models</h2>
|
|
|
|
| 205 |
</p>
|
| 206 |
</div> -->
|
| 207 |
|
| 208 |
+
<!-- Python and Flask -->
|
| 209 |
+
<!-- <div class="grid grid-cols-1 md:grid-cols-3 gap-8">
|
| 210 |
<div
|
| 211 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 212 |
<img src="https://cdn-icons-png.flaticon.com/512/5968/5968350.png" alt="Python Flask"
|
|
|
|
| 215 |
<p class="text-sm text-gray-600">Handles backend, file uploads & AI Responses.</p>
|
| 216 |
</div> -->
|
| 217 |
|
| 218 |
+
<!-- LangChain -->
|
| 219 |
+
<!-- <div
|
| 220 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 221 |
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751439498/download_wabh02.png" alt="LangChain"
|
| 222 |
class="mx-auto h-20 mb-4 object-contain" />
|
|
|
|
| 224 |
<p class="text-sm text-gray-600">LangChain manages PDF processing & LLM calls.</p>
|
| 225 |
</div> -->
|
| 226 |
|
| 227 |
+
<!-- Embeddings -->
|
| 228 |
+
<!-- <div
|
| 229 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 230 |
<img src="https://huggingface.co/front/assets/huggingface_logo-noborder.svg" alt="MiniLM Embeddings"
|
| 231 |
class="mx-auto h-20 mb-4 object-contain" />
|
| 232 |
<h3 class="text-xl font-semibold text-gray-800 mb-2">Embedding Model: all-MiniLM-L6-v2 </h3>
|
| 233 |
<p class="text-sm text-gray-600">Converts Text into Numerical Vectors.</p>
|
| 234 |
</div> -->
|
| 235 |
+
|
| 236 |
+
<!-- FAISS -->
|
| 237 |
+
<!-- <div
|
| 238 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 239 |
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751439632/download_so6va6.png" alt="FAISS"
|
| 240 |
class="mx-auto h-20 mb-4 object-contain" />
|
|
|
|
| 243 |
</div> -->
|
| 244 |
|
| 245 |
|
| 246 |
+
<!-- LLM -->
|
| 247 |
+
<!-- <div
|
| 248 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 249 |
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751520819/download_cbh1yx.jpg" alt="Mixtral LLM"
|
| 250 |
class="mx-auto h-20 mb-4 object-contain" />
|
|
|
|
| 252 |
<p class="text-sm text-gray-600">Generates correct answers from extracted PDF chunks.</p>
|
| 253 |
</div> -->
|
| 254 |
|
| 255 |
+
<!-- Tailwind CSS -->
|
| 256 |
+
<!-- <div
|
| 257 |
class="bg-white/80 backdrop-blur-md border border-gray-200 rounded-xl p-6 shadow-lg text-center transition hover:shadow-xl">
|
| 258 |
<img src="https://res.cloudinary.com/dekujzz4s/image/upload/v1751439818/download_qgtwpn.png"
|
| 259 |
alt="Tailwind CSS" class="mx-auto h-20 mb-4 object-contain" />
|
|
|
|
| 263 |
</div>
|
| 264 |
</div>
|
| 265 |
</section> -->
|
| 266 |
+
<!-- </main> -->
|
| 267 |
</div>
|
| 268 |
|
| 269 |
<!-- ========== Connect / Footer Section ========== -->
|
|
|
|
| 403 |
btnUpload.disabled = true;
|
| 404 |
btnUpload.textContent = "Upload PDF";
|
| 405 |
};
|
| 406 |
+
|
| 407 |
+
// Sidebar toggle
|
| 408 |
+
const sidebar = document.getElementById("sidebar");
|
| 409 |
+
const sidebarToggle = document.getElementById("sidebarToggle");
|
| 410 |
+
const sidebarFileName = document.getElementById("sidebarFileName");
|
| 411 |
+
const btnSummarize = document.getElementById("btnSummarize");
|
| 412 |
+
const summaryBox = document.getElementById("summaryBox");
|
| 413 |
+
|
| 414 |
+
sidebarToggle.onclick = () => {
|
| 415 |
+
sidebar.classList.toggle("-translate-x-full");
|
| 416 |
+
};
|
| 417 |
+
|
| 418 |
+
// Update sidebar filename when file is uploaded
|
| 419 |
+
btnUpload.onclick = async () => {
|
| 420 |
+
const file = pdfInput.files[0];
|
| 421 |
+
const formData = new FormData();
|
| 422 |
+
formData.append("file", file);
|
| 423 |
+
|
| 424 |
+
btnUpload.disabled = true;
|
| 425 |
+
btnUpload.textContent = "Uploading…";
|
| 426 |
+
|
| 427 |
+
const res = await fetch("/upload", { method: "POST", body: formData });
|
| 428 |
+
const data = await res.json();
|
| 429 |
+
|
| 430 |
+
if (res.ok) {
|
| 431 |
+
fileId = data.file_id;
|
| 432 |
+
|
| 433 |
+
document.getElementById("fileNameDisplay").textContent = `📄 ${file.name}`;
|
| 434 |
+
sidebarFileName.textContent = file.name;
|
| 435 |
+
btnSummarize.disabled = false;
|
| 436 |
+
|
| 437 |
+
document.getElementById("uploader").classList.add("hidden");
|
| 438 |
+
document.getElementById("chatInterface").classList.remove("hidden");
|
| 439 |
+
} else {
|
| 440 |
+
alert(data.error || "Upload failed");
|
| 441 |
+
btnUpload.disabled = false;
|
| 442 |
+
btnUpload.textContent = "Upload PDF";
|
| 443 |
+
}
|
| 444 |
+
};
|
| 445 |
+
|
| 446 |
+
// Summarize logic
|
| 447 |
+
btnSummarize.onclick = async () => {
|
| 448 |
+
btnSummarize.disabled = true;
|
| 449 |
+
btnSummarize.textContent = "Summarizing…";
|
| 450 |
+
|
| 451 |
+
try {
|
| 452 |
+
const res = await fetch("/summarize", {
|
| 453 |
+
method: "POST",
|
| 454 |
+
headers: { "Content-Type": "application/json" },
|
| 455 |
+
body: JSON.stringify({ file_id: fileId }),
|
| 456 |
+
});
|
| 457 |
+
const data = await res.json();
|
| 458 |
+
|
| 459 |
+
if (res.ok) {
|
| 460 |
+
summaryBox.textContent = data.summary || "No summary available.";
|
| 461 |
+
summaryBox.classList.remove("hidden");
|
| 462 |
+
} else {
|
| 463 |
+
summaryBox.textContent = data.error || "Summarization failed.";
|
| 464 |
+
summaryBox.classList.remove("hidden");
|
| 465 |
+
}
|
| 466 |
+
} catch (err) {
|
| 467 |
+
summaryBox.textContent = "Error summarizing file.";
|
| 468 |
+
summaryBox.classList.remove("hidden");
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
btnSummarize.disabled = false;
|
| 472 |
+
btnSummarize.textContent = "Summarize";
|
| 473 |
+
};
|
| 474 |
+
|
| 475 |
</script>
|
| 476 |
|
| 477 |
</body>
|