Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -10,6 +10,7 @@ import gradio as gr
|
|
| 10 |
from fastapi import FastAPI
|
| 11 |
from fastapi.middleware.cors import CORSMiddleware
|
| 12 |
from pydantic import BaseModel
|
|
|
|
| 13 |
|
| 14 |
logger = logging.getLogger(__name__)
|
| 15 |
|
|
@@ -29,16 +30,6 @@ TEMPERATURE = 0.25
|
|
| 29 |
TOP_K = 3
|
| 30 |
EXTERNAL_API_URL = "https://omarelrayes-api.hf.space"
|
| 31 |
|
| 32 |
-
# FastAPI app
|
| 33 |
-
app = FastAPI(title="DermaScan AI - RAG System")
|
| 34 |
-
|
| 35 |
-
app.add_middleware(
|
| 36 |
-
CORSMiddleware,
|
| 37 |
-
allow_origins=["*"],
|
| 38 |
-
allow_methods=["*"],
|
| 39 |
-
allow_headers=["*"],
|
| 40 |
-
)
|
| 41 |
-
|
| 42 |
# Global variables
|
| 43 |
SESSIONS = {}
|
| 44 |
agent = None
|
|
@@ -92,6 +83,23 @@ def initialize_system():
|
|
| 92 |
|
| 93 |
logger.info("✓ System initialized successfully!")
|
| 94 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 95 |
# Pydantic models
|
| 96 |
class ChatRequest(BaseModel):
|
| 97 |
thread_id: str
|
|
@@ -306,8 +314,8 @@ def gradio_upload_image(image: Image.Image, thread_id: str = "default") -> tuple
|
|
| 306 |
logger.error(f"Upload error: {e}", exc_info=True)
|
| 307 |
return f"Error: {str(e)}", None, None, None
|
| 308 |
|
| 309 |
-
# Build Gradio UI
|
| 310 |
-
with gr.Blocks(title="DermaScan AI - Patient Portal"
|
| 311 |
gr.Markdown("""
|
| 312 |
# 🏥 DermaScan AI - مساعد أمراض الجلدية
|
| 313 |
|
|
@@ -375,11 +383,7 @@ with gr.Blocks(title="DermaScan AI - Patient Portal", theme=gr.themes.Soft()) as
|
|
| 375 |
# Mount Gradio to FastAPI
|
| 376 |
app = gr.mount_gradio_app(app, demo, path="/")
|
| 377 |
|
| 378 |
-
#
|
| 379 |
-
|
| 380 |
-
|
| 381 |
-
|
| 382 |
-
|
| 383 |
-
if __name__ == "__main__":
|
| 384 |
-
import uvicorn
|
| 385 |
-
uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
| 10 |
from fastapi import FastAPI
|
| 11 |
from fastapi.middleware.cors import CORSMiddleware
|
| 12 |
from pydantic import BaseModel
|
| 13 |
+
from contextlib import asynccontextmanager
|
| 14 |
|
| 15 |
logger = logging.getLogger(__name__)
|
| 16 |
|
|
|
|
| 30 |
TOP_K = 3
|
| 31 |
EXTERNAL_API_URL = "https://omarelrayes-api.hf.space"
|
| 32 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
# Global variables
|
| 34 |
SESSIONS = {}
|
| 35 |
agent = None
|
|
|
|
| 83 |
|
| 84 |
logger.info("✓ System initialized successfully!")
|
| 85 |
|
| 86 |
+
# FastAPI app with lifespan
|
| 87 |
+
@asynccontextmanager
|
| 88 |
+
async def lifespan(app: FastAPI):
|
| 89 |
+
# Startup
|
| 90 |
+
initialize_system()
|
| 91 |
+
yield
|
| 92 |
+
# Shutdown (if needed)
|
| 93 |
+
|
| 94 |
+
app = FastAPI(title="DermaScan AI - RAG System", lifespan=lifespan)
|
| 95 |
+
|
| 96 |
+
app.add_middleware(
|
| 97 |
+
CORSMiddleware,
|
| 98 |
+
allow_origins=["*"],
|
| 99 |
+
allow_methods=["*"],
|
| 100 |
+
allow_headers=["*"],
|
| 101 |
+
)
|
| 102 |
+
|
| 103 |
# Pydantic models
|
| 104 |
class ChatRequest(BaseModel):
|
| 105 |
thread_id: str
|
|
|
|
| 314 |
logger.error(f"Upload error: {e}", exc_info=True)
|
| 315 |
return f"Error: {str(e)}", None, None, None
|
| 316 |
|
| 317 |
+
# Build Gradio UI (بدون theme parameter هنا)
|
| 318 |
+
with gr.Blocks(title="DermaScan AI - Patient Portal") as demo:
|
| 319 |
gr.Markdown("""
|
| 320 |
# 🏥 DermaScan AI - مساعد أمراض الجلدية
|
| 321 |
|
|
|
|
| 383 |
# Mount Gradio to FastAPI
|
| 384 |
app = gr.mount_gradio_app(app, demo, path="/")
|
| 385 |
|
| 386 |
+
# ⚠️ احذف هذا السطر - HF Spaces يشغل التطبيق تلقائياً
|
| 387 |
+
# if __name__ == "__main__":
|
| 388 |
+
# import uvicorn
|
| 389 |
+
# uvicorn.run(app, host="0.0.0.0", port=7860)
|
|
|
|
|
|
|
|
|
|
|
|