Spaces:
Runtime error
Runtime error
Download api.py from dragonhearted/calculator_api: direct link, hf CLI and curl.
- Browser
- Download file 591 Bytes
-
https://huggingface.co/spaces/dragonhearted/calculator_api/resolve/main/api.py
- Command line
-
hf download hf://spaces/dragonhearted/calculator_api/api.py
-
curl -L -o api.py https://huggingface.co/spaces/dragonhearted/calculator_api/resolve/main/api.py
591 Bytes
| from fastapi import FastAPI | |
| from pydantic import BaseModel | |
| import uvicorn | |
| app = FastAPI() | |
| class Inputs(BaseModel): | |
| expression: str | |
| def calculate(expression): | |
| try: | |
| result = eval(expression) | |
| return result | |
| except Exception as e: | |
| raise Exception("ERROR") | |
| async def calculate_endpoint(request: Inputs): | |
| try: | |
| result = calculate(request.expression) | |
| return {'result': result} | |
| except Exception as e: | |
| return {"error": str(e)} | |
| if __name__ == "__main__": | |
| uvicorn.run(app, host="0.0.0.0", port = 8000) |