DavidFernandes commited on
Commit
2318150
·
verified ·
1 Parent(s): c32f684

Update pages/3_✍️_Writing_Assistant.py

Browse files
Files changed (1) hide show
  1. pages/3_✍️_Writing_Assistant.py +207 -374
pages/3_✍️_Writing_Assistant.py CHANGED
@@ -1,375 +1,208 @@
1
- import streamlit as st
2
- from theme import apply_dark_theme, show_page_header, show_footer
3
- from utils import initialize_session_state, generate_document, save_to_history
4
- from datetime import datetime
5
-
6
- # Page config
7
- st.set_page_config(
8
- page_title="Writing Assistant | CiviDoc AI",
9
- page_icon="✍️",
10
- layout="centered",
11
- initial_sidebar_state="collapsed",
12
- )
13
-
14
- # Apply dark theme
15
- st.markdown(apply_dark_theme(), unsafe_allow_html=True)
16
-
17
- def writing_assistant_page():
18
- # Initialize states
19
- initialize_session_state()
20
-
21
- # Header
22
- st.markdown(show_page_header(
23
- "✍️ Writing Assistant",
24
- "Create professional government documents effortlessly"
25
- ), unsafe_allow_html=True)
26
-
27
- # Document Type Selection
28
- st.markdown(
29
- "<div class='card'>"
30
- "<h3>Select Document Type</h3>"
31
- "<p>Choose the type of document you need to create</p>"
32
- "</div>",
33
- unsafe_allow_html=True
34
- )
35
-
36
- doc_types = {
37
- "RTI": "📝 RTI Application",
38
- "COMPLAINT": "📢 Complaint Letter",
39
- "LEGAL": "⚖️ Legal Notice",
40
- "APPEAL": "📨 Appeal Letter",
41
- "PERMISSION": "🔑 Permission Request",
42
- "APPLICATION": "📋 Government Application",
43
- "CUSTOM": "✒️ Custom Document"
44
- }
45
-
46
- # Mobile-friendly document type selector with icons
47
- selected_type = st.selectbox(
48
- "Document Type",
49
- options=list(doc_types.keys()),
50
- format_func=lambda x: doc_types[x],
51
- key="doc_type_selector"
52
- )
53
-
54
- # Common Fields Section - Always visible
55
- st.markdown(
56
- "<div class='card'>"
57
- "<h4>Personal Information</h4>",
58
- unsafe_allow_html=True
59
- )
60
-
61
- name = st.text_input("Full Name", placeholder="Enter your full name")
62
- address = st.text_area("Address", placeholder="Enter your complete address")
63
- contact = st.text_input("Contact Number", placeholder="Enter your contact number")
64
- email = st.text_input("Email Address", placeholder="Enter your email address")
65
-
66
- st.markdown("</div>", unsafe_allow_html=True)
67
-
68
- # Dynamic Form Based on Selection
69
- if selected_type == "RTI":
70
- show_rti_form(name, address, contact, email)
71
- elif selected_type == "COMPLAINT":
72
- show_complaint_form(name, address, contact, email)
73
- elif selected_type == "LEGAL":
74
- show_legal_notice_form(name, address, contact, email)
75
- elif selected_type == "APPEAL":
76
- show_appeal_form(name, address, contact, email)
77
- elif selected_type == "PERMISSION":
78
- show_permission_form(name, address, contact, email)
79
- elif selected_type == "APPLICATION":
80
- show_application_form(name, address, contact, email)
81
- else: # CUSTOM
82
- show_custom_form(name, address, contact, email)
83
-
84
- def show_rti_form(name, address, contact, email):
85
- """RTI Application Form"""
86
- st.markdown(
87
- "<div class='card'>"
88
- "<h4>RTI Application Details</h4>",
89
- unsafe_allow_html=True
90
- )
91
-
92
- department = st.text_input("Department/Authority Name", placeholder="Enter department name")
93
- subject = st.text_input("Subject of Information", placeholder="Enter subject")
94
-
95
- st.markdown("<div class='touch-spacing'>", unsafe_allow_html=True)
96
- information = st.text_area(
97
- "Information Required",
98
- placeholder="Clearly specify the information you are seeking...",
99
- height=150
100
- )
101
-
102
- time_period = st.text_input(
103
- "Time Period",
104
- placeholder="Specify the time period for which information is sought"
105
- )
106
-
107
- st.markdown("</div></div>", unsafe_allow_html=True)
108
-
109
- if validate_and_generate("RTI Application", locals()):
110
- st.balloons()
111
-
112
- def show_complaint_form(name, address, contact, email):
113
- """Complaint Letter Form"""
114
- st.markdown(
115
- "<div class='card'>"
116
- "<h4>Complaint Details</h4>",
117
- unsafe_allow_html=True
118
- )
119
-
120
- authority = st.text_input("Authority/Department Name", placeholder="Enter authority name")
121
-
122
- complaint_types = [
123
- "Public Service",
124
- "Infrastructure",
125
- "Government Employee",
126
- "Civic Issue",
127
- "Other"
128
- ]
129
-
130
- complaint_type = st.selectbox("Type of Complaint", complaint_types)
131
-
132
- st.markdown("<div class='touch-spacing'>", unsafe_allow_html=True)
133
- description = st.text_area(
134
- "Complaint Description",
135
- placeholder="Describe your complaint in detail...",
136
- height=150
137
- )
138
-
139
- previous_complaints = st.text_area(
140
- "Previous Complaints (if any)",
141
- placeholder="Mention any previous complaints filed regarding this issue..."
142
- )
143
-
144
- st.markdown("</div></div>", unsafe_allow_html=True)
145
-
146
- if validate_and_generate("Complaint Letter", locals()):
147
- st.balloons()
148
-
149
- def show_legal_notice_form(name, address, contact, email):
150
- """Legal Notice Form"""
151
- st.markdown(
152
- "<div class='card'>"
153
- "<h4>Legal Notice Details</h4>",
154
- unsafe_allow_html=True
155
- )
156
-
157
- recipient = st.text_input("Notice To (Name/Department)", placeholder="Enter recipient's name")
158
- recipient_address = st.text_area("Recipient's Address", placeholder="Enter recipient's address")
159
-
160
- st.markdown("<div class='touch-spacing'>", unsafe_allow_html=True)
161
- subject = st.text_input("Subject of Notice", placeholder="Enter notice subject")
162
- cause = st.text_area(
163
- "Cause of Action",
164
- placeholder="Describe the reason for this legal notice...",
165
- height=100
166
- )
167
-
168
- relief_sought = st.text_area(
169
- "Relief Sought",
170
- placeholder="Specify what action you want taken...",
171
- height=100
172
- )
173
-
174
- time_period = st.number_input(
175
- "Response Time Period (in days)",
176
- min_value=1,
177
- value=15
178
- )
179
-
180
- st.markdown("</div></div>", unsafe_allow_html=True)
181
-
182
- if validate_and_generate("Legal Notice", locals()):
183
- st.balloons()
184
-
185
- def show_appeal_form(name, address, contact, email):
186
- """Appeal Letter Form"""
187
- st.markdown(
188
- "<div class='card'>"
189
- "<h4>Appeal Details</h4>",
190
- unsafe_allow_html=True
191
- )
192
-
193
- authority = st.text_input("Appellate Authority", placeholder="Enter authority name")
194
- reference = st.text_input("Previous Reference/Order Number", placeholder="Enter reference number")
195
-
196
- st.markdown("<div class='touch-spacing'>", unsafe_allow_html=True)
197
- order_date = st.date_input("Date of Previous Order")
198
-
199
- grounds = st.text_area(
200
- "Grounds for Appeal",
201
- placeholder="Explain the reasons for your appeal...",
202
- height=150
203
- )
204
-
205
- relief = st.text_area(
206
- "Relief Sought",
207
- placeholder="Specify what you are seeking through this appeal...",
208
- height=100
209
- )
210
-
211
- st.markdown("</div></div>", unsafe_allow_html=True)
212
-
213
- if validate_and_generate("Appeal Letter", locals()):
214
- st.balloons()
215
-
216
- def show_permission_form(name, address, contact, email):
217
- """Permission Request Form"""
218
- st.markdown(
219
- "<div class='card'>"
220
- "<h4>Permission Request Details</h4>",
221
- unsafe_allow_html=True
222
- )
223
-
224
- authority = st.text_input("Authority Name", placeholder="Enter authority name")
225
- purpose = st.text_input("Purpose of Request", placeholder="Enter the purpose")
226
-
227
- st.markdown("<div class='touch-spacing'>", unsafe_allow_html=True)
228
- details = st.text_area(
229
- "Request Details",
230
- placeholder="Provide detailed information about your request...",
231
- height=150
232
- )
233
-
234
- duration = st.text_input("Duration (if applicable)", placeholder="Specify time period")
235
- location = st.text_input("Location (if applicable)", placeholder="Specify location")
236
-
237
- undertaking = st.text_area(
238
- "Undertaking/Declaration",
239
- placeholder="Any declarations or undertakings...",
240
- height=100
241
- )
242
-
243
- st.markdown("</div></div>", unsafe_allow_html=True)
244
-
245
- if validate_and_generate("Permission Request", locals()):
246
- st.balloons()
247
-
248
- def show_application_form(name, address, contact, email):
249
- """Government Application Form"""
250
- st.markdown(
251
- "<div class='card'>"
252
- "<h4>Application Details</h4>",
253
- unsafe_allow_html=True
254
- )
255
-
256
- department = st.text_input("Department Name", placeholder="Enter department name")
257
- purpose = st.text_input("Purpose of Application", placeholder="Enter purpose")
258
-
259
- application_types = [
260
- "License",
261
- "Certificate",
262
- "Registration",
263
- "Permit",
264
- "Other"
265
- ]
266
-
267
- app_type = st.selectbox("Application Type", application_types)
268
-
269
- st.markdown("<div class='touch-spacing'>", unsafe_allow_html=True)
270
- details = st.text_area(
271
- "Application Details",
272
- placeholder="Provide detailed information...",
273
- height=150
274
- )
275
-
276
- supporting_docs = st.text_area(
277
- "Supporting Documents",
278
- placeholder="List all supporting documents...",
279
- height=100
280
- )
281
-
282
- st.markdown("</div></div>", unsafe_allow_html=True)
283
-
284
- if validate_and_generate("Government Application", locals()):
285
- st.balloons()
286
-
287
- def show_custom_form(name, address, contact, email):
288
- """Custom Document Form"""
289
- st.markdown(
290
- "<div class='card'>"
291
- "<h4>Custom Document Details</h4>",
292
- unsafe_allow_html=True
293
- )
294
-
295
- title = st.text_input("Document Title", placeholder="Enter document title")
296
- recipient = st.text_input("Recipient/Authority", placeholder="Enter recipient name")
297
-
298
- st.markdown("<div class='touch-spacing'>", unsafe_allow_html=True)
299
- subject = st.text_input("Subject", placeholder="Enter subject")
300
-
301
- content = st.text_area(
302
- "Document Content",
303
- placeholder="Enter the main content of your document...",
304
- height=300
305
- )
306
-
307
- st.markdown("</div></div>", unsafe_allow_html=True)
308
-
309
- if validate_and_generate("Custom Document", locals()):
310
- st.balloons()
311
-
312
- def validate_and_generate(doc_type, fields):
313
- """Validate fields and generate document"""
314
- if st.button(f"Generate {doc_type}", use_container_width=True):
315
- # Basic validation
316
- required_fields = {k: v for k, v in fields.items()
317
- if k not in ['st', 'contact', 'email']}
318
-
319
- empty_fields = [k for k, v in required_fields.items()
320
- if not v or (isinstance(v, str) and not v.strip())]
321
-
322
- if empty_fields:
323
- st.error(
324
- f"Please fill in all required fields: "
325
- f"{', '.join(empty_fields)}"
326
- )
327
- return False
328
-
329
- try:
330
- with st.spinner("Generating document..."):
331
- # Generate document
332
- generated_content = generate_document(doc_type, fields)
333
-
334
- # Save to history
335
- timestamp = datetime.now()
336
- doc_name = f"{doc_type}_{timestamp.strftime('%Y%m%d_%H%M%S')}"
337
- save_to_history(doc_name, doc_type, generated_content, timestamp)
338
-
339
- # Show success message
340
- st.success("Document generated successfully!")
341
-
342
- # Display generated document
343
- st.markdown(
344
- "<div class='card'>"
345
- "<h4>Generated Document</h4>"
346
- f"<pre style='white-space: pre-wrap;'>{generated_content}</pre>"
347
- "</div>",
348
- unsafe_allow_html=True
349
- )
350
-
351
- # Action buttons
352
- col1, col2 = st.columns(2)
353
- with col1:
354
- st.download_button(
355
- "📥 Download Document",
356
- generated_content,
357
- file_name=f"{doc_name}.txt",
358
- mime="text/plain",
359
- use_container_width=True
360
- )
361
-
362
- with col2:
363
- if st.button("📋 Create Another", use_container_width=True):
364
- st.rerun()
365
-
366
- return True
367
-
368
- except Exception as e:
369
- st.error(f"Error generating document: {str(e)}")
370
- return False
371
-
372
- return False
373
-
374
- if __name__ == "__main__":
375
  writing_assistant_page()
 
