jonathanjordan21 commited on
Commit
2cb9c9a
·
verified ·
1 Parent(s): 5add6b6

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -0
app.py CHANGED
@@ -3,6 +3,11 @@ from pydantic import BaseModel
3
 
4
  import random
5
 
 
 
 
 
 
6
  app = FastAPI()
7
 
8
  # Define the ticket schema using Pydantic
@@ -14,6 +19,10 @@ class Ticket(BaseModel):
14
  service_category: str
15
  difficulty: int # Adjust type as needed (e.g., int or str)
16
 
 
 
 
 
17
  @app.get("/")
18
  def greet_json():
19
  return {"Hello": "World!"}
@@ -28,3 +37,13 @@ async def create_ticket(ticket: Ticket):
28
  "message": "Ticket created successfully",
29
  "ticket": tick
30
  }
 
 
 
 
 
 
 
 
 
 
 
3
 
4
  import random
5
 
6
+ import matplotlib.pyplot as plt
7
+ import pandas as pd
8
+
9
+ import io
10
+
11
  app = FastAPI()
12
 
13
  # Define the ticket schema using Pydantic
 
19
  service_category: str
20
  difficulty: int # Adjust type as needed (e.g., int or str)
21
 
22
+
23
+ class Code(BaseModel):
24
+ code: str
25
+
26
  @app.get("/")
27
  def greet_json():
28
  return {"Hello": "World!"}
 
37
  "message": "Ticket created successfully",
38
  "ticket": tick
39
  }
40
+
41
+
42
+ @app.post("/run_code")
43
+ async def run_code(code: Code):
44
+ img_buffer = io.BytesIO()
45
+ exec(code.code)
46
+ img_buffer.seek(0) # Reset buffer position
47
+
48
+ # Return image as response
49
+ return Response(content=img_buffer.getvalue(), media_type="image/png")