Spaces:
Running on Zero
Running on Zero
Download app.py from TechKick/enterprise-ai-document-intelligence-platform: direct link, hf CLI and curl.
- Browser
- Download file 5.05 kB
-
https://huggingface.co/spaces/TechKick/enterprise-ai-document-intelligence-platform/resolve/main/app.py
- Command line
-
hf download hf://spaces/TechKick/enterprise-ai-document-intelligence-platform/app.py
-
curl -L -o app.py https://huggingface.co/spaces/TechKick/enterprise-ai-document-intelligence-platform/resolve/main/app.py
5.05 kB
| import spaces | |
| import os | |
| import gradio as gr | |
| from ui import upload_document, chat, clear_chat | |
| custom_css = """ | |
| .gradio-container { | |
| max-width: 100% !important; | |
| padding: 1.5rem 2rem !important; | |
| margin: 0 !important; | |
| } | |
| .header-box { | |
| text-align: center; | |
| padding: 1rem; | |
| margin-bottom: 1rem; | |
| width: 100%; | |
| } | |
| .header-box h1 { | |
| margin-bottom: 0.5rem; | |
| } | |
| .header-box p { | |
| margin: 0.3rem 0; | |
| } | |
| .example-btn { | |
| border-radius: 8px !important; | |
| font-size: 0.88rem !important; | |
| flex: 1 !important; | |
| } | |
| .send-btn { | |
| background: linear-gradient(135deg, #2563eb 0%, #1d4ed8 100%) !important; | |
| color: white !important; | |
| border: none !important; | |
| font-weight: 600 !important; | |
| border-radius: 8px !important; | |
| box-shadow: 0 4px 12px rgba(37, 99, 235, 0.3) !important; | |
| } | |
| .send-btn:hover { | |
| background: linear-gradient(135deg, #1d4ed8 0%, #1e40af 100%) !important; | |
| box-shadow: 0 6px 16px rgba(37, 99, 235, 0.45) !important; | |
| } | |
| """ | |
| def user_submit(user_message, history): | |
| if not user_message or not user_message.strip(): | |
| return "", history | |
| updated_history = chat(user_message, history) | |
| return "", updated_history | |
| with gr.Blocks(title="Enterprise AI Document Intelligence Platform") as demo: | |
| gr.Markdown( | |
| """ | |
| <div style="text-align: center;"> | |
| # π€ Enterprise AI Document Intelligence Platform | |
| Upload a PDF and chat with your documents using<br>AI-powered Retrieval-Augmented Generation (RAG) | |
| *Powered by*<br>**Groq β’ Sentence Transformers β’ FAISS** | |
| </div> | |
| """ | |
| ) | |
| gr.Markdown("---") | |
| with gr.Row(): | |
| # Sidebar for PDF Ingestion (responsive 1/4 screen width) | |
| with gr.Column(scale=1, min_width=320): | |
| gr.Markdown("### π Document Ingestion") | |
| upload = gr.File( | |
| label="Upload Enterprise PDF", | |
| file_types=[".pdf"], | |
| file_count="single" | |
| ) | |
| status = gr.Markdown("*No document indexed yet. Upload a PDF above.*") | |
| active_doc = gr.Markdown("βΉοΈ **Active Index:** Empty") | |
| clear_btn = gr.Button("ποΈ Clear Chat History", variant="secondary") | |
| gr.Markdown( | |
| """ | |
| --- | |
| **System Stack:** | |
| - π PyMuPDF PDF Text Extraction | |
| - π§ `all-MiniLM-L6-v2` Vector Embeddings | |
| - β‘ FAISS Vector Similarity Index | |
| - π€ Groq `llama-3.3-70b-versatile` Engine | |
| """ | |
| ) | |
| # Main Chat Panel (expanding to fill remaining full width) | |
| with gr.Column(scale=3): | |
| gr.Markdown("### π¬ Enterprise Knowledge Chat") | |
| chatbot = gr.Chatbot( | |
| height=560, | |
| placeholder="π‘ Upload a PDF document on the left, then ask questions here." | |
| ) | |
| gr.Markdown("#### π‘ Try Asking") | |
| with gr.Row(): | |
| ex1 = gr.Button("π Summarize this document", variant="secondary", size="sm", elem_classes=["example-btn"]) | |
| ex2 = gr.Button("π οΈ List technical skills", variant="secondary", size="sm", elem_classes=["example-btn"]) | |
| ex3 = gr.Button("π What projects are mentioned?", variant="secondary", size="sm", elem_classes=["example-btn"]) | |
| ex4 = gr.Button("π Give me a short overview", variant="secondary", size="sm", elem_classes=["example-btn"]) | |
| with gr.Row(): | |
| question = gr.Textbox( | |
| placeholder="Ask anything about the uploaded document...", | |
| show_label=False, | |
| scale=5, | |
| container=False | |
| ) | |
| ask = gr.Button("Send π", variant="primary", scale=1, elem_classes=["send-btn"]) | |
| # Event Connections | |
| upload.upload( | |
| upload_document, | |
| inputs=upload, | |
| outputs=[status, active_doc] | |
| ) | |
| ask.click( | |
| user_submit, | |
| inputs=[question, chatbot], | |
| outputs=[question, chatbot] | |
| ) | |
| question.submit( | |
| user_submit, | |
| inputs=[question, chatbot], | |
| outputs=[question, chatbot] | |
| ) | |
| ex1.click( | |
| lambda h: user_submit("Summarize this document", h), | |
| inputs=[chatbot], | |
| outputs=[question, chatbot] | |
| ) | |
| ex2.click( | |
| lambda h: user_submit("List technical skills", h), | |
| inputs=[chatbot], | |
| outputs=[question, chatbot] | |
| ) | |
| ex3.click( | |
| lambda h: user_submit("What projects are mentioned?", h), | |
| inputs=[chatbot], | |
| outputs=[question, chatbot] | |
| ) | |
| ex4.click( | |
| lambda h: user_submit("Give me a short overview", h), | |
| inputs=[chatbot], | |
| outputs=[question, chatbot] | |
| ) | |
| clear_btn.click( | |
| clear_chat, | |
| inputs=[], | |
| outputs=[chatbot] | |
| ) | |
| if __name__ == "__main__": | |
| demo.launch( | |
| css=custom_css, | |
| theme=gr.themes.Soft(), | |
| ssr_mode=False | |
| ) | |