File size: 2,043 Bytes
bdfdb09 3e1dc54 3dc1b33 bdfdb09 ccb4d06 6a6d439 bdfdb09 ccb4d06 6a6d439 07d5a3e ccb4d06 6a6d439 a61ca29 6a6d439 07d5a3e 6a6d439 bdfdb09 ccb4d06 bdfdb09 ccb4d06 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 | 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) |