geeksiddhant commited on
Commit
03d11e5
·
verified ·
1 Parent(s): 9977846

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from fastapi import FastAPI
2
+ import gradio as gr
3
+ from pydantic import BaseModel
4
+
5
+ app = FastAPI()
6
+
7
+ class Numbers(BaseModel):
8
+ num1: float
9
+ num2: float
10
+
11
+ @app.post("/add")
12
+ async def add_numbers(numbers: Numbers):
13
+ result = numbers.num1 + numbers.num2
14
+ return {"sum": result}
15
+
16
+ def greet(name):
17
+ return f"Hello, {name}!"
18
+
19
+ gradio_app = gr.Interface(fn=greet, inputs="text", outputs="text")
20
+
21
+ app = gr.mount_gradio_app(app, gradio_app, path="/gradio")
22
+
23
+ @app.get("/")
24
+ async def read_root():
25
+ return {"message": "Welcome to the FastAPI and Gradio app!"}
26
+
27
+ if __name__ == "__main__":
28
+ import uvicorn
29
+ uvicorn.run(app, host="0.0.0.0", port=8000)