Shakeel1979 commited on
Commit
74c1fa6
Β·
verified Β·
1 Parent(s): e42e4ad

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +63 -63
app.py CHANGED
@@ -1,5 +1,4 @@
1
  import streamlit as st
2
- # import os
3
  import numpy as np
4
  import matplotlib.pyplot as plt
5
  from matplotlib.patches import Polygon, Circle
@@ -227,10 +226,10 @@ def main():
227
  for point, label in [('1', 'A'), ('2', 'B'), ('3', 'C')]:
228
  cols = st.sidebar.columns([3, 3])
229
  coordinates[f'x{point}'] = cols[0].number_input(
230
- f"X{point}", value=0.0, min_value=-100.0, max_value=100.0, step=0.1
231
  )
232
  coordinates[f'y{point}'] = cols[1].number_input(
233
- f"Y{point}", value=0.0, min_value=-100.0, max_value=100.0, step=0.1
234
  )
235
  return coordinates
236
 
@@ -318,7 +317,7 @@ def main():
318
  # Plot triangle
319
  fig = plot_triangle(vertices, properties)
320
 
321
- ### Old codea for Save as PDF
322
  # Generate PDF and get the data
323
  # save_as_pdf_reportlab(
324
  # coords['x1'], coords['y1'], coords['x2'], coords['y2'], coords['x3'], coords['y3'],
@@ -333,73 +332,74 @@ def main():
333
  # st.download_button("Download PDF", pdf_data,
334
  # file_name="Triangle_solver_results.pdf",
335
  # mime="application/pdf")
336
- ### Old code2 for Save as PDF
337
- # if st.button("Save as PDF"):
338
- # save_as_pdf_reportlab(
339
- # coords['x1'], coords['y1'], coords['x2'], coords['y2'], coords['x3'], coords['y3'],
340
- # a, b, c, A, B, C, area, perimeter, I_x, I_y, U_x, U_y, G_x, G_y,
341
- # midpoints, radius_in, radius_circum, fig
342
- # )
343
- # st.success("Results saved as PDF!")
344
- # with open("Triangle_solver_results.pdf", "rb") as pdf_file:
345
- # st.download_button("Download PDF", pdf_file, file_name="Triangle_solver_results.pdf")
346
 
347
- ### New code for Save as PDF
348
  if st.button("Save as PDF"):
349
- try:
350
- # Add debug message
351
- st.info("Creating PDF... Please wait")
 
 
 
 
 
 
 
 
 
 
 
352
 
353
- # Call your PDF creation function
354
- save_as_pdf_reportlab(
355
- coords['x1'], coords['y1'], coords['x2'], coords['y2'], coords['x3'], coords['y3'],
356
- a, b, c, A, B, C, area, perimeter, I_x, I_y, U_x, U_y, G_x, G_y,
357
- midpoints, radius_in, radius_circum, fig
358
- )
359
 
360
- # Check if file exists and has content
361
- pdf_path = "Triangle_solver_results.pdf"
362
 
363
- if os.path.exists(pdf_path) and os.path.getsize(pdf_path) > 0:
364
- st.success("PDF created successfully!")
365
 
366
- # Read the PDF file
367
- with open(pdf_path, "rb") as pdf_file:
368
- pdf_data = pdf_file.read()
369
 
370
- # Create download button
371
- st.download_button(
372
- label="πŸ“„ Download PDF",
373
- data=pdf_data,
374
- file_name="Triangle_solver_results.pdf",
375
- mime="application/pdf"
376
- )
377
- else:
378
- st.error("❌ PDF file was not created or is empty!")
379
- st.info("Check if the save_as_pdf_reportlab function is working correctly")
380
 
381
- except FileNotFoundError as e:
382
- st.error(f"❌ File not found: {e}")
383
- except PermissionError as e:
384
- st.error(f"❌ Permission denied: {e}")
385
- except Exception as e:
386
- st.error(f"❌ Error creating PDF: {str(e)}")
387
- st.info("Please check your save_as_pdf_reportlab function for errors")
388
-
389
- # Alternative: Test if your PDF function works at all
390
- if st.button("πŸ” Debug PDF Function"):
391
- try:
392
- st.info("Testing PDF creation...")
393
- # Test with minimal parameters
394
- save_as_pdf_reportlab(
395
- coords['x1'], coords['y1'], coords['x2'], coords['y2'], coords['x3'], coords['y3'],
396
- a, b, c, A, B, C, area, perimeter, I_x, I_y, U_x, U_y, G_x, G_y,
397
- midpoints, radius_in, radius_circum, fig
398
- )
399
- st.success("PDF function executed without errors")
400
- except Exception as e:
401
- st.error(f"PDF function failed: {str(e)}")
402
- st.code(str(e)) # Show detailed error
403
 
404
  if __name__ == "__main__":
