rmaitest commited on
Commit
6a69f5f
·
verified ·
1 Parent(s): 8a57db9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -4
app.py CHANGED
@@ -1,9 +1,11 @@
 
 
1
  import gradio as gr
2
  import pandas as pd
3
  from huggingface_hub import hf_hub_download
4
  import joblib
5
  from fastapi import FastAPI
6
- from gradio import fastapi as gr_fastapi
7
 
8
  # Load the model
9
  repo_id = "rmaitest/mlmodel2"
@@ -42,11 +44,15 @@ iface = gr.Interface(
42
  # Create FastAPI app
43
  app = FastAPI()
44
 
45
- # Mount Gradio as an API on the /predict endpoint
46
- app = gr_fastapi.mount_gradio_app(app, iface, path="/predict")
 
 
 
47
 
48
- # Launch Gradio app (optionally with API)
49
  if __name__ == "__main__":
50
  iface.launch(share=True)
51
 
52
 
 
 
1
+ pip install gradio fastapi uvicorn
2
+
3
  import gradio as gr
4
  import pandas as pd
5
  from huggingface_hub import hf_hub_download
6
  import joblib
7
  from fastapi import FastAPI
8
+ from gradio.routes import Route
9
 
10
  # Load the model
11
  repo_id = "rmaitest/mlmodel2"
 
44
  # Create FastAPI app
45
  app = FastAPI()
46
 
47
+ # Create a route for the /predict API endpoint
48
+ @app.post("/predict")
49
+ async def predict(size: float, bedrooms: int, age: int):
50
+ # Call the Gradio function manually for the API route
51
+ return iface.fn(size, bedrooms, age)
52
 
53
+ # Launch Gradio interface (only for UI purposes, if needed)
54
  if __name__ == "__main__":
55
  iface.launch(share=True)
56
 
57
 
58
+