update-9
Browse files
app.py
CHANGED
|
@@ -1,107 +1,7 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
import requests
|
| 3 |
-
import os
|
| 4 |
from fastapi import FastAPI
|
| 5 |
-
from fastapi.staticfiles import StaticFiles
|
| 6 |
-
import tempfile
|
| 7 |
|
| 8 |
-
|
| 9 |
-
from src.api.main import app as fastapi_app
|
| 10 |
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def test_api_endpoint():
|
| 16 |
-
"""Test the API connection"""
|
| 17 |
-
try:
|
| 18 |
-
# When running integrated, we can't make requests to ourselves
|
| 19 |
-
# Instead, we'll return a success message indicating the API is available
|
| 20 |
-
return "โ
API is running! (Integrated mode - API endpoints available at /api/v1/*)"
|
| 21 |
-
except Exception as e:
|
| 22 |
-
return f"โ API connection failed: {str(e)}"
|
| 23 |
-
|
| 24 |
-
def get_api_status():
|
| 25 |
-
"""Get API status and information"""
|
| 26 |
-
try:
|
| 27 |
-
# When running integrated, return static info about the API
|
| 28 |
-
return "๐ค Welcome to the Todo Backend API\n\nApp: Todo Backend API\nVersion: 1.0.0"
|
| 29 |
-
except Exception as e:
|
| 30 |
-
return f"โ Error connecting to API: {str(e)}"
|
| 31 |
-
|
| 32 |
-
def api_documentation():
|
| 33 |
-
"""Show API documentation link"""
|
| 34 |
-
return "๐ API Documentation: /docs"
|
| 35 |
-
|
| 36 |
-
# Create Gradio interface
|
| 37 |
-
with gr.Blocks(title="Todo Backend API - Hugging Face Interface") as demo:
|
| 38 |
-
gr.Markdown("# ๐ค Todo Backend API - Hugging Face Interface")
|
| 39 |
-
gr.Markdown("This interface provides access to the Todo Backend API running on Hugging Face Spaces")
|
| 40 |
-
|
| 41 |
-
with gr.Tabs():
|
| 42 |
-
# API Status Tab
|
| 43 |
-
with gr.Tab("๐ API Status"):
|
| 44 |
-
gr.Markdown("## API Status Check")
|
| 45 |
-
status_btn = gr.Button("Check API Status")
|
| 46 |
-
status_output = gr.Textbox(label="API Status", lines=5)
|
| 47 |
-
status_btn.click(fn=get_api_status, outputs=status_output)
|
| 48 |
-
|
| 49 |
-
gr.Markdown("## Test API Connection")
|
| 50 |
-
test_btn = gr.Button("Test API Endpoint")
|
| 51 |
-
test_output = gr.Textbox(label="Test Result", lines=3)
|
| 52 |
-
test_btn.click(fn=test_api_endpoint, outputs=test_output)
|
| 53 |
-
|
| 54 |
-
# Documentation Tab
|
| 55 |
-
with gr.Tab("๐ Documentation"):
|
| 56 |
-
gr.Markdown("## API Documentation")
|
| 57 |
-
doc_btn = gr.Button("Show Documentation Link")
|
| 58 |
-
doc_output = gr.Textbox(label="Documentation URL")
|
| 59 |
-
doc_btn.click(fn=api_documentation, outputs=doc_output)
|
| 60 |
-
|
| 61 |
-
gr.Markdown("### Available Endpoints:")
|
| 62 |
-
gr.Markdown("- `GET /` - API status")
|
| 63 |
-
gr.Markdown("- `GET /api/v1/` - API root")
|
| 64 |
-
gr.Markdown("- `POST /api/v1/auth/register` - User registration")
|
| 65 |
-
gr.Markdown("- `POST /api/v1/auth/login` - User login")
|
| 66 |
-
gr.Markdown("- `GET /api/v1/tasks` - Get user tasks (requires auth)")
|
| 67 |
-
gr.Markdown("- `POST /api/v1/tasks` - Create task (requires auth)")
|
| 68 |
-
gr.Markdown("- `GET /api/v1/tasks/{task_id}` - Get specific task")
|
| 69 |
-
gr.Markdown("- `PUT /api/v1/tasks/{task_id}` - Update task")
|
| 70 |
-
gr.Markdown("- `DELETE /api/v1/tasks/{task_id}` - Delete task")
|
| 71 |
-
|
| 72 |
-
# Info Tab
|
| 73 |
-
with gr.Tab("โน๏ธ Information"):
|
| 74 |
-
gr.Markdown("## About This Space")
|
| 75 |
-
gr.Markdown("""
|
| 76 |
-
This Hugging Face Space provides a Gradio interface to interact with the Todo Backend API.
|
| 77 |
-
|
| 78 |
-
**Features:**
|
| 79 |
-
- JWT-based authentication
|
| 80 |
-
- User isolation for tasks
|
| 81 |
-
- Full CRUD operations
|
| 82 |
-
- Async database operations
|
| 83 |
-
|
| 84 |
-
**Technologies:**
|
| 85 |
-
- FastAPI (Backend)
|
| 86 |
-
- SQLModel (Database ORM)
|
| 87 |
-
- Gradio (Hugging Face Interface)
|
| 88 |
-
- Python 3.11
|
| 89 |
-
|
| 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 |
-
if __name__ == "__main__":
|
| 100 |
-
# For local development, run the combined app
|
| 101 |
-
import uvicorn
|
| 102 |
-
|
| 103 |
-
# Launch the combined app
|
| 104 |
-
uvicorn.run(app, host="0.0.0.0", port=8000)
|
| 105 |
-
else:
|
| 106 |
-
# For Hugging Face Spaces, make sure the correct app object is available
|
| 107 |
-
app = app
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
from fastapi import FastAPI
|
|
|
|
|
|
|
| 2 |
|
| 3 |
+
app = FastAPI()
|
|
|
|
| 4 |
|
| 5 |
+
@app.get("/")
|
| 6 |
+
def home():
|
| 7 |
+
return {"status": "ok"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|