Spaces:
Sleeping
Sleeping
Update pages/3_✍️_Writing_Assistant.py
Browse files- 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 |
-
|
| 37 |
-
"
|
| 38 |
-
"
|
| 39 |
-
"
|
| 40 |
-
"
|
| 41 |
-
"
|
| 42 |
-
"
|
| 43 |
-
"
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
"Document
|
| 49 |
-
options=list(
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
st.
|
| 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 |
-
st.
|
| 108 |
-
|
| 109 |
-
if validate_and_generate("
|
| 110 |
-
st.balloons()
|
| 111 |
-
|
| 112 |
-
def
|
| 113 |
-
"""
|
| 114 |
-
st.markdown(
|
| 115 |
-
"<div class='card'>"
|
| 116 |
-
"<h4>
|
| 117 |
-
unsafe_allow_html=True
|
| 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 |
-
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()
|