jonathanjordan21 commited on
Commit
2895d9c
·
verified ·
1 Parent(s): ab35ae7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +15 -2
app.py CHANGED
@@ -25,6 +25,9 @@ class Ticket(BaseModel):
25
 
26
  class Code(BaseModel):
27
  code: str
 
 
 
28
 
29
  @app.get("/")
30
  def greet_json():
@@ -48,7 +51,7 @@ async def run_code(code: Code):
48
  exec(code.code)
49
  # img_buffer.seek(0) # Reset buffer position
50
 
51
- file_path = "graph.pdf"
52
 
53
  # if "plt.subplots(" in code.code:
54
  # print("SUBPLOTS DETECTED")
@@ -76,4 +79,14 @@ async def run_code(code: Code):
76
 
77
  # return Response(content=img_buffer.getvalue(), media_type="image/png")
78
  # return FileResponse(file_path, media_type="image/png")
79
- return FileResponse(file_path, media_type="application/pdf", filename="graph.pdf")
 
 
 
 
 
 
 
 
 
 
 
25
 
26
  class Code(BaseModel):
27
  code: str
28
+ project_id: str
29
+ chain_id: str
30
+ session_id: str
31
 
32
  @app.get("/")
33
  def greet_json():
 
51
  exec(code.code)
52
  # img_buffer.seek(0) # Reset buffer position
53
 
54
+ file_path = f"graphs_{code.project_id}_{code.chain_id}_{code.session_id}.pdf"
55
 
56
  # if "plt.subplots(" in code.code:
57
  # print("SUBPLOTS DETECTED")
 
79
 
80
  # return Response(content=img_buffer.getvalue(), media_type="image/png")
81
  # return FileResponse(file_path, media_type="image/png")
82
+ return FileResponse(file_path, media_type="application/pdf", filename="graph.pdf")
83
+
84
+
85
+
86
+ @app.get("/chart/{project_id}/{chain_id}")
87
+ async def get_chart(project_id: str, chain_id: str, session_id: str):
88
+
89
+ # Return as application/pdf response
90
+ return Response(pdf_buffer.read(), media_type="application/pdf", headers={
91
+ "Content-Disposition": f'inline; filename="graphs_{project_id}_{chain_id}_{session_id}.pdf"'
92
+ })