Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,5 +1,6 @@
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.responses import Response
|
|
|
|
| 3 |
from pydantic import BaseModel
|
| 4 |
|
| 5 |
import random
|
|
@@ -42,9 +43,14 @@ async def create_ticket(ticket: Ticket):
|
|
| 42 |
|
| 43 |
@app.post("/run_code")
|
| 44 |
async def run_code(code: Code):
|
| 45 |
-
img_buffer = io.BytesIO()
|
| 46 |
exec(code.code)
|
| 47 |
-
img_buffer.seek(0) # Reset buffer position
|
|
|
|
|
|
|
|
|
|
|
|
|
| 48 |
|
| 49 |
# Return image as response
|
| 50 |
-
return Response(content=img_buffer.getvalue(), media_type="image/png")
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
| 2 |
from fastapi.responses import Response
|
| 3 |
+
from fastapi.responses import FileResponse
|
| 4 |
from pydantic import BaseModel
|
| 5 |
|
| 6 |
import random
|
|
|
|
| 43 |
|
| 44 |
@app.post("/run_code")
|
| 45 |
async def run_code(code: Code):
|
| 46 |
+
# img_buffer = io.BytesIO()
|
| 47 |
exec(code.code)
|
| 48 |
+
# img_buffer.seek(0) # Reset buffer position
|
| 49 |
+
|
| 50 |
+
file_path = "graph.png"
|
| 51 |
+
plt.savefig(file_path)
|
| 52 |
+
plt.close()
|
| 53 |
|
| 54 |
# Return image as response
|
| 55 |
+
# return Response(content=img_buffer.getvalue(), media_type="image/png")
|
| 56 |
+
return FileResponse(file_path, media_type="image/png")
|