Spaces:
Runtime error
Runtime error
Initial WorkWise backend merged main.py -> app.py
Browse files- app copy 2.py +0 -26
- app.py +14 -74
- app.py.merged +86 -0
app copy 2.py
DELETED
|
@@ -1,26 +0,0 @@
|
|
| 1 |
-
import gradio as gr
|
| 2 |
-
from fastapi import FastAPI
|
| 3 |
-
import spaces
|
| 4 |
-
|
| 5 |
-
app = FastAPI()
|
| 6 |
-
|
| 7 |
-
@spaces.GPU
|
| 8 |
-
def your_gpu_function(input_data):
|
| 9 |
-
# Your GPU computation
|
| 10 |
-
return result
|
| 11 |
-
|
| 12 |
-
# FastAPI endpoint
|
| 13 |
-
@app.get("/api/predict")
|
| 14 |
-
async def predict(input: str):
|
| 15 |
-
result = your_gpu_function(input)
|
| 16 |
-
return {"result": result}
|
| 17 |
-
|
| 18 |
-
# Gradio interface (required for ZeroGPU)
|
| 19 |
-
with gr.Blocks() as demo:
|
| 20 |
-
gr.Interface(fn=your_gpu_function, inputs="text", outputs="text")
|
| 21 |
-
|
| 22 |
-
# Mount FastAPI to Gradio
|
| 23 |
-
app = gr.mount_gradio_app(app, demo, path="/")
|
| 24 |
-
|
| 25 |
-
if __name__ == "__main__":
|
| 26 |
-
demo.launch()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
app.py
CHANGED
|
@@ -1,86 +1,26 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastapi import FastAPI
|
| 3 |
-
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
import spaces
|
| 5 |
|
| 6 |
-
|
| 7 |
-
from app.config import settings
|
| 8 |
-
from app.routes import ingest_routes, ask_routes, metrics_routes
|
| 9 |
-
from app.services.vector_store import vector_store
|
| 10 |
-
from app.utils.logger import setup_logger
|
| 11 |
|
| 12 |
-
logger = setup_logger(__name__)
|
| 13 |
-
|
| 14 |
-
# Create FastAPI app
|
| 15 |
-
app = FastAPI(
|
| 16 |
-
title="WorkWise Backend",
|
| 17 |
-
description="RAG-powered Jira analytics application",
|
| 18 |
-
version="1.0.0"
|
| 19 |
-
)
|
| 20 |
-
|
| 21 |
-
# CORS Middleware
|
| 22 |
-
app.add_middleware(
|
| 23 |
-
CORSMiddleware,
|
| 24 |
-
allow_origins=settings.ALLOWED_ORIGINS,
|
| 25 |
-
allow_credentials=True,
|
| 26 |
-
allow_methods=["*"],
|
| 27 |
-
allow_headers=["*"],
|
| 28 |
-
)
|
| 29 |
-
|
| 30 |
-
# Include your existing routers
|
| 31 |
-
app.include_router(ingest_routes.router, prefix="/api", tags=["Ingestion"])
|
| 32 |
-
app.include_router(ask_routes.router, prefix="/api", tags=["Query"])
|
| 33 |
-
app.include_router(metrics_routes.router, prefix="/api", tags=["Metrics"])
|
| 34 |
-
|
| 35 |
-
@app.get("/")
|
| 36 |
-
async def root():
|
| 37 |
-
return {
|
| 38 |
-
"status": "online",
|
| 39 |
-
"service": "WorkWise API",
|
| 40 |
-
"version": "1.0.0"
|
| 41 |
-
}
|
| 42 |
-
|
| 43 |
-
@app.get("/health")
|
| 44 |
-
async def health_check():
|
| 45 |
-
try:
|
| 46 |
-
info = vector_store.get_collection_info()
|
| 47 |
-
return {
|
| 48 |
-
"status": "healthy",
|
| 49 |
-
"index_path": settings.FAISS_INDEX_PATH,
|
| 50 |
-
"payloads_path": settings.FAISS_PAYLOADS_PATH,
|
| 51 |
-
"vectors_count": info.get("vectors_count", 0)
|
| 52 |
-
}
|
| 53 |
-
except Exception as e:
|
| 54 |
-
logger.error(f"Health check failed: {e}")
|
| 55 |
-
return {"status": "error", "message": str(e)}
|
| 56 |
-
|
| 57 |
-
# Minimal Gradio UI (required for ZeroGPU)
|
| 58 |
@spaces.GPU
|
| 59 |
-
def
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
|
| 69 |
-
#
|
| 70 |
-
with gr.Blocks(
|
| 71 |
-
gr.
|
| 72 |
-
gr.Markdown("Ask questions about your Jira data")
|
| 73 |
-
|
| 74 |
-
with gr.Row():
|
| 75 |
-
input_text = gr.Textbox(label="Your Question", placeholder="e.g., What are the top issues this sprint?")
|
| 76 |
-
output_text = gr.Textbox(label="Answer")
|
| 77 |
-
|
| 78 |
-
submit_btn = gr.Button("Ask")
|
| 79 |
-
submit_btn.click(fn=query_jira, inputs=input_text, outputs=output_text)
|
| 80 |
|
| 81 |
-
# Mount
|
| 82 |
app = gr.mount_gradio_app(app, demo, path="/")
|
| 83 |
|
| 84 |
-
# Launch
|
| 85 |
if __name__ == "__main__":
|
| 86 |
demo.launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
from fastapi import FastAPI
|
|
|
|
| 3 |
import spaces
|
| 4 |
|
| 5 |
+
app = FastAPI()
|
|
|
|
|
|
|
|
|
|
|
|
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
@spaces.GPU
|
| 8 |
+
def your_gpu_function(input_data):
|
| 9 |
+
# Your GPU computation
|
| 10 |
+
return result
|
| 11 |
+
|
| 12 |
+
# FastAPI endpoint
|
| 13 |
+
@app.get("/api/predict")
|
| 14 |
+
async def predict(input: str):
|
| 15 |
+
result = your_gpu_function(input)
|
| 16 |
+
return {"result": result}
|
| 17 |
|
| 18 |
+
# Gradio interface (required for ZeroGPU)
|
| 19 |
+
with gr.Blocks() as demo:
|
| 20 |
+
gr.Interface(fn=your_gpu_function, inputs="text", outputs="text")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
+
# Mount FastAPI to Gradio
|
| 23 |
app = gr.mount_gradio_app(app, demo, path="/")
|
| 24 |
|
|
|
|
| 25 |
if __name__ == "__main__":
|
| 26 |
demo.launch()
|
app.py.merged
ADDED
|
@@ -0,0 +1,86 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import gradio as gr
|
| 2 |
+
from fastapi import FastAPI
|
| 3 |
+
from fastapi.middleware.cors import CORSMiddleware
|
| 4 |
+
import spaces
|
| 5 |
+
|
| 6 |
+
# Import your existing routes and services
|
| 7 |
+
from app.config import settings
|
| 8 |
+
from app.routes import ingest_routes, ask_routes, metrics_routes
|
| 9 |
+
from app.services.vector_store import vector_store
|
| 10 |
+
from app.utils.logger import setup_logger
|
| 11 |
+
|
| 12 |
+
logger = setup_logger(__name__)
|
| 13 |
+
|
| 14 |
+
# Create FastAPI app
|
| 15 |
+
app = FastAPI(
|
| 16 |
+
title="WorkWise Backend",
|
| 17 |
+
description="RAG-powered Jira analytics application",
|
| 18 |
+
version="1.0.0"
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# CORS Middleware
|
| 22 |
+
app.add_middleware(
|
| 23 |
+
CORSMiddleware,
|
| 24 |
+
allow_origins=settings.ALLOWED_ORIGINS,
|
| 25 |
+
allow_credentials=True,
|
| 26 |
+
allow_methods=["*"],
|
| 27 |
+
allow_headers=["*"],
|
| 28 |
+
)
|
| 29 |
+
|
| 30 |
+
# Include your existing routers
|
| 31 |
+
app.include_router(ingest_routes.router, prefix="/api", tags=["Ingestion"])
|
| 32 |
+
app.include_router(ask_routes.router, prefix="/api", tags=["Query"])
|
| 33 |
+
app.include_router(metrics_routes.router, prefix="/api", tags=["Metrics"])
|
| 34 |
+
|
| 35 |
+
@app.get("/")
|
| 36 |
+
async def root():
|
| 37 |
+
return {
|
| 38 |
+
"status": "online",
|
| 39 |
+
"service": "WorkWise API",
|
| 40 |
+
"version": "1.0.0"
|
| 41 |
+
}
|
| 42 |
+
|
| 43 |
+
@app.get("/health")
|
| 44 |
+
async def health_check():
|
| 45 |
+
try:
|
| 46 |
+
info = vector_store.get_collection_info()
|
| 47 |
+
return {
|
| 48 |
+
"status": "healthy",
|
| 49 |
+
"index_path": settings.FAISS_INDEX_PATH,
|
| 50 |
+
"payloads_path": settings.FAISS_PAYLOADS_PATH,
|
| 51 |
+
"vectors_count": info.get("vectors_count", 0)
|
| 52 |
+
}
|
| 53 |
+
except Exception as e:
|
| 54 |
+
logger.error(f"Health check failed: {e}")
|
| 55 |
+
return {"status": "error", "message": str(e)}
|
| 56 |
+
|
| 57 |
+
# Minimal Gradio UI (required for ZeroGPU)
|
| 58 |
+
@spaces.GPU
|
| 59 |
+
def query_jira(question: str):
|
| 60 |
+
"""Simple wrapper for Gradio - calls your actual RAG logic"""
|
| 61 |
+
try:
|
| 62 |
+
# Import your actual query function here
|
| 63 |
+
from app.services.rag_service import process_query # adjust import as needed
|
| 64 |
+
result = process_query(question)
|
| 65 |
+
return result
|
| 66 |
+
except Exception as e:
|
| 67 |
+
return f"Error: {str(e)}"
|
| 68 |
+
|
| 69 |
+
# Create Gradio interface
|
| 70 |
+
with gr.Blocks(title="WorkWise - Ask Jira") as demo:
|
| 71 |
+
gr.Markdown("# WorkWise - Jira RAG Assistant")
|
| 72 |
+
gr.Markdown("Ask questions about your Jira data")
|
| 73 |
+
|
| 74 |
+
with gr.Row():
|
| 75 |
+
input_text = gr.Textbox(label="Your Question", placeholder="e.g., What are the top issues this sprint?")
|
| 76 |
+
output_text = gr.Textbox(label="Answer")
|
| 77 |
+
|
| 78 |
+
submit_btn = gr.Button("Ask")
|
| 79 |
+
submit_btn.click(fn=query_jira, inputs=input_text, outputs=output_text)
|
| 80 |
+
|
| 81 |
+
# Mount Gradio to FastAPI
|
| 82 |
+
app = gr.mount_gradio_app(app, demo, path="/")
|
| 83 |
+
|
| 84 |
+
# Launch
|
| 85 |
+
if __name__ == "__main__":
|
| 86 |
+
demo.launch()
|