retvq commited on
Commit
9e84cc4
Β·
verified Β·
1 Parent(s): ef83f22

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +105 -82
app.py CHANGED
@@ -96,47 +96,107 @@ def generate_question_paper(pdf_file, difficulty, num_questions, progress=gr.Pro
96
  except Exception as e:
97
  raise gr.Error(f"Generation failed: {str(e)}")
98
 
99
- # --- 3. UI Layout ---
100
-
101
- # No theme argument used here to ensure compatibility
102
- with gr.Blocks(title="ExamGen AI") as demo:
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
103
 
104
- # Header Section with inline styling
105
  gr.HTML("""
106
- <div style="text-align: center; margin-bottom: 2rem;">
107
- <h1 style="font-size: 2.5rem; font-weight: 800;
108
- background: linear-gradient(45deg, #4f46e5, #9333ea);
109
- -webkit-background-clip: text; -webkit-text-fill-color: transparent;
110
- background-clip: text; margin-bottom: 0.5rem;">
111
- ExamGen AI
112
- </h1>
113
- <p style="font-size: 1.1rem; color: #64748b;">
114
- Transform study materials into professional grade exam papers in seconds.
115
- </p>
116
  </div>
117
  """)
118
 
119
  with gr.Row():
120
 
121
- # --- Left Column: Controls ---
122
- with gr.Column(scale=1, variant="panel"):
123
- gr.Markdown("### πŸ› οΈ Configuration")
124
 
125
- # File Upload
126
  pdf_input = gr.File(
127
- label="Upload Study Material",
128
  file_types=[".pdf"],
129
  file_count="single"
130
  )
131
 
132
- gr.Markdown("---")
133
 
134
- # Settings Group
135
  difficulty = gr.Radio(
136
  choices=["Easy", "Medium", "Hard"],
137
  value="Medium",
138
- label="Complexity",
139
- info="Adjusts vocabulary and concept depth"
140
  )
141
 
142
  num_questions = gr.Slider(
@@ -145,72 +205,35 @@ with gr.Blocks(title="ExamGen AI") as demo:
145
  value=10,
146
  step=1,
147
  label="Total Questions",
148
- info="Distribution: 40% MCQ, 40% Short, 20% Essay"
149
  )
150
-
151
- # Action Button
 
152
  btn_generate = gr.Button(
153
- "✨ Generate Exam Paper",
154
- variant="primary",
155
  size="lg"
156
  )
157
 
158
- # Footer/Status
159
- gr.HTML("""
160
- <div style="font-size: 0.8rem; color: #94a3b8; text-align: center; margin-top: 2rem;">
161
- Powered by <b>Llama 3.2</b> & <b>LangChain</b><br>
162
- Note: Ensure HF_TOKEN is set in secrets.
 
163
  </div>
164
- """)
165
-
166
- # --- Right Column: Preview ---
167
- with gr.Column(scale=2):
168
- gr.Markdown("### πŸ“„ Paper Preview")
169
-
170
- output = gr.Markdown(
171
- value="<div style='color: #9ca3af; font-style: italic;'>Upload a PDF and click Generate to see the result here...</div>"
172
  )
173
 
174
- # Add visual enhancements with HTML/CSS
175
- gr.HTML("""
176
- <style>
177
- /* Global container styling */
178
- .gradio-container {
179
- background: linear-gradient(to bottom right, #f8fafc, #eff6ff) !important;
180
- }
181
-
182
- /* Output paper styling */
183
- .prose {
184
- background-color: white !important;
185
- border: 1px solid #e2e8f0;
186
- border-radius: 8px;
187
- padding: 2rem !important;
188
- box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
189
- min-height: 600px;
190
- }
191
-
192
- /* Button hover effects */
193
- button.primary {
194
- background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%) !important;
195
- border: none !important;
196
- transition: all 0.3s !important;
197
- color: white !important;
198
- }
199
-
200
- button.primary:hover {
201
- transform: translateY(-2px) !important;
202
- box-shadow: 0 10px 20px rgba(79, 70, 229, 0.3) !important;
203
- }
204
-
205
- /* Card-like panels */
206
- .panel {
207
- background: white;
208
- border-radius: 8px;
209
- box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
210
- padding: 1.5rem;
211
- }
212
- </style>
213
- """)
214
 
215
  # --- Interaction Wiring ---
216
  btn_generate.click(
 
96
  except Exception as e:
97
  raise gr.Error(f"Generation failed: {str(e)}")
98
 
99
+ # --- 3. UI Layout (MVP Styling) ---
100
+
101
+ # CSS Injection for SaaS/MVP Look
102
+ css = """
103
+ @import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;800&display=swap');
104
+
105
+ .gradio-container {
106
+ font-family: 'Inter', sans-serif !important;
107
+ background-color: #f3f4f6 !important;
108
+ }
109
+
110
+ .header-container {
111
+ text-align: center;
112
+ padding: 3rem 1rem;
113
+ background: white;
114
+ border-bottom: 1px solid #e5e7eb;
115
+ margin-bottom: 2rem;
116
+ }
117
+
118
+ .logo-text {
119
+ font-size: 2rem;
120
+ font-weight: 800;
121
+ background: linear-gradient(135deg, #4f46e5 0%, #ec4899 100%);
122
+ -webkit-background-clip: text;
123
+ -webkit-text-fill-color: transparent;
124
+ }
125
+
126
+ .subtitle {
127
+ color: #6b7280;
128
+ font-size: 1.1rem;
129
+ margin-top: 0.5rem;
130
+ }
131
+
132
+ /* Custom Panel Styling */
133
+ .control-panel {
134
+ background: white !important;
135
+ border: 1px solid #e5e7eb !important;
136
+ border-radius: 12px !important;
137
+ padding: 1.5rem !important;
138
+ box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1) !important;
139
+ }
140
+
141
+ /* Paper Output Styling */
142
+ .paper-preview {
143
+ background: white !important;
144
+ border: 1px solid #e5e7eb !important;
145
+ min-height: 700px !important;
146
+ padding: 3rem !important;
147
+ border-radius: 2px !important;
148
+ box-shadow: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 10px 10px -5px rgba(0, 0, 0, 0.04) !important;
149
+ font-family: 'Times New Roman', serif !important; /* Academic look */
150
+ }
151
+
152
+ /* Primary Button Styling */
153
+ #gen-btn {
154
+ background: linear-gradient(135deg, #4f46e5 0%, #4338ca 100%) !important;
155
+ border: none !important;
156
+ color: white !important;
157
+ font-weight: 600 !important;
158
+ padding: 12px !important;
159
+ border-radius: 8px !important;
160
+ transition: transform 0.2s, box-shadow 0.2s !important;
161
+ }
162
+
163
+ #gen-btn:hover {
164
+ transform: translateY(-2px);
165
+ box-shadow: 0 10px 15px -3px rgba(79, 70, 229, 0.4) !important;
166
+ }
167
+ """
168
+
169
+ with gr.Blocks(title="ExamGen AI", css=css) as demo:
170
 
171
+ # Header
172
  gr.HTML("""
173
+ <div class="header-container">
174
+ <div class="logo-text">ExamGen AI</div>
175
+ <div class="subtitle">Enterprise-grade Question Paper Generator</div>
 
 
 
 
 
 
 
176
  </div>
177
  """)
178
 
179
  with gr.Row():
180
 
181
+ # --- Left Sidebar: Controls ---
182
+ with gr.Column(scale=1, elem_classes="control-panel"):
183
+ gr.Markdown("### βš™οΈ Configuration")
184
 
185
+ gr.Markdown("**1. Upload Material**")
186
  pdf_input = gr.File(
187
+ label="",
188
  file_types=[".pdf"],
189
  file_count="single"
190
  )
191
 
192
+ gr.HTML("<hr style='margin: 1.5rem 0; border-color: #f3f4f6;'>")
193
 
194
+ gr.Markdown("**2. Exam Settings**")
195
  difficulty = gr.Radio(
196
  choices=["Easy", "Medium", "Hard"],
197
  value="Medium",
198
+ label="Difficulty Level",
199
+ info="Determines concept depth"
200
  )
201
 
202
  num_questions = gr.Slider(
 
205
  value=10,
206
  step=1,
207
  label="Total Questions",
208
+ info="Mix of MCQ, Short & Long answers"
209
  )
210
+
211
+ gr.HTML("<div style='margin-top: 1.5rem;'></div>")
212
+
213
  btn_generate = gr.Button(
214
+ "✨ Generate Question Paper",
215
+ elem_id="gen-btn",
216
  size="lg"
217
  )
218
 
219
+ gr.Markdown(
220
+ """
221
+ <div style="margin-top: 2rem; padding: 1rem; background: #f9fafb; border-radius: 6px; font-size: 0.8rem; color: #6b7280;">
222
+ <strong>System Status:</strong><br>
223
+ 🟒 Model: Llama-3.2-3B<br>
224
+ 🟒 RAG Engine: Active
225
  </div>
226
+ """
 
 
 
 
 
 
 
227
  )
228
 
229
+ # --- Right Content: Paper Preview ---
230
+ with gr.Column(scale=2):
231
+ with gr.Group():
232
+ gr.Markdown("### πŸ“„ Examination Paper Preview")
233
+ output = gr.Markdown(
234
+ value="<div style='text-align: center; color: #9ca3af; margin-top: 5rem;'><i>Generated paper will appear here formatted as a document.</i></div>",
235
+ elem_classes="paper-preview"
236
+ )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
237
 
238
  # --- Interaction Wiring ---
239
  btn_generate.click(