Spaces:
Sleeping
Sleeping
Update main.py
Browse files
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 |
-
|
| 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",
|