Spaces:
Sleeping
Sleeping
|
Download FIXED.md from Pavankumardns/chatdocs: direct link, hf CLI and curl.
- Browser
- Download file 3.05 kB
-
https://huggingface.co/spaces/Pavankumardns/chatdocs/resolve/main/FIXED.md
- Command line
-
hf download hf://spaces/Pavankumardns/chatdocs/FIXED.md
-
curl -L -o FIXED.md https://huggingface.co/spaces/Pavankumardns/chatdocs/resolve/main/FIXED.md
3.05 kB
β FIXED - React Frontend Now Calls Real Backend APIs
What Was Wrong
The React components had hardcoded mock responses:
Upload.tsx (Line 44-48)
// BEFORE - Mock delay
setTimeout(() => {
navigate("/chat");
}, 1500);
Chat.tsx (Line 52-68)
// BEFORE - Random mock responses
setTimeout(() => {
const responses = ["Based on the document...", "Great question..."];
const assistantMessage = {
content: responses[Math.floor(Math.random() * responses.length)]
};
setMessages(prev => [...prev, assistantMessage]);
}, 1500);
What I Fixed
Upload.tsx
// AFTER - Real API call
const handleContinue = async () => {
const formData = new FormData();
formData.append('file', file);
const response = await fetch('/api/upload', {
method: 'POST',
body: formData
});
const data = await response.json();
if (response.ok) {
navigate("/chat");
} else {
alert(`Upload failed: ${data.error}`);
}
};
Chat.tsx
// AFTER - Real API call
const handleSend = async () => {
const response = await fetch('/api/chat', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ query })
});
const data = await response.json();
const assistantMessage = {
content: data.response // Real LLM response!
};
setMessages(prev => [...prev, assistantMessage]);
};
Files Changed
- β
src/pages/Upload.tsx- Real upload API call - β
src/pages/Chat.tsx- Real chat API call - β
Rebuilt React app (
npm run build) - β Removed api-fix.js hack (no longer needed)
How to Test
- Refresh browser (Ctrl+Shift+R to clear cache)
- Go to: http://localhost:5000
- Click "Get Started" - should work now
- Upload a PDF - will call real backend
- Watch terminal - you'll see upload logs
- Ask questions - will get real LLM responses
What You'll See
In Browser:
- Upload shows "Processing..." while uploading
- Chat shows real AI responses from your document
In Terminal:
================================================================================
π€ UPLOAD REQUEST RECEIVED
================================================================================
πΎ Saving file: document.pdf
Size: 4280.00 KB
π Processing document.pdf...
β Extracted 7890 words
β Created 150 chunks
π§ Creating AI embeddings for 150 chunks...
β³ Embeddings: 20/150 chunks (60%)
...
β
Upload completed in 38.5 seconds
================================================================================
Architecture
Frontend (React) β Backend (Flask) β Pinecone (Vector DB) β Groq (LLM)
- Upload: React β
/api/uploadβ Extract PDF β Create embeddings β Store in Pinecone - Chat: React β
/api/chatβ Query Pinecone β Get context β Call Groq LLM β Return response
Done!
No more hacks, no more mock responses. Clean, proper integration. π