File size: 7,803 Bytes
85502be
 
d1c8f0b
 
 
 
3963b4a
9a1cae9
d476498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d1c8f0b
85502be
3963b4a
cc6f972
d1c8f0b
85502be
d892a2a
3963b4a
d892a2a
3963b4a
823eded
3963b4a
 
 
d1c8f0b
85502be
 
 
 
 
6fc3de7
85502be
c8f66b3
 
 
 
6fc3de7
85502be
c8f66b3
 
 
 
 
 
85502be
6fc3de7
 
85502be
6fc3de7
85502be
 
6f31f30
85502be
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d476498
 
 
 
 
d1c8f0b
85502be
 
9a1cae9
d476498
 
 
 
 
 
 
fb6f36e
 
d476498
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
fb6f36e
 
 
85502be
 
fb6f36e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
85502be
 
 
 
fb6f36e
 
d476498
85502be
 
 
 
 
 
fb6f36e
d476498
fb6f36e
 
 
 
d476498
 
 
 
 
 
fb6f36e
 
 
d476498
 
 
 
 
 
 
fb6f36e
d476498
 
 
 
 
 
 
85502be
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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
# app.py

import streamlit as st
from datetime import datetime
import os
from fpdf import FPDF
import google.generativeai as genai
import re
import base64

# --- Styling Improvements ---
def set_background(image_path):
    with open(image_path, "rb") as f:
        img_data = f.read()
    b64_img = base64.b64encode(img_data).decode()
    st.markdown(
        f"""
        <style>
        .stApp {{
            background-image: url("data:image/png;base64,{b64_img}");
            background-size: cover;
            background-position: center;
        }}
        .main {{
            background-color: rgba(255, 255, 255, 0.9);
            border-radius: 10px;
            padding: 2rem;
            box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
        }}
        .stTextInput>div>div>input, .stSelectbox>div>div>select {{
            background-color: rgba(255, 255, 255, 0.8);
            border: 1px solid #1e3c72;
        }}
        .stButton>button {{
            background: linear-gradient(to right, #1e3c72, #2a5298);
            color: white;
            border: none;
            padding: 0.5rem 2rem;
            border-radius: 25px;
            font-weight: bold;
        }}
        .stDownloadButton>button {{
            background: linear-gradient(to right, #2a5298, #1e3c72);
            color: white;
        }}
        </style>
        """,
        unsafe_allow_html=True
    )

# --- API Client ---
def get_gemini_response(prompt):
    api_key = os.environ.get("groq")
    if not api_key:
        return "❌ GEMINI_API_KEY not set. Please add it in Hugging Face 'Secrets'."

    genai.configure(api_key=api_key)
    model = genai.GenerativeModel("gemini-2.0-flash")
    try:
        response = model.generate_content(prompt + " Use plain text format without markdown, avoid symbols like **, #, or any special formatting.")
        return response.text
    except Exception as e:
        return f"❌ Gemini API Error: {str(e)}"

# --- Utility Function to Clean Text ---
def sanitize_text(text):
    return re.sub(r'[^\x00-\x7F]+', ' ', text)

# --- PDF Generation ---
class PDF(FPDF):
    def header(self):
        self.set_font("Arial", "B", 12)
        self.set_text_color(40, 40, 40)
        self.cell(0, 10, '"Success is where preparation and opportunity meet." - Bobby Unser', 0, 1, 'C')
        self.ln(5)

    def footer(self):
        self.set_y(-15)
        self.set_font("Arial", "I", 8)
        self.set_text_color(100, 100, 100)
        footer_text = f"Generated on {datetime.now().strftime('%Y-%m-%d %H:%M:%S')} | Created by Mahar Affandi Noor Ghazi - Pace GK Academy | Contact: +92 311 750 5369"
        self.cell(0, 10, footer_text, 0, 0, 'C')

def create_pdf(interview_text, note_text, name):
    pdf = PDF()
    pdf.add_page()

    pdf.set_font("Times", "B", 18)
    pdf.cell(0, 10, f"Mock Interview: {name}", ln=1, align='C')
    pdf.ln(10)

    pdf.set_font("Times", "", 12)
    interview_lines = sanitize_text(interview_text).split('\n')
    for line in interview_lines:
        if line.strip():
            pdf.multi_cell(0, 8, line.strip())
    pdf.ln(10)

    pdf.set_font("Times", "B", 14)
    pdf.cell(0, 10, "Special Note", ln=1)
    pdf.set_font("Times", "", 12)
    note_lines = sanitize_text(note_text).split('\n')
    for line in note_lines:
        if line.strip():
            pdf.multi_cell(0, 8, line.strip())
    
    output_path = f"{name.replace(' ', '_')}_mock_interview.pdf"
    pdf.output(output_path)
    return output_path

