praiteri commited on
Commit
9012508
·
1 Parent(s): 31fd788

repo update from private

Browse files
Files changed (3) hide show
  1. marimo/app.py +34 -29
  2. marimo/crystal_violet.py +1 -1
  3. marimo/index.html +28 -10
marimo/app.py CHANGED
@@ -1,8 +1,10 @@
1
  from typing import Annotated, Callable, Coroutine
2
- from fastapi.responses import HTMLResponse, RedirectResponse
3
  import marimo
4
  from fastapi import FastAPI, Form, Request, Response
5
  import os
 
 
6
 
7
  # Create a FastAPI app
8
  app = FastAPI()
@@ -22,6 +24,35 @@ marimo_server = (
22
  .with_app(path="/surface", root="./surface_adsorption.py")
23
  )
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  # Mount the marimo server at the root
26
  # This will handle all the routes defined in the marimo server
27
  app.mount("", marimo_server.build())
@@ -29,31 +60,5 @@ app.mount("", marimo_server.build())
29
  # Run the server
30
  if __name__ == "__main__":
31
  import uvicorn
32
- uvicorn.run(app, host="0.0.0.0", port=8000)
33
-
34
- #from typing import Annotated, Callable, Coroutine
35
- #from fastapi.responses import HTMLResponse, RedirectResponse
36
- #import marimo
37
- #from fastapi import FastAPI, Form, Request, Response
38
- #
39
- #
40
- ## Create a marimo asgi app
41
- #server = (
42
- # marimo.create_asgi_app()
43
- # .with_app(path="", root="./index.py")
44
- # .with_app(path="/bc", root="./bomb_calorimetry.py")
45
- # .with_app(path="/cv", root="./crystal_violet.py")
46
- # .with_app(path="/stats", root="./statistics_lab.py")
47
- # .with_app(path="/surface", root="./surface_adsorption.py")
48
- #)
49
- #
50
- ## Create a FastAPI app
51
- #app = FastAPI()
52
- #
53
- #app.mount("/", server.build())
54
- #
55
- ## Run the server
56
- #if __name__ == "__main__":
57
- # import uvicorn
58
- #
59
- # uvicorn.run(app, host="0.0.0.0", port=8000)
 
1
  from typing import Annotated, Callable, Coroutine
2
+ from fastapi.responses import HTMLResponse, RedirectResponse, FileResponse
3
  import marimo
4
  from fastapi import FastAPI, Form, Request, Response
5
  import os
6
+ from pathlib import Path
7
+
8
 
9
  # Create a FastAPI app
10
  app = FastAPI()
 
24
  .with_app(path="/surface", root="./surface_adsorption.py")
25
  )
26
 
27
+ # Create a route to download a file
28
+ @app.get("/download-pdf/{pdf_name}")
29
+ async def download_pdf(pdf_name: str):
30
+ # Assuming PDFs are stored in a 'pdfs' directory
31
+ pdf_path = f"../pdfs/{pdf_name}"
32
+
33
+ if os.path.exists(pdf_path):
34
+ return FileResponse(
35
+ pdf_path,
36
+ media_type='application/pdf',
37
+ filename=pdf_name
38
+ )
39
+ return {"error": f"PDF not found [../pdfs/{pdf_name}]"}, 404
40
+
41
+ # Create a route to display a pdf
42
+ @app.get("/pdf/direct/{pdf_name}")
43
+ async def get_pdf_direct(pdf_name: str):
44
+ pdf_path = Path(f"../pdfs/{pdf_name}")
45
+
46
+ if not pdf_path.exists():
47
+ raise HTTPException(status_code=404, detail=f"PDF not found {pdf_path}")
48
+
49
+ return FileResponse(
50
+ path=pdf_path,
51
+ media_type="application/pdf",
52
+ filename=pdf_name + ".pdf"
53
+ )
54
+
55
+
56
  # Mount the marimo server at the root
57
  # This will handle all the routes defined in the marimo server
58
  app.mount("", marimo_server.build())
 
60
  # Run the server
61
  if __name__ == "__main__":
62
  import uvicorn
63
+ uvicorn.run(app, host="0.0.0.0", port=2718)
64
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
marimo/crystal_violet.py CHANGED
@@ -16,7 +16,7 @@ def _():
16
  def _(mo):
