File size: 1,888 Bytes
7498a97
eca5da4
 
 
604987c
7498a97
 
 
eca5da4
 
 
 
 
 
 
 
 
 
 
7498a97
 
 
 
 
 
eca5da4
604987c
 
 
8c924eb
 
 
 
ec8c795
e3f9d7d
999bfec
8c924eb
 
 
ec8c795
8c924eb
604987c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
50
51
52
53
54
55
56
from fastapi import FastAPI, HTTPException, Body
from fastapi.staticfiles import StaticFiles
from fastapi.templating import Jinja2Templates
from starlette.requests import Request
from fastapi.middleware.cors import CORSMiddleware

app = FastAPI()

# Mount the static directory for serving static files like CSS, JS, etc.
app.mount("/static", StaticFiles(directory="static"), name="static")

# Setting up the Jinja2 templating with the templates directory
templates = Jinja2Templates(directory="templates")

@app.get("/")
async def read_root(request: Request):
    # Using the template for the homepage and passing some dynamic data (in this case, "name": "John")
    return templates.TemplateResponse("index.html", {"request": request, "name": "John"})

@app.post("/question/")
async def read_question(question: str = Body(..., embed=True)):
    return {"Received Question": question}

@app.post("/opportunity/")
async def read_opportunity(opportunity: str = Body(..., embed=True)):
    return {"Received Opportunity": opportunity}

@app.post("/run-script/")
async def run_script():
    try:
        # Execute the python script
        from utilities import step1
        # The script executed successfully
        print(f' \n ****** \n GOOOOOOODDD')
        step1.run_step1()
        print(f' \n ****** \n GOOOOOOODDD -----------2')
        return {"status": "success", "message": "Script executed successfully"}
    except Exception as e:
        # There was an error during script execution
        print(f' \n ****** \n BADDDDD \n {str(e)}')
        return {"status": "error", "message": str(e)}

origins = [
    "http://localhost",
    "http://localhost:8000",
    "http://localhost:4000",
    "https://bfmanza-fastapitest1.hf.space"
]

app.add_middleware(
    CORSMiddleware,
    allow_origins=origins,
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)