Corran commited on
Commit
fd25f55
·
verified ·
1 Parent(s): ca56f16

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +7 -6
main.py CHANGED
@@ -6,22 +6,23 @@ app = FastAPI()
6
 
7
  @app.get("/")
8
  def run_notebook(fruits: str):
 
9
  fruit_list = fruits.split(",")
10
 
 
 
 
11
  # Execute the notebook with Papermill
12
- output_path = "output.ipynb"
13
  pm.execute_notebook(
14
  "fruitchecker.ipynb",
15
- output_path,
16
  parameters={"fruits": fruit_list}
17
  )
18
 
 
 
19
  # Extract the CSV result
20
  with open(output_path, "r") as f:
21
- notebook_content = f.read()
22
-
23
- # Find the CSV output in the notebook
24
- csv_output = notebook_content.split("csv_output = ")[-1].strip().strip("\"'")
25
 
26
  # Return as downloadable CSV
27
  return Response(content=csv_output, media_type="text/csv",
 
6
 
7
  @app.get("/")
8
  def run_notebook(fruits: str):
9
+
10
  fruit_list = fruits.split(",")
11
 
12
+ with open("fruits.txt", "w") as f:
13
+ f.write("\n".join(fruit_list))
14
+
15
  # Execute the notebook with Papermill
 
16
  pm.execute_notebook(
17
  "fruitchecker.ipynb",
 
18
  parameters={"fruits": fruit_list}
19
  )
20
 
21
+ output_path = "output.csv"
22
+
23
  # Extract the CSV result
24
  with open(output_path, "r") as f:
25
+ csv_output = f.read()
 
 
 
26
 
27
  # Return as downloadable CSV
28
  return Response(content=csv_output, media_type="text/csv",