Spaces:
Runtime error
Runtime error
added app.py
Browse files
app.py
ADDED
@@ -0,0 +1,24 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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)
|