405
  main()
 
1
  import streamlit as st
 
2
  import numpy as np
3
  import matplotlib.pyplot as plt
4
  from matplotlib.patches import Polygon, Circle
 
226
  for point, label in [('1', 'A'), ('2', 'B'), ('3', 'C')]:
227
  cols = st.sidebar.columns([3, 3])
228
  coordinates[f'x{point}'] = cols[0].number_input(
229
+ f"X{point}", value=0.0, min_value=-100.0, max_value=100.0, step=0.001, format="%.3f"
230
  )
231
  coordinates[f'y{point}'] = cols[1].number_input(
232
+ f"Y{point}", value=0.0, min_value=-100.0, max_value=100.0, step=0.001, format="%.3f"
233
  )
234
  return coordinates
235
 
 
317
  # Plot triangle
318
  fig = plot_triangle(vertices, properties)
319
 
320
+ ### Old code for Save as PDF
321
  # Generate PDF and get the data
322
  # save_as_pdf_reportlab(
323
  # coords['x1'], coords['y1'], coords['x2'], coords['y2'], coords['x3'], coords['y3'],
 
332
  # st.download_button("Download PDF", pdf_data,
333
  # file_name="Triangle_solver_results.pdf",
334
  # mime="application/pdf")
 
 
 
 
 
 
 
 
 
 
335
 
336
+ ## Code for Save as PDF
337
  if st.button("Save as PDF"):
338
+ save_as_pdf_reportlab(
339
+ coords['x1'], coords['y1'], coords['x2'], coords['y2'], coords['x3'], coords['y3'],
340
+ a, b, c, A, B, C, area, perimeter, I_x, I_y, U_x, U_y, G_x, G_y,
341
+ midpoints, radius_in, radius_circum, fig
342
+ )
343
+ st.success("Results saved as PDF!")
344
+ with open("Triangle_solver_results.pdf", "rb") as pdf_file:
345
+ st.download_button("Download PDF", pdf_file, file_name="Triangle_solver_results.pdf")
346
+
347
+ ### New code for Save as PDF
348
+ # if st.button("Save as PDF"):
349
+ # try:
350
+ # # Add debug message
351
+ # st.info("Creating PDF... Please wait")
352
 
353
+ # # Call your PDF creation function
354
+ # save_as_pdf_reportlab(
355
+ # coords['x1'], coords['y1'], coords['x2'], coords['y2'], coords['x3'], coords['y3'],
356
+ # a, b, c, A, B, C, area, perimeter, I_x, I_y, U_x, U_y, G_x, G_y,
357
+ # midpoints, radius_in, radius_circum, fig
358
+ # )
359
 
360
+ # # Check if file exists and has content
361
+ # pdf_path = "Triangle_solver_results.pdf"
362
 
363
+ # if os.path.exists(pdf_path) and os.path.getsize(pdf_path) > 0:
364
+ # st.success("PDF created successfully!")
365
 
366
+ # # Read the PDF file
367
+ # with open(pdf_path, "rb") as pdf_file:
368
+ # pdf_data = pdf_file.read()
369
 
370
+ # # Create download button
371
+ # st.download_button(
372
+ # label="πŸ“„ Download PDF",
373
+ # data=pdf_data,
374
+ # file_name="Triangle_solver_results.pdf",
375
+ # mime="application/pdf"
376
+ # )
377
+ # else:
378
+ # st.error("❌ PDF file was not created or is empty!")
379
+ # st.info("Check if the save_as_pdf_reportlab function is working correctly")
380
 
381
+ # except FileNotFoundError as e:
382
+ # st.error(f"❌ File not found: {e}")
383
+ # except PermissionError as e:
384
+ # st.error(f"❌ Permission denied: {e}")
385
+ # except Exception as e:
386
+ # st.error(f"❌ Error creating PDF: {str(e)}")
387
+ # st.info("Please check your save_as_pdf_reportlab function for errors")
388
+
389
+ # # Alternative: Test if your PDF function works at all
390
+ # if st.button("πŸ” Debug PDF Function"):
391
+ # try:
392
+ # st.info("Testing PDF creation...")
393
+ # # Test with minimal parameters
394
+ # save_as_pdf_reportlab(
395
+ # coords['x1'], coords['y1'], coords['x2'], coords['y2'], coords['x3'], coords['y3'],
396
+ # a, b, c, A, B, C, area, perimeter, I_x, I_y, U_x, U_y, G_x, G_y,
397
+ # midpoints, radius_in, radius_circum, fig
398
+ # )
399
+ # st.success("PDF function executed without errors")
400
+ # except Exception as e:
401
+ # st.error(f"PDF function failed: {str(e)}")
402
+ # st.code(str(e)) # Show detailed error
403
 
404
  if __name__ == "__main__":
405
  main()