# --- Streamlit App ---
st.set_page_config(
    page_title="Interview Generator",
    page_icon="πŸ“˜",
    layout="centered",
    initial_sidebar_state="collapsed"
)

# Set background
set_background("background.jpg")  # Ensure background.jpg is uploaded

st.title("πŸŽ“ Pace GK Academy - Mock Interview Generator")
st.markdown("""
    <div style="text-align: center; margin-bottom: 2rem;">
        <h3 style="color: #1e3c72; font-family: 'Helvetica', sans-serif;">Professional Exam Preparation Toolkit</h3>
        <p style="color: #2a5298;">Crafting Success Stories for PPSC, FPSC, CSS & PMS Aspirants</p>
    </div>
""", unsafe_allow_html=True)

with st.form("interview_form"):
    cols = st.columns(2)
    with cols[0]:
        name = st.text_input("Full Name ✍️")
        father_name = st.text_input("Father's Name πŸ‘¨")
        district = st.text_input("District of Domicile πŸ™οΈ")
        tehsil = st.text_input("Tehsil πŸ—ΊοΈ")
    with cols[1]:
        bachelors = st.text_input("Bachelor's Degree πŸŽ“")
        masters = st.text_input("Master's Degree πŸŽ“")
        department_post = st.text_input("Department & Post πŸ›οΈ")
        exam_type = st.selectbox("Exam Type πŸ“", ["PPSC", "FPSC", "CSS", "PMS", "Other"])
    
    hobby = st.text_input("Hobby 🎨")
    fav_personality = st.text_input("Favorite Personality 🌟")
    
    submitted = st.form_submit_button("πŸš€ Generate Interview Report")

if submitted:
    if all([name, father_name, district, tehsil, bachelors, masters, department_post, exam_type, hobby, fav_personality]):
        interview_prompt = f"""
        Generate a detailed mock interview based on the following Pakistani candidate's profile:
        - Name: {name}
        - Father's Name: {father_name}
        - District: {district}
        - Tehsil: {tehsil}
        - Bachelor's Degree: {bachelors}
        - Master's Degree: {masters}
        - Exam Type: {exam_type}
        - Department and Post: {department_post}
        - Hobby: {hobby}
        - Favorite Personality: {fav_personality}
        Include questions from:
        - Name-based personalities
        - District/Tehsil-specific geography, history, administration
        - Educational background
        - Post/Department-specific issues
        - Pakistan's geography, national & international affairs, sports
        - Government projects related to education
        - Situational judgment and problem-solving
        - Questions related to religion
        - Questions related to pre and post Pakistan history
        - Questions from geography especially countries in international affairs
        Format all in clear, numbered interview questions.
        """
  
        note_prompt = f"""
        Based on the profile of a candidate applying for the post of {department_post} through {exam_type},
        give a special note with motivational advice and suggest specific areas the candidate should study.
        Also suggest good ideas to answer a few important questions.
        Keep the tone encouraging and professional.
        """  

        with st.spinner("πŸ” Analyzing profile and crafting personalized interview..."):
            interview_text = get_gemini_response(interview_prompt)
            note_text = get_gemini_response(note_prompt)

        st.success("βœ… Interview Generated Successfully!")
        
        with st.expander("πŸ“‹ View Interview Questions", expanded=True):
            st.write(interview_text)
        
        with st.expander("πŸ“ View Special Note", expanded=False):
            st.write(note_text)

        file_path = create_pdf(interview_text, note_text, name)
        with open(file_path, "rb") as f:
            st.download_button(
                "πŸ“„ Download Comprehensive Report",
                f,
                file_name=file_path,
                mime="application/pdf",
                help="Download your personalized interview guide with professional recommendations"
            )
    else:
        st.warning("⚠️ Please complete all fields to proceed.")

st.markdown("""
    <div style="text-align: center; margin-top: 2rem; color: #1e3c72;">
        <p>πŸ“ž Contact: +92 311 750 5369 | πŸ“ Pace GK Academy</p>
        <p>πŸ’‘ Expert Guidance for Competitive Exam Success</p>
    </div>
""", unsafe_allow_html=True)