Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -1,4 +1,4 @@
|
|
1 |
-
from fastapi import FastAPI
|
2 |
from fastapi.responses import HTMLResponse
|
3 |
from transformers import pipeline
|
4 |
import gradio as gr
|
@@ -15,18 +15,18 @@ def image_classifier(image):
|
|
15 |
results[result['label']] = result['score']
|
16 |
return results
|
17 |
|
18 |
-
# Define Gradio Interface
|
19 |
-
gr_interface = gr.Interface(fn=image_classifier, inputs=gr.Image(type="pil"), outputs="label")
|
20 |
-
|
21 |
# Define FastAPI app
|
22 |
app = FastAPI()
|
23 |
|
|
|
|
|
|
|
24 |
# Define route for Gradio interface
|
25 |
@app.get("/")
|
26 |
-
async def gr_interface_route():
|
27 |
-
return HTMLResponse(gr_interface.launch(
|
28 |
|
29 |
-
# Expose the FastAPI app using Uvicorn
|
30 |
-
if __name__ == "__main__":
|
31 |
-
|
32 |
-
|
|
|
1 |
+
from fastapi import FastAPI, Request
|
2 |
from fastapi.responses import HTMLResponse
|
3 |
from transformers import pipeline
|
4 |
import gradio as gr
|
|
|
15 |
results[result['label']] = result['score']
|
16 |
return results
|
17 |
|
|
|
|
|
|
|
18 |
# Define FastAPI app
|
19 |
app = FastAPI()
|
20 |
|
21 |
+
# Define Gradio Interface
|
22 |
+
gr_interface = gr.Interface(fn=image_classifier, inputs=gr.inputs.Image(), outputs="label")
|
23 |
+
|
24 |
# Define route for Gradio interface
|
25 |
@app.get("/")
|
26 |
+
async def gr_interface_route(request: Request):
|
27 |
+
return HTMLResponse(gr_interface.launch(request))
|
28 |
|
29 |
+
# Expose the FastAPI app using Uvicorn (for local testing)
|
30 |
+
# if __name__ == "__main__":
|
31 |
+
# import uvicorn
|
32 |
+
# uvicorn.run(app, host="0.0.0.0", port=8000)
|