TKM03's picture
Update app.py
3c45742 verified
raw
history blame
4.58 kB
import numpy as np
from sentence_transformers import SentenceTransformer
import faiss
import re
import gradio as gr
# [Previous functions remain exactly the same - preprocess_text, query_qa_system, initialize_qa_system, etc.]
# Custom CSS for professional styling
custom_css = """
.gradio-container {
max-width: 1200px !important;
margin: auto !important;
padding: 20px !important;
background-color: #f8f9fa !important;
}
.main-header {
text-align: center;
margin-bottom: 2rem;
padding: 2rem;
background: linear-gradient(135deg, #1a365d 0%, #2c5282 100%);
color: white;
border-radius: 10px;
box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}
.main-header h1 {
font-size: 2.5rem;
margin-bottom: 1rem;
font-weight: 600;
}
.main-header p {
font-size: 1.1rem;
opacity: 0.9;
}
.upload-section {
background: white;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
margin-bottom: 2rem;
}
.qa-section {
background: white;
padding: 2rem;
border-radius: 10px;
box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}
.status-box {
margin-top: 1rem;
padding: 1rem;
border-radius: 8px;
background: #f0f9ff;
border: 1px solid #bae6fd;
}
.custom-button {
background: #2563eb !important;
color: white !important;
border-radius: 8px !important;
padding: 0.75rem 1.5rem !important;
font-weight: 500 !important;
}
.custom-button:hover {
background: #1d4ed8 !important;
}
.answer-box {
background: #f8fafc !important;
border: 1px solid #e2e8f0 !important;
border-radius: 8px !important;
font-family: 'Source Code Pro', monospace !important;
}
.section-title {
color: #1e293b;
font-size: 1.25rem;
font-weight: 600;
margin-bottom: 1rem;
}
/* Responsive design */
@media (max-width: 768px) {
.gradio-container {
padding: 10px !important;
}
.main-header {
padding: 1.5rem;
}
.main-header h1 {
font-size: 2rem;
}
}
"""
# Create the enhanced Gradio interface
with gr.Blocks(title="Interview Q&A Assistant", css=custom_css) as demo:
# Header Section
with gr.Row(elem_classes=["main-header"]):
with gr.Column():
gr.Markdown("# Interview Q&A Assistant")
gr.Markdown("Your AI-powered interview preparation companion. Upload your interview questions PDF and get instant, relevant answers to your queries.")
# Upload Section
with gr.Row():
with gr.Column(elem_classes=["upload-section"]):
gr.Markdown("### πŸ“ Document Upload", elem_classes=["section-title"])
with gr.Row():
pdf_upload = gr.File(
label="Upload your interview questions PDF",
file_types=[".pdf"],
elem_classes=["file-upload"]
)
with gr.Row():
upload_button = gr.Button("Initialize Q&A System", elem_classes=["custom-button"])
with gr.Row():
status_text = gr.Textbox(
label="System Status",
value="Upload a PDF to begin",
elem_classes=["status-box"]
)
# Q&A Section
with gr.Row():
with gr.Column(elem_classes=["qa-section"]):
gr.Markdown("### πŸ’‘ Ask Questions", elem_classes=["section-title"])
with gr.Row():
question_input = gr.Textbox(
label="What would you like to know about the interview?",
placeholder="e.g., What are the common behavioral questions?",
lines=2
)
with gr.Row():
submit_button = gr.Button("Get Answer", elem_classes=["custom-button"])
with gr.Row():
answer_output = gr.Textbox(
label="Answer",
lines=10,
elem_classes=["answer-box"]
)
# Information Section
with gr.Row():
gr.Markdown("""
<div style="text-align: center; padding: 2rem; color: #64748b; font-size: 0.9rem;">
Made with ❀️ for interview preparation success
</div>
""")
# Set up events (keeping the same functionality)
upload_button.click(upload_file, inputs=pdf_upload, outputs=status_text)
submit_button.click(answer_question, inputs=question_input, outputs=answer_output)
# Launch the app
if __name__ == "__main__":
demo.launch(share=True)