Spaces:
Runtime error
Runtime error
Download main.py from BFManza/FastAPITest1: direct link, hf CLI and curl.
- Browser
- Download file 1.89 kB
-
https://huggingface.co/spaces/BFManza/FastAPITest1/resolve/main/main.py
- Command line
-
hf download hf://spaces/BFManza/FastAPITest1/main.py
-
curl -L -o main.py https://huggingface.co/spaces/BFManza/FastAPITest1/resolve/main/main.py
1.89 kB
| 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") | |
| 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"}) | |
| async def read_question(question: str = Body(..., embed=True)): | |
| return {"Received Question": question} | |
| async def read_opportunity(opportunity: str = Body(..., embed=True)): | |
| return {"Received Opportunity": opportunity} | |
| 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=["*"], | |
| ) |