Spaces:
Runtime error
Runtime error
Upload app.py with huggingface_hub
Browse files
app.py
CHANGED
|
@@ -200,44 +200,9 @@ def import_date():
|
|
| 200 |
return datetime.now().strftime("%B %d, %Y")
|
| 201 |
|
| 202 |
def generate_header_image(topic, tone):
|
| 203 |
-
"""Generate
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
if image_generator is None:
|
| 207 |
-
return None
|
| 208 |
-
|
| 209 |
-
try:
|
| 210 |
-
# Create business-focused prompt with LoRA triggers
|
| 211 |
-
business_style = {
|
| 212 |
-
"Professional": "corporate office style, business presentation",
|
| 213 |
-
"Casual": "modern startup office, friendly business environment",
|
| 214 |
-
"Academic": "research presentation, educational infographic",
|
| 215 |
-
"Persuasive": "marketing presentation, compelling business visual",
|
| 216 |
-
"Informative": "clean infographic style, data visualization"
|
| 217 |
-
}
|
| 218 |
-
|
| 219 |
-
style_desc = business_style.get(tone, "professional business")
|
| 220 |
-
|
| 221 |
-
# Enhanced prompt for business LoRAs
|
| 222 |
-
image_prompt = f"Professional business infographic header for {topic}, {style_desc}, clean corporate design, business graphics, office environment, high quality, no text, ultra realistic"
|
| 223 |
-
|
| 224 |
-
# Use optimized generation settings
|
| 225 |
-
generator = torch.Generator().manual_seed(42) # Consistent seed for business docs
|
| 226 |
-
|
| 227 |
-
# Generate with optimized settings
|
| 228 |
-
image = image_generator(
|
| 229 |
-
prompt=image_prompt,
|
| 230 |
-
num_inference_steps=1, # Ultra-fast with Schnell + optimizations
|
| 231 |
-
generator=generator,
|
| 232 |
-
height=384, # Better aspect ratio for headers
|
| 233 |
-
width=768,
|
| 234 |
-
).images[0]
|
| 235 |
-
|
| 236 |
-
return image
|
| 237 |
-
|
| 238 |
-
except Exception as e:
|
| 239 |
-
print(f"Optimized image generation failed: {str(e)}")
|
| 240 |
-
return None
|
| 241 |
|
| 242 |
def export_to_pdf(content, topic, header_image=None):
|
| 243 |
"""Export the one-pager content to PDF"""
|
|
@@ -272,28 +237,14 @@ def export_to_pdf(content, topic, header_image=None):
|
|
| 272 |
# Build PDF content
|
| 273 |
story = []
|
| 274 |
|
| 275 |
-
#
|
| 276 |
if header_image:
|
| 277 |
try:
|
| 278 |
-
#
|
| 279 |
-
|
| 280 |
-
header_image.save(img_buffer, format='PNG')
|
| 281 |
-
img_buffer.seek(0)
|
| 282 |
-
|
| 283 |
-
with tempfile.NamedTemporaryFile(delete=False, suffix='.png') as img_file:
|
| 284 |
-
img_file.write(img_buffer.getvalue())
|
| 285 |
-
img_path = img_file.name
|
| 286 |
-
|
| 287 |
-
# Add image to PDF
|
| 288 |
-
img = RLImage(img_path, width=6*inch, height=3*inch)
|
| 289 |
-
story.append(img)
|
| 290 |
story.append(Spacer(1, 20))
|
| 291 |
-
|
| 292 |
-
# Clean up temp image file
|
| 293 |
-
os.unlink(img_path)
|
| 294 |
-
|
| 295 |
except Exception as e:
|
| 296 |
-
print(f"Failed to add image
|
| 297 |
|
| 298 |
# Add title
|
| 299 |
story.append(Paragraph(f"Business Document: {topic}", title_style))
|
|
@@ -382,8 +333,9 @@ def create_interface():
|
|
| 382 |
|
| 383 |
include_image_checkbox = gr.Checkbox(
|
| 384 |
label="Generate Header Image",
|
| 385 |
-
value=
|
| 386 |
-
info="
|
|
|
|
| 387 |
)
|
| 388 |
|
| 389 |
generate_btn = gr.Button("π Generate One-Pager", variant="primary")
|
|
@@ -444,12 +396,12 @@ def create_interface():
|
|
| 444 |
|
| 445 |
# Initialize model and launch
|
| 446 |
if __name__ == "__main__":
|
| 447 |
-
print("π Starting One-Pager Generator with
|
| 448 |
print("π₯ Loading AI text model...")
|
| 449 |
model_status = initialize_model()
|
| 450 |
print(f"β
{model_status}")
|
| 451 |
|
| 452 |
-
print("π¨
|
| 453 |
image_status = initialize_image_generator()
|
| 454 |
print(f"β
{image_status}")
|
| 455 |
|
|
|
|
| 200 |
return datetime.now().strftime("%B %d, %Y")
|
| 201 |
|
| 202 |
def generate_header_image(topic, tone):
|
| 203 |
+
"""Generate header image placeholder (image generation disabled)"""
|
| 204 |
+
# Image generation disabled for now to avoid dependency issues
|
| 205 |
+
return None
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 206 |
|
| 207 |
def export_to_pdf(content, topic, header_image=None):
|
| 208 |
"""Export the one-pager content to PDF"""
|
|
|
|
| 237 |
# Build PDF content
|
| 238 |
story = []
|
| 239 |
|
| 240 |
+
# Skip image handling for now (images disabled)
|
| 241 |
if header_image:
|
| 242 |
try:
|
| 243 |
+
# Add placeholder for image
|
| 244 |
+
story.append(Paragraph("[Header Image Placeholder]", title_style))
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 245 |
story.append(Spacer(1, 20))
|
|
|
|
|
|
|
|
|
|
|
|
|
| 246 |
except Exception as e:
|
| 247 |
+
print(f"Failed to add image placeholder: {str(e)}")
|
| 248 |
|
| 249 |
# Add title
|
| 250 |
story.append(Paragraph(f"Business Document: {topic}", title_style))
|
|
|
|
| 333 |
|
| 334 |
include_image_checkbox = gr.Checkbox(
|
| 335 |
label="Generate Header Image",
|
| 336 |
+
value=False,
|
| 337 |
+
info="Image generation temporarily disabled",
|
| 338 |
+
interactive=False
|
| 339 |
)
|
| 340 |
|
| 341 |
generate_btn = gr.Button("π Generate One-Pager", variant="primary")
|
|
|
|
| 396 |
|
| 397 |
# Initialize model and launch
|
| 398 |
if __name__ == "__main__":
|
| 399 |
+
print("π Starting One-Pager Generator with modern AI via Inference API...")
|
| 400 |
print("π₯ Loading AI text model...")
|
| 401 |
model_status = initialize_model()
|
| 402 |
print(f"β
{model_status}")
|
| 403 |
|
| 404 |
+
print("π¨ Initializing image generator...")
|
| 405 |
image_status = initialize_image_generator()
|
| 406 |
print(f"β
{image_status}")
|
| 407 |
|