Spaces:
Sleeping
Sleeping
File size: 4,580 Bytes
94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 94fd8fc 3c45742 |
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 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
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) |