Spaces:
Sleeping
Sleeping
Upload 6 files
Browse files
app.py
CHANGED
|
@@ -113,31 +113,40 @@ def list_uploaded_pdfs():
|
|
| 113 |
return f"β Error: {str(e)}"
|
| 114 |
|
| 115 |
# β
Gradio UI
|
| 116 |
-
with gr.Blocks() as demo:
|
| 117 |
-
gr.Markdown(
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 122 |
file.change(fn=upload_pdf, inputs=file, outputs=upload_out)
|
| 123 |
|
| 124 |
-
with gr.Tab("2. Generate
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
gr.
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
gr.
|
| 134 |
-
|
| 135 |
-
|
|
|
|
|
|
|
|
|
|
| 136 |
list_btn = gr.Button("π Refresh List")
|
| 137 |
pdf_list_output = gr.Markdown()
|
| 138 |
list_btn.click(fn=list_uploaded_pdfs, outputs=pdf_list_output)
|
| 139 |
|
| 140 |
-
# β
Launch Gradio
|
| 141 |
-
# β
Start Gradio interface
|
| 142 |
if __name__ == "__main__":
|
| 143 |
-
demo.launch()
|
|
|
|
| 113 |
return f"β Error: {str(e)}"
|
| 114 |
|
| 115 |
# β
Gradio UI
|
| 116 |
+
with gr.Blocks(theme="default") as demo:
|
| 117 |
+
gr.Markdown(
|
| 118 |
+
"""
|
| 119 |
+
<div style='text-align: center; padding: 1rem;'>
|
| 120 |
+
<h1 style='color: #3b82f6;'>π AI-Powered PDF Q&A System</h1>
|
| 121 |
+
<p style='font-size: 1.1rem;'>Upload your PDFs, generate smart questions, and get intelligent answers.</p>
|
| 122 |
+
</div>
|
| 123 |
+
"""
|
| 124 |
+
)
|
| 125 |
+
|
| 126 |
+
with gr.Tab("π€ 1. Upload PDF"):
|
| 127 |
+
gr.Markdown("### π Upload a PDF File")
|
| 128 |
+
file = gr.File(label="Choose your PDF file", file_types=[".pdf"])
|
| 129 |
+
upload_out = gr.Textbox(label="Upload Result", interactive=False)
|
| 130 |
file.change(fn=upload_pdf, inputs=file, outputs=upload_out)
|
| 131 |
|
| 132 |
+
with gr.Tab("π§ 2. Generate Questions & Answers"):
|
| 133 |
+
gr.Markdown("### π€ Generate Q&A from your PDF")
|
| 134 |
+
fname = gr.Textbox(label="Enter uploaded filename", placeholder="example.pdf")
|
| 135 |
+
qa_result = gr.Textbox(label="Generated Q&A", lines=12, interactive=False)
|
| 136 |
+
gr.Button("π Generate Q&A").click(fn=generate_qa, inputs=fname, outputs=qa_result)
|
| 137 |
+
|
| 138 |
+
with gr.Tab("β 3. Ask a Question"):
|
| 139 |
+
gr.Markdown("### π¬ Ask a question based on uploaded PDF")
|
| 140 |
+
token_box = gr.Textbox(label="Token ID", placeholder="e.g., 123e4567-e89b-12d3-a456...")
|
| 141 |
+
question_box = gr.Textbox(label="Type your question", placeholder="What is the main topic discussed?")
|
| 142 |
+
answer_result = gr.Textbox(label="Answer Output", lines=6, interactive=False)
|
| 143 |
+
gr.Button("π― Get Answer").click(fn=ask_question, inputs=[token_box, question_box], outputs=answer_result)
|
| 144 |
+
|
| 145 |
+
with gr.Tab("π 4. View Uploaded PDFs"):
|
| 146 |
+
gr.Markdown("### π Uploaded PDF List (with Preview Snippets)")
|
| 147 |
list_btn = gr.Button("π Refresh List")
|
| 148 |
pdf_list_output = gr.Markdown()
|
| 149 |
list_btn.click(fn=list_uploaded_pdfs, outputs=pdf_list_output)
|
| 150 |
|
|
|
|
|
|
|
| 151 |
if __name__ == "__main__":
|
| 152 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|