geeksiddhant commited on
Commit
03044c8
·
verified ·
1 Parent(s): b81aac5

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -6
app.py CHANGED
@@ -1,24 +1,29 @@
1
  from fastapi import FastAPI
2
  import gradio as gr
 
3
 
4
- # Initialize the FastAPI app
5
  app = FastAPI()
6
 
7
- # Define your Gradio interface
 
 
 
 
 
 
 
 
8
  def greet(name):
9
  return f"Hello, {name}!"
10
 
11
  gradio_app = gr.Interface(fn=greet, inputs="text", outputs="text")
12
 
13
- # Mount the Gradio app onto the FastAPI app
14
  app = gr.mount_gradio_app(app, gradio_app, path="/gradio")
15
 
16
- # Optional: Define additional FastAPI routes
17
  @app.get("/")
18
  async def read_root():
19
  return {"message": "Welcome to the FastAPI and Gradio app!"}
20
 
21
- # Run the app with Uvicorn
22
  if __name__ == "__main__":
23
  import uvicorn
24
- uvicorn.run(app, host="0.0.0.0", port=7860)
 
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)