Download app.py from Manav0603/project2: direct link, hf CLI and curl.
- Browser
- Download file 2.04 kB
-
https://huggingface.co/spaces/Manav0603/project2/resolve/main/app.py
- Command line
-
hf download hf://spaces/Manav0603/project2/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Manav0603/project2/resolve/main/app.py
2.04 kB
| import gradio as gr | |
| from main import process_pdf, query_pdf | |
| # ---------------- Gradio UI ---------------- | |
| with gr.Blocks(css=""" | |
| body {background-color: #f5f5f5; font-family: 'Segoe UI', sans-serif;} | |
| .gr-button {background-color: #4b6cb7; color: white; border-radius: 8px;} | |
| .gr-textbox {border-radius: 6px; border: 1px solid #ccc;} | |
| """) as demo: | |
| gr.Markdown("<h1 style='text-align:center; color:#4b6cb7;'>📄 PDF QA System with Mistral-7B</h1>") | |
| gr.Markdown("<p style='text-align:center; font-size:14px;'>Upload your PDF and ask questions. Powered by Mistral-7B Instruct v0.2 via Hugging Face API.</p>") | |
| with gr.Row(): | |
| with gr.Column(scale=1): | |
| pdf_input = gr.File(label="Upload PDF", file_types=[".pdf"]) | |
| upload_btn = gr.Button("🔄 Process PDF", variant="primary") | |
| status_output = gr.Textbox(label="Status", value="Upload a PDF to initialize QA system.", interactive=False, lines=3) | |
| with gr.Column(scale=1): | |
| question_input = gr.Textbox( | |
| label="Ask a question", | |
| placeholder="What is this document about?", | |
| lines=2 | |
| ) | |
| ask_btn = gr.Button("💡 Get Answer", variant="secondary") | |
| answer_output = gr.Textbox( | |
| label="Answer", | |
| placeholder="Your answer will appear here...", | |
| interactive=False, | |
| lines=8 | |
| ) | |
| # Event handlers | |
| upload_btn.click(fn=process_pdf, inputs=pdf_input, outputs=status_output) | |
| ask_btn.click(fn=query_pdf, inputs=question_input, outputs=answer_output) | |
| # Allow Enter key to submit question | |
| question_input.submit(fn=query_pdf, inputs=question_input, outputs=answer_output) | |
| # Footer | |
| gr.Markdown("---") | |
| gr.Markdown("⚡ Powered by Mistral-7B Instruct v0.2 via Hugging Face API") | |
| # ---------------- Launch ---------------- | |
| if __name__ == "__main__": | |
| demo.launch(server_name="0.0.0.0", server_port=7860, share=True) |