17
  mo.md(
18
  """
19
- # Crystdal Violet Lab
20
 
21
  This notebook mimics a kinetics laboratory experiment, where a UV-Vis spectrophotometer is used to measure the absorbance as the reaction between crystal violet and hydroxide proceeds.
22
  The absorbance versus time data can then be used to determine the rate of the reaction with respect to both crystal violet and hydroxide ions.
 
16
  def _(mo):
17
  mo.md(
18
  """
19
+ # Crystal Violet Lab
20
 
21
  This notebook mimics a kinetics laboratory experiment, where a UV-Vis spectrophotometer is used to measure the absorbance as the reaction between crystal violet and hydroxide proceeds.
22
  The absorbance versus time data can then be used to determine the rate of the reaction with respect to both crystal violet and hydroxide ions.
marimo/index.html CHANGED
@@ -88,27 +88,45 @@
88
  <body>
89
  <h1>Chemical Energetics and Kinetics Virtual Notebook</h1>
90
 
91
- <h2>Labs</h2>
92
  <div class="lab-grid">
93
  <a href="/stats" class="lab-card">
94
- <h3>Statistics</h3>
95
- <p>Basic statistical concepts and Python introduction</p>
96
  </a>
97
  <a href="/bc" class="lab-card">
98
- <h3>Bomb Calorimetry</h3>
99
- <p>Thermodynamics and heat measurements</p>
100
  </a>
101
  <a href="/cv" class="lab-card">
102
- <h3>Crystal Violet</h3>
103
- <p>Chemical kinetics and reaction rates</p>
104
  </a>
105
  <a href="/surface" class="lab-card">
106
- <h3>Surface Adsorption</h3>
107
- <p>Equilibrium and surface chemistry</p>
 
 
 
 
 
 
 
 
108
  </a>
109
  </div>
110
 
111
- <h2><strong>Check the unit outline for when the reports are due</strong></h2>
 
 
 
 
 
 
 
 
 
 
112
 
113
  <p>This web page and those linked below have been created with Python using Jupyter Notebooks and will be used to develop important skills in data analysis, data processing, and computing using simulated experimental results and computational chemistry software.</p>
114
 
 
88
  <body>
89
  <h1>Chemical Energetics and Kinetics Virtual Notebook</h1>
90
 
91
+ <!-- <h2>Labs</h2> -->
92
  <div class="lab-grid">
93
  <a href="/stats" class="lab-card">
94
+ <h3 style="text-align: center">Statistics Lab</h3>
95
+ <p style="text-align: center">Basic statistical concepts and Python introduction<br>(Week 2)</p>
96
  </a>
97
  <a href="/bc" class="lab-card">
98
+ <h3 style="text-align: center">Bomb Calorimetry Lab</h3>
99
+ <p style="text-align: center">Thermodynamics and heat measurements<br>(Week 4)</p>
100
  </a>
101
  <a href="/cv" class="lab-card">
102
+ <h3 style="text-align: center">Crystal Violet Lab</h3>
103
+ <p style="text-align: center">Chemical kinetics and reaction rates<br>(Week 8)</p>
104
  </a>
105
  <a href="/surface" class="lab-card">
106
+ <h3 style="text-align: center">Surface Adsorption Lab</h3>
107
+ <p style="text-align: center">Equilibrium and surface chemistry<br>(Week 10)</p>
108
+ </a>
109
+ <a href="/download-pdf/LabManualCHEM2000-1.pdf" class="lab-card">
110
+ <h3 style="text-align: center">Lab Manual<br>(Download PDF)</h3>
111
+ <p style="text-align: center">Version 1 - 20/02/2025</p>
112
+ </a>
113
+ <a href="/download-pdf/NotesOfStatistics-1.pdf" class="lab-card">
114
+ <h3 style="text-align: center">Notes of Statistics<br>(Download PDF)</h3>
115
+ <p style="text-align: center">Version 1 - 20/02/2025</p>
116
  </a>
117
  </div>
118
 
119
+ <!--
120
+ <embed
121
+ src="/pdf/direct/calendar.pdf"
122
+ type="application/pdf"
123
+ width="100%"
124
+ height="600px"
125
+ />
126
+ -->
127
+
128
+
129
+ <h2 style="text-align: center"><strong>Check the unit outline for when the reports are due</strong></h2>
130
 
131
  <p>This web page and those linked below have been created with Python using Jupyter Notebooks and will be used to develop important skills in data analysis, data processing, and computing using simulated experimental results and computational chemistry software.</p>
132