codeboosterstech commited on
Commit
28c10e5
Β·
verified Β·
1 Parent(s): 0ded493

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +228 -0
app.py ADDED
@@ -0,0 +1,228 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Enhanced Gradio application with more dynamic question configuration
3
+ """
4
+
5
+ import gradio as gr
6
+ import os
7
+ import tempfile
8
+ from multi_agent import MultiAgentSystem
9
+ from docx_builder import generate_all_documents
10
+
11
+ # Initialize the multi-agent system
12
+ agent_system = MultiAgentSystem()
13
+
14
+ def generate_exam_package(subject, stream, part_a_count, part_b_count, part_c_count,
15
+ part_a_marks, part_b_marks, part_c_marks, syllabus_file, reference_file):
16
+ """Enhanced main function with dynamic marks configuration"""
17
+
18
+ try:
19
+ # Convert counts and marks to integers
20
+ part_a_count = int(part_a_count)
21
+ part_b_count = int(part_b_count)
22
+ part_c_count = int(part_c_count)
23
+ part_a_marks = int(part_a_marks)
24
+ part_b_marks = int(part_b_marks)
25
+ part_c_marks = int(part_c_marks)
26
+
27
+ # Generate exam package with dynamic marks
28
+ final_output, status = agent_system.generate_exam_package(
29
+ subject=subject,
30
+ stream=stream,
31
+ part_a_count=part_a_count,
32
+ part_b_count=part_b_count,
33
+ part_c_count=part_c_count,
34
+ part_a_marks=part_a_marks,
35
+ part_b_marks=part_b_marks,
36
+ part_c_marks=part_c_marks,
37
+ syllabus_file=syllabus_file,
38
+ reference_file=reference_file
39
+ )
40
+
41
+ if status != "Success":
42
+ return None, None, None, status
43
+
44
+ # Create temporary directory for outputs
45
+ with tempfile.TemporaryDirectory() as temp_dir:
46
+ # Generate DOCX files
47
+ files = generate_all_documents(final_output, subject, stream, temp_dir)
48
+
49
+ # Return file paths
50
+ return files["question_paper"], files["answer_key"], files["obe_summary"], "Generation completed successfully!"
51
+
52
+ except Exception as e:
53
+ error_msg = f"Error: {str(e)}"
54
+ print(error_msg)
55
+ return None, None, None, error_msg
56
+
57
+ def update_progress_ui():
58
+ """Update progress in UI"""
59
+ progress = agent_system.get_progress()
60
+ return f"{progress['stage'].upper()}: {progress['message']} ({progress['percentage']}%)"
61
+
62
+ def calculate_total_marks(part_a_count, part_b_count, part_c_count, part_a_marks, part_b_marks, part_c_marks):
63
+ """Calculate and display total marks in real-time"""
64
+ try:
65
+ total = (int(part_a_count) * int(part_a_marks)) + (int(part_b_count) * int(part_b_marks)) + (int(part_c_count) * int(part_c_marks))
66
+ return f"πŸ“Š Total Marks: {total}"
67
+ except:
68
+ return "πŸ“Š Total Marks: 0"
69
+
70
+ # Enhanced Gradio interface
71
+ with gr.Blocks(title="AI Exam Generator", theme=gr.themes.Soft()) as demo:
72
+ gr.Markdown("# πŸš€ AI-Powered Question Paper & Answer Generator")
73
+ gr.Markdown("Generate complete exam packages with OBE compliance using multi-agent AI system")
74
+
75
+ with gr.Row():
76
+ with gr.Column():
77
+ # Input section
78
+ subject_name = gr.Textbox(
79
+ label="Subject Name",
80
+ placeholder="e.g., Data Structures, Thermodynamics, Digital Electronics",
81
+ value="Data Structures"
82
+ )
83
+
84
+ stream = gr.Dropdown(
85
+ choices=["CSE", "Non-CSE"],
86
+ label="Stream",
87
+ value="CSE"
88
+ )
89
+
90
+ # Enhanced question configuration with marks
91
+ with gr.Group():
92
+ gr.Markdown("### Part A Configuration")
93
+ with gr.Row():
94
+ part_a_count = gr.Number(
95
+ label="Number of Questions",
96
+ value=5,
97
+ minimum=1,
98
+ maximum=50,
99
+ step=1
100
+ )
101
+ part_a_marks = gr.Number(
102
+ label="Marks per Question",
103
+ value=2,
104
+ minimum=1,
105
+ maximum=10,
106
+ step=1
107
+ )
108
+
109
+ with gr.Group():
110
+ gr.Markdown("### Part B Configuration")
111
+ with gr.Row():
112
+ part_b_count = gr.Number(
113
+ label="Number of Questions",
114
+ value=5,
115
+ minimum=1,
116
+ maximum=20,
117
+ step=1
118
+ )
119
+ part_b_marks = gr.Number(
120
+ label="Marks per Question",
121
+ value=13,
122
+ minimum=5,
123
+ maximum=20,
124
+ step=1
125
+ )
126
+
127
+ with gr.Group():
128
+ gr.Markdown("### Part C Configuration")
129
+ with gr.Row():
130
+ part_c_count = gr.Number(
131
+ label="Number of Questions",
132
+ value=1,
133
+ minimum=1,
134
+ maximum=5,
135
+ step=1
136
+ )
137
+ part_c_marks = gr.Number(
138
+ label="Marks per Question",
139
+ value=14,
140
+ minimum=10,
141
+ maximum=30,
142
+ step=1
143
+ )
144
+
145
+ # Total marks display
146
+ total_marks_display = gr.Textbox(
147
+ label="Marks Summary",
148
+ value="πŸ“Š Total Marks: 0",
149
+ interactive=False
150
+ )
151
+
152
+ syllabus_pdf = gr.File(
153
+ label="Syllabus PDF",
154
+ file_types=[".pdf"],
155
+ type="filepath"
156
+ )
157
+
158
+ reference_qp = gr.File(
159
+ label="Reference Question Paper PDF (Optional)",
160
+ file_types=[".pdf"],
161
+ type="filepath"
162
+ )
163
+
164
+ generate_btn = gr.Button("Generate Exam Package", variant="primary", size="lg")
165
+
166
+ with gr.Column():
167
+ # Output section
168
+ status_display = gr.Textbox(
169
+ label="Generation Status",
170
+ value="Ready to generate",
171
+ interactive=False
172
+ )
173
+
174
+ with gr.Row():
175
+ qp_download = gr.File(
176
+ label="Question Paper (.docx)",
177
+ file_types=[".docx"],
178
+ interactive=False
179
+ )
180
+
181
+ answers_download = gr.File(
182
+ label="Answer Key (.docx)",
183
+ file_types=[".docx"],
184
+ interactive=False
185
+ )
186
+
187
+ obe_download = gr.File(
188
+ label="OBE Summary (.docx)",
189
+ file_types=[".docx"],
190
+ interactive=False
191
+ )
192
+
193
+ # Progress section
194
+ progress_text = gr.Textbox(
195
+ label="Real-time Progress",
196
+ value="System ready",
197
+ interactive=False,
198
+ every=2
199
+ )
200
+
201
+ # Event handlers for real-time calculations
202
+ inputs_for_calculation = [part_a_count, part_b_count, part_c_count, part_a_marks, part_b_marks, part_c_marks]
203
+
204
+ for input_component in inputs_for_calculation:
205
+ input_component.change(
206
+ fn=calculate_total_marks,
207
+ inputs=inputs_for_calculation,
208
+ outputs=[total_marks_display]
209
+ )
210
+
211
+ # Main generation handler
212
+ generate_btn.click(
213
+ fn=generate_exam_package,
214
+ inputs=[subject_name, stream, part_a_count, part_b_count, part_c_count,
215
+ part_a_marks, part_b_marks, part_c_marks, syllabus_pdf, reference_qp],
216
+ outputs=[qp_download, answers_download, obe_download, status_display]
217
+ )
218
+
219
+ # Progress updates
220
+ progress_text.change(
221
+ fn=update_progress_ui,
222
+ inputs=[],
223
+ outputs=[progress_text]
224
+ )
225
+
226
+ if __name__ == "__main__":
227
+ demo.queue(concurrency_count=1)
228
+ demo.launch(server_name="0.0.0.0", server_port=7860, share=False)