asmaakbar commited on
Commit
3ae0d8c
·
1 Parent(s): 3ba17a7
Files changed (1) hide show
  1. app.py +26 -20
app.py CHANGED
@@ -5,9 +5,6 @@ from fastapi import FastAPI
5
  from fastapi.staticfiles import StaticFiles
6
  import tempfile
7
 
8
- # Import and create the FastAPI app
9
- from src.api.main import app as fastapi_app
10
-
11
  # Configuration for Hugging Face integration
12
  # When running in Hugging Face Spaces, the API will be available at the same server
13
  API_BASE_URL = os.getenv("API_BASE_URL", "http://localhost:8000")
@@ -90,24 +87,33 @@ with gr.Blocks(title="Todo Backend API - Hugging Face Interface") as demo:
90
  **Source Code:** [GitHub Repository](#)
91
  """)
92
 
93
- # For Hugging Face Spaces, we'll use the existing app and add Gradio to it
94
- app = fastapi_app
95
-
96
- # Mount the Gradio app using the proper method for newer Gradio versions
97
- app = gr.mount_gradio_app(app, demo, path="/gradio")
98
-
99
- # Add a root redirect to guide users to the proper endpoints
100
- @app.get("/")
101
- async def root():
102
- return {
103
- "message": "Todo Backend API with Gradio Interface",
104
- "api_docs": "/docs",
105
- "gradio_interface": "/gradio",
106
- "api_endpoints": {
107
- "auth": "/api/v1/auth",
108
- "tasks": "/api/v1/tasks"
 
 
 
 
 
109
  }
110
- }
 
 
 
 
111
 
112
  if __name__ == "__main__":
113
  # For local development, run the combined app
 
5
  from fastapi.staticfiles import StaticFiles
6
  import tempfile
7
 
 
 
 
8
  # Configuration for Hugging Face integration
9
  # When running in Hugging Face Spaces, the API will be available at the same server
10
  API_BASE_URL = os.getenv("API_BASE_URL", "http://localhost:8000")
 
87
  **Source Code:** [GitHub Repository](#)
88
  """)
89
 
90
+ # Create the main app and import the API routes properly to avoid circular imports
91
+ def create_combined_app():
92
+ from src.api.main import create_app
93
+
94
+ # Create the main API app
95
+ api_app = create_app()
96
+
97
+ # Mount the Gradio app using the proper method for newer Gradio versions
98
+ combined_app = gr.mount_gradio_app(api_app, demo, path="/gradio")
99
+
100
+ # Add a root redirect to guide users to the proper endpoints
101
+ @combined_app.get("/")
102
+ async def root():
103
+ return {
104
+ "message": "Todo Backend API with Gradio Interface",
105
+ "api_docs": "/docs",
106
+ "gradio_interface": "/gradio",
107
+ "api_endpoints": {
108
+ "auth": "/api/v1/auth",
109
+ "tasks": "/api/v1/tasks"
110
+ }
111
  }
112
+
113
+ return combined_app
114
+
115
+ # Create the combined app
116
+ app = create_combined_app()
117
 
118
  if __name__ == "__main__":
119
  # For local development, run the combined app