File size: 1,104 Bytes
d24bd61
46bcd76
6915dbd
5add6b6
 
2cb9c9a
 
 
 
 
04adfa1
 
46bcd76
 
 
 
 
 
 
 
6915dbd
2cb9c9a
 
 
 
d24bd61
 
 
46bcd76
 
 
 
 
5add6b6
 
46bcd76
 
5add6b6
46bcd76
2cb9c9a
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
from fastapi import FastAPI
from pydantic import BaseModel

import random

import matplotlib.pyplot as plt
import pandas as pd

import io

app = FastAPI()

# Define the ticket schema using Pydantic
class Ticket(BaseModel):
    name: str
    department: str
    category: str
    description: str
    service_category: str
    difficulty: int  # Adjust type as needed (e.g., int or str)


class Code(BaseModel):
    code: str

@app.get("/")
def greet_json():
    return {"Hello": "World!"}

@app.post("/ticket")
async def create_ticket(ticket: Ticket):
    # Here you can process the ticket, e.g., save it to a database.
    # For now, we simply return the received ticket data.
    tick = ticket.dict()
    tick["number"] = random.randint(1000, 9999)
    return {
        "message": "Ticket created successfully",
        "ticket": tick
    }


@app.post("/run_code")
async def run_code(code: Code):
    img_buffer = io.BytesIO()
    exec(code.code)
    img_buffer.seek(0)  # Reset buffer position

    # Return image as response
    return Response(content=img_buffer.getvalue(), media_type="image/png")