deepkansara-123 commited on
Commit
e861f53
Β·
verified Β·
1 Parent(s): c89ef97

Upload 6 files

Browse files
Files changed (1) hide show
  1. app.py +30 -21
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("# πŸ“„ PDF Q&A System")
118
-
119
- with gr.Tab("1. Upload PDF"):
120
- file = gr.File(label="Upload PDF")
121
- upload_out = gr.Textbox(label="Upload Result")
 
 
 
 
 
 
 
 
122
  file.change(fn=upload_pdf, inputs=file, outputs=upload_out)
123
 
124
- with gr.Tab("2. Generate Q&A"):
125
- fname = gr.Textbox(label="Enter uploaded filename")
126
- qa_result = gr.Textbox(label="Generated Q&A", lines=10)
127
- gr.Button("Generate Q&A").click(fn=generate_qa, inputs=fname, outputs=qa_result)
128
-
129
- with gr.Tab("3. Ask a Question"):
130
- token_box = gr.Textbox(label="Enter Token ID")
131
- question_box = gr.Textbox(label="Your Question")
132
- answer_result = gr.Textbox(label="Answer Output", lines=5)
133
- gr.Button("Ask").click(fn=ask_question, inputs=[token_box, question_box], outputs=answer_result)
134
-
135
- with gr.Tab("4. View Uploaded PDFs"):
 
 
 
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)