Spaces:
Sleeping
Sleeping
NikhilSetiya
commited on
Commit
·
951c6d3
1
Parent(s):
5ebb00f
Fix build issues and update dependencies
Browse files- app.py +2 -1
- backend.py +46 -0
- requirements.txt +2 -1
app.py
CHANGED
@@ -1,4 +1,5 @@
|
|
|
|
1 |
from frontend import demo
|
2 |
|
3 |
if __name__ == "__main__":
|
4 |
-
demo.launch()
|
|
|
1 |
+
import gradio as gr
|
2 |
from frontend import demo
|
3 |
|
4 |
if __name__ == "__main__":
|
5 |
+
demo.launch(server_name="0.0.0.0", server_port=7860)
|
backend.py
ADDED
@@ -0,0 +1,46 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from fastapi import FastAPI
|
2 |
+
from pydantic import BaseModel
|
3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
4 |
+
|
5 |
+
app = FastAPI()
|
6 |
+
|
7 |
+
# Add CORS middleware
|
8 |
+
app.add_middleware(
|
9 |
+
CORSMiddleware,
|
10 |
+
allow_origins=["*"],
|
11 |
+
allow_credentials=True,
|
12 |
+
allow_methods=["*"],
|
13 |
+
allow_headers=["*"],
|
14 |
+
)
|
15 |
+
|
16 |
+
class CalculatorInput(BaseModel):
|
17 |
+
num1: float
|
18 |
+
num2: float
|
19 |
+
operation: str
|
20 |
+
|
21 |
+
class CalculatorResponse(BaseModel):
|
22 |
+
result: float
|
23 |
+
operation: str
|
24 |
+
|
25 |
+
@app.post("/calculate", response_model=CalculatorResponse)
|
26 |
+
async def calculate(input_data: CalculatorInput):
|
27 |
+
result = 0.0
|
28 |
+
|
29 |
+
if input_data.operation == "add":
|
30 |
+
result = input_data.num1 + input_data.num2
|
31 |
+
elif input_data.operation == "subtract":
|
32 |
+
result = input_data.num1 - input_data.num2
|
33 |
+
elif input_data.operation == "multiply":
|
34 |
+
result = input_data.num1 * input_data.num2
|
35 |
+
elif input_data.operation == "divide":
|
36 |
+
if input_data.num2 == 0:
|
37 |
+
raise ValueError("Cannot divide by zero")
|
38 |
+
result = input_data.num1 / input_data.num2
|
39 |
+
else:
|
40 |
+
raise ValueError("Invalid operation")
|
41 |
+
|
42 |
+
return CalculatorResponse(result=result, operation=input_data.operation)
|
43 |
+
|
44 |
+
if __name__ == "__main__":
|
45 |
+
import uvicorn
|
46 |
+
uvicorn.run(app, host="0.0.0.0", port=8000)
|
requirements.txt
CHANGED
@@ -1,7 +1,8 @@
|
|
1 |
gradio==4.12.0
|
2 |
-
requests==2.31.0
|
3 |
fastapi==0.104.1
|
4 |
uvicorn==0.24.0
|
5 |
pydantic==2.5.2
|
|
|
|
|
6 |
pytest==7.4.3
|
7 |
httpx==0.25.2
|
|
|
1 |
gradio==4.12.0
|
|
|
2 |
fastapi==0.104.1
|
3 |
uvicorn==0.24.0
|
4 |
pydantic==2.5.2
|
5 |
+
requests==2.31.0
|
6 |
+
python-multipart==0.0.6
|
7 |
pytest==7.4.3
|
8 |
httpx==0.25.2
|