1
+ import streamlit as st
2
+ from theme import apply_dark_theme, show_page_header, show_footer
3
+ from utils import initialize_session_state, generate_document, save_to_history
4
+ from datetime import datetime
5
+
6
+ # Page config
7
+ st.set_page_config(
8
+ page_title="Writing Assistant | CiviDoc AI",
9
+ page_icon="✍️",
10
+ layout="centered",
11
+ initial_sidebar_state="collapsed",
12
+ )
13
+
14
+ # Apply dark theme
15
+ st.markdown(apply_dark_theme(), unsafe_allow_html=True)
16
+
17
+ def writing_assistant_page():
18
+ # Initialize states
19
+ initialize_session_state()
20
+
21
+ # Header
22
+ st.markdown(show_page_header(
23
+ "✍️ Writing Assistant",
24
+ "Create professional government documents effortlessly"
25
+ ), unsafe_allow_html=True)
26
+
27
+ # Document Type Selection
28
+ st.markdown(
29
+ "<div class='card'>"
30
+ "<h3>Select Document Type</h3>"
31
+ "<p>Choose the type of document you need to create</p>"
32
+ "</div>",
33
+ unsafe_allow_html=True
34
+ )
35
+
36
+ doc_categories = {
37
+ "Personal Identification and Certificates": ["Aadhar Card", "Birth Certificate", "Death Certificate", "Marriage Certificate", "Name Change Certificate", "Domicile Certificate"],
38
+ "Financial and Tax-Related Applications": ["PAN Card", "Tax Identification Number (TIN)", "Income Certificate", "Property Tax Payment"],
39
+ "Licenses and Permits": ["Driver's License", "Passport Application", "Firearm License", "Fishing or Hunting Permit", "Building Permit", "Business License"],
40
+ "Educational and Employment Applications": ["Scholarship Applications", "Student Loan Application", "Government Job Application", "No Objection Certificate (NOC)", "Employee Provident Fund (EPF) Withdrawal"],
41
+ "Healthcare-Related Applications": ["Health Insurance Application", "Disability Certificate", "Medical Leave Certificate"],
42
+ "Social Welfare and Subsidy Applications": ["Pension Application", "Unemployment Benefits", "Ration Card", "Senior Citizen Card", "Housing Assistance or Loan Application"],
43
+ "Environmental and Utility Permissions": ["Electricity and Water Connection", "Gas Connection", "Sanitation Permit", "Pollution Clearance Certificate"],
44
+ "Legal and Civic Documents": ["Right to Information (RTI)", "Public Grievance Application", "Affidavit for Name Change or Correction", "Legal Aid Application"]
45
+ }
46
+
47
+ selected_category = st.selectbox(
48
+ "Document Category",
49
+ options=list(doc_categories.keys())
50
+ )
51
+
52
+ selected_type = st.selectbox(
53
+ "Document Type",
54
+ options=doc_categories[selected_category]
55
+ )
56
+
57
+ # Common Fields Section - Always visible
58
+ st.markdown(
59
+ "<div class='card'>"
60
+ "<h4>Personal Information</h4>",
61
+ unsafe_allow_html=True
62
+ )
63
+
64
+ name = st.text_input("Full Name", placeholder="Enter your full name")
65
+ address = st.text_area("Address", placeholder="Enter your complete address")
66
+ contact = st.text_input("Contact Number", placeholder="Enter your contact number")
67
+ email = st.text_input("Email Address", placeholder="Enter your email address")
68
+
69
+ st.markdown("</div>", unsafe_allow_html=True)
70
+
71
+ # Dynamic Form Based on Selection
72
+ if selected_type == "Aadhar Card":
73
+ show_aadhar_card_form(name, address, contact, email)
74
+ elif selected_type == "Birth Certificate":
75
+ show_birth_certificate_form(name, address, contact, email)
76
+ elif selected_type == "Death Certificate":
77
+ show_death_certificate_form(name, address, contact, email)
78
+ elif selected_type == "Marriage Certificate":
79
+ show_marriage_certificate_form(name, address, contact, email)
80
+ # Add all additional forms following the same pattern for new documents...
81
+
82
+ def show_aadhar_card_form(name, address, contact, email):
83
+ """Aadhar Card Application Form"""
84
+ st.markdown(
85
+ "<div class='card'>"
86
+ "<h4>Aadhar Card Details</h4>",
87
+ unsafe_allow_html=True
88
+ )
89
+
90
+ uidai_center = st.text_input("UIDAI Center", placeholder="Enter UIDAI center")
91
+ date_of_birth = st.date_input("Date of Birth")
92
+ gender = st.selectbox("Gender", ["Male", "Female", "Other"])
93
+
94
+ if validate_and_generate("Aadhar Card Application", locals()):
95
+ st.balloons()
96
+
97
+ def show_birth_certificate_form(name, address, contact, email):
98
+ """Birth Certificate Application Form"""
99
+ st.markdown(
100
+ "<div class='card'>"
101
+ "<h4>Birth Certificate Details</h4>",
102
+ unsafe_allow_html=True
103
+ )
104
+
105
+ birth_date = st.date_input("Date of Birth")
106
+ place_of_birth = st.text_input("Place of Birth", placeholder="Enter place of birth")
107
+ parent_name = st.text_input("Parent's Name", placeholder="Enter parent's name")
108
+
109
+ if validate_and_generate("Birth Certificate Application", locals()):
110
+ st.balloons()
111
+
112
+ def show_death_certificate_form(name, address, contact, email):
113
+ """Death Certificate Application Form"""
114
+ st.markdown(
115
+ "<div class='card'>"
116
+ "<h4>Death Certificate Details</h4>",
117
+ unsafe_allow_html=True
118
+ )
119
+
120
+ date_of_death = st.date_input("Date of Death")
121
+ place_of_death = st.text_input("Place of Death", placeholder="Enter place of death")
122
+ relation = st.text_input("Relation to Deceased", placeholder="Enter relation")
123
+
124
+ if validate_and_generate("Death Certificate Application", locals()):
125
+ st.balloons()
126
+
127
+ def show_marriage_certificate_form(name, address, contact, email):
128
+ """Marriage Certificate Application Form"""
129
+ st.markdown(
130
+ "<div class='card'>"
131
+ "<h4>Marriage Certificate Details</h4>",
132
+ unsafe_allow_html=True
133
+ )
134
+
135
+ spouse_name = st.text_input("Spouse Name", placeholder="Enter spouse's name")
136
+ marriage_date = st.date_input("Date of Marriage")
137
+ place_of_marriage = st.text_input("Place of Marriage", placeholder="Enter place")
138
+
139
+ if validate_and_generate("Marriage Certificate Application", locals()):
140
+ st.balloons()
141
+
142
+ # Add the other document forms here in the same way:
143
+ # E.g. `show_pan_card_form`, `show_driver_license_form`, etc.
144
+
145
+ def validate_and_generate(doc_type, fields):
146
+ """Validate fields and generate document"""
147
+ if st.button(f"Generate {doc_type}", use_container_width=True):
148
+ # Basic validation
149
+ required_fields = {k: v for k, v in fields.items()
150
+ if k not in ['st', 'contact', 'email']}
151
+
152
+ empty_fields = [k for k, v in required_fields.items()
153
+ if not v or (isinstance(v, str) and not v.strip())]
154
+
155
+ if empty_fields:
156
+ st.error(
157
+ f"Please fill in all required fields: "
158
+ f"{', '.join(empty_fields)}"
159
+ )
160
+ return False
161
+
162
+ try:
163
+ with st.spinner("Generating document..."):
164
+ # Generate document
165
+ generated_content = generate_document(doc_type, fields)
166
+
167
+ # Save to history
168
+ timestamp = datetime.now()
169
+ doc_name = f"{doc_type}_{timestamp.strftime('%Y%m%d_%H%M%S')}"
170
+ save_to_history(doc_name, doc_type, generated_content, timestamp)
171
+
172
+ # Show success message
173
+ st.success("Document generated successfully!")
174
+
175
+ # Display generated document
176
+ st.markdown(
177
+ "<div class='card'>"
178
+ "<h4>Generated Document</h4>"
179
+ f"<pre style='white-space: pre-wrap;'>{generated_content}</pre>"
180
+ "</div>",
181
+ unsafe_allow_html=True
182
+ )
183
+
184
+ # Action buttons
185
+ col1, col2 = st.columns(2)
186
+ with col1:
187
+ st.download_button(
188
+ "📥 Download Document",
189
+ generated_content,
190
+ file_name=f"{doc_name}.txt",
191
+ mime="text/plain",
192
+ use_container_width=True
193
+ )
194
+
195
+ with col2:
196
+ if st.button("📋 Create Another", use_container_width=True):
197
+ st.rerun()
198
+
199
+ return True
200
+
201
+ except Exception as e:
202
+ st.error(f"Error generating document: {str(e)}")
203
+ return False
204
+
205
+ return False
206
+
207
+ if __name__ == "__main__":
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
208
  writing_assistant_page()