Spaces:
Runtime error
Runtime error
Initial WorkWise backend merged main.py -> app.py
Browse files- app copy 2.py +57 -0
- app.py +15 -47
app copy 2.py
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
import spaces
|
| 3 |
+
|
| 4 |
+
# Import your services
|
| 5 |
+
from app.config import settings
|
| 6 |
+
from app.services.vector_store import vector_store
|
| 7 |
+
from app.utils.logger import setup_logger
|
| 8 |
+
|
| 9 |
+
logger = setup_logger(__name__)
|
| 10 |
+
|
| 11 |
+
@spaces.GPU
|
| 12 |
+
def query_jira(question: str):
|
| 13 |
+
try:
|
| 14 |
+
from app.services.rag_service import process_query
|
| 15 |
+
return process_query(question)
|
| 16 |
+
except Exception as e:
|
| 17 |
+
return f"Error: {str(e)}"
|
| 18 |
+
|
| 19 |
+
# Create Gradio app with API
|
| 20 |
+
with gr.Blocks() as demo:
|
| 21 |
+
gr.Markdown("# WorkWise - Jira RAG Assistant")
|
| 22 |
+
|
| 23 |
+
input_text = gr.Textbox(label="Question")
|
| 24 |
+
output_text = gr.Textbox(label="Answer")
|
| 25 |
+
submit_btn = gr.Button("Ask")
|
| 26 |
+
|
| 27 |
+
submit_btn.click(fn=query_jira, inputs=input_text, outputs=output_text, api_name="ask")
|
| 28 |
+
|
| 29 |
+
# Access FastAPI app from Gradio
|
| 30 |
+
app = demo.app
|
| 31 |
+
|
| 32 |
+
# CORS Middleware
|
| 33 |
+
app.add_middleware(
|
| 34 |
+
CORSMiddleware,
|
| 35 |
+
allow_origins=settings.ALLOWED_ORIGINS,
|
| 36 |
+
allow_credentials=True,
|
| 37 |
+
allow_methods=["*"],
|
| 38 |
+
allow_headers=["*"],
|
| 39 |
+
)
|
| 40 |
+
|
| 41 |
+
# Add your custom routes to Gradio's underlying FastAPI app
|
| 42 |
+
from app.routes import ingest_routes, ask_routes, metrics_routes
|
| 43 |
+
|
| 44 |
+
app.include_router(ingest_routes.router, prefix="/api", tags=["Ingestion"])
|
| 45 |
+
app.include_router(ask_routes.router, prefix="/api", tags=["Query"])
|
| 46 |
+
app.include_router(metrics_routes.router, prefix="/api", tags=["Metrics"])
|
| 47 |
+
|
| 48 |
+
@app.get("/health")
|
| 49 |
+
async def health_check():
|
| 50 |
+
try:
|
| 51 |
+
info = vector_store.get_collection_info()
|
| 52 |
+
return {"status": "healthy", "vectors_count": info.get("vectors_count", 0)}
|
| 53 |
+
except Exception as e:
|
| 54 |
+
return {"status": "error", "message": str(e)}
|
| 55 |
+
|
| 56 |
+
if __name__ == "__main__":
|
| 57 |
+
demo.launch(ssr_mode=False)
|
app.py
CHANGED
|
@@ -1,57 +1,25 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
-
import
|
| 3 |
|
| 4 |
-
#
|
| 5 |
-
|
| 6 |
-
from app.services.vector_store import vector_store
|
| 7 |
-
from app.utils.logger import setup_logger
|
| 8 |
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
def query_jira(question: str):
|
| 13 |
-
try:
|
| 14 |
-
from app.services.rag_service import process_query
|
| 15 |
-
return process_query(question)
|
| 16 |
-
except Exception as e:
|
| 17 |
-
return f"Error: {str(e)}"
|
| 18 |
-
|
| 19 |
-
# Create Gradio app with API
|
| 20 |
-
with gr.Blocks() as demo:
|
| 21 |
-
gr.Markdown("# WorkWise - Jira RAG Assistant")
|
| 22 |
-
|
| 23 |
-
input_text = gr.Textbox(label="Question")
|
| 24 |
-
output_text = gr.Textbox(label="Answer")
|
| 25 |
-
submit_btn = gr.Button("Ask")
|
| 26 |
-
|
| 27 |
-
submit_btn.click(fn=query_jira, inputs=input_text, outputs=output_text, api_name="ask")
|
| 28 |
-
|
| 29 |
-
# Access FastAPI app from Gradio
|
| 30 |
-
app = demo.app
|
| 31 |
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
allow_origins=settings.ALLOWED_ORIGINS,
|
| 36 |
-
allow_credentials=True,
|
| 37 |
-
allow_methods=["*"],
|
| 38 |
-
allow_headers=["*"],
|
| 39 |
-
)
|
| 40 |
|
| 41 |
-
#
|
| 42 |
-
|
|
|
|
| 43 |
|
| 44 |
-
|
| 45 |
-
app.include_router(ask_routes.router, prefix="/api", tags=["Query"])
|
| 46 |
-
app.include_router(metrics_routes.router, prefix="/api", tags=["Metrics"])
|
| 47 |
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
try:
|
| 51 |
-
info = vector_store.get_collection_info()
|
| 52 |
-
return {"status": "healthy", "vectors_count": info.get("vectors_count", 0)}
|
| 53 |
-
except Exception as e:
|
| 54 |
-
return {"status": "error", "message": str(e)}
|
| 55 |
|
| 56 |
if __name__ == "__main__":
|
| 57 |
demo.launch(ssr_mode=False)
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
|
| 4 |
+
# Minimal FastAPI
|
| 5 |
+
app = FastAPI()
|
|
|
|
|
|
|
| 6 |
|
| 7 |
+
@app.get("/health")
|
| 8 |
+
async def health():
|
| 9 |
+
return {"status": "ok"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 10 |
|
| 11 |
+
@app.get("/test")
|
| 12 |
+
async def test():
|
| 13 |
+
return {"message": "FastAPI is working"}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
|
| 15 |
+
# Minimal Gradio
|
| 16 |
+
def echo(text):
|
| 17 |
+
return f"You said: {text}"
|
| 18 |
|
| 19 |
+
demo = gr.Interface(fn=echo, inputs="text", outputs="text")
|
|
|
|
|
|
|
| 20 |
|
| 21 |
+
# Mount and get the app back
|
| 22 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 23 |
|
| 24 |
if __name__ == "__main__":
|
| 25 |
demo.launch(ssr_mode=False)
|