Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,25 +5,20 @@ from prometheus_client import Counter, generate_latest, CONTENT_TYPE_LATEST
|
|
| 5 |
from transformers import pipeline
|
| 6 |
import gradio as gr
|
| 7 |
|
| 8 |
-
# β
FastAPI app
|
| 9 |
app = FastAPI(title="Incident Triage Bot")
|
| 10 |
|
| 11 |
-
# π Prometheus metrics
|
| 12 |
triage_requests = Counter("triage_requests_total", "Total triage requests")
|
| 13 |
triage_errors = Counter("triage_errors_total", "Total triage errors")
|
| 14 |
|
| 15 |
-
# π§ Load lightweight model (CPU only)
|
| 16 |
triage_pipeline = pipeline(
|
| 17 |
"text2text-generation",
|
| 18 |
model="google/flan-t5-small",
|
| 19 |
-
device=-1 #
|
| 20 |
)
|
| 21 |
|
| 22 |
-
# π₯ Request model
|
| 23 |
class Incident(BaseModel):
|
| 24 |
description: str
|
| 25 |
|
| 26 |
-
# π Triage API
|
| 27 |
@app.post("/triage")
|
| 28 |
async def triage(incident: Incident):
|
| 29 |
triage_requests.inc()
|
|
@@ -35,17 +30,14 @@ async def triage(incident: Incident):
|
|
| 35 |
triage_errors.inc()
|
| 36 |
return {"error": str(e)}
|
| 37 |
|
| 38 |
-
# π Metrics endpoint
|
| 39 |
@app.get("/metrics")
|
| 40 |
def metrics():
|
| 41 |
return Response(generate_latest(), media_type=CONTENT_TYPE_LATEST)
|
| 42 |
|
| 43 |
-
# π Root
|
| 44 |
@app.get("/")
|
| 45 |
def home():
|
| 46 |
return {"message": "LLM Incident Triage Bot is running!"}
|
| 47 |
|
| 48 |
-
# π¨ Gradio UI
|
| 49 |
def gradio_triage(description):
|
| 50 |
try:
|
| 51 |
triage_requests.inc()
|
|
|
|
| 5 |
from transformers import pipeline
|
| 6 |
import gradio as gr
|
| 7 |
|
|
|
|
| 8 |
app = FastAPI(title="Incident Triage Bot")
|
| 9 |
|
|
|
|
| 10 |
triage_requests = Counter("triage_requests_total", "Total triage requests")
|
| 11 |
triage_errors = Counter("triage_errors_total", "Total triage errors")
|
| 12 |
|
|
|
|
| 13 |
triage_pipeline = pipeline(
|
| 14 |
"text2text-generation",
|
| 15 |
model="google/flan-t5-small",
|
| 16 |
+
device=-1 # CPU-only
|
| 17 |
)
|
| 18 |
|
|
|
|
| 19 |
class Incident(BaseModel):
|
| 20 |
description: str
|
| 21 |
|
|
|
|
| 22 |
@app.post("/triage")
|
| 23 |
async def triage(incident: Incident):
|
| 24 |
triage_requests.inc()
|
|
|
|
| 30 |
triage_errors.inc()
|
| 31 |
return {"error": str(e)}
|
| 32 |
|
|
|
|
| 33 |
@app.get("/metrics")
|
| 34 |
def metrics():
|
| 35 |
return Response(generate_latest(), media_type=CONTENT_TYPE_LATEST)
|
| 36 |
|
|
|
|
| 37 |
@app.get("/")
|
| 38 |
def home():
|
| 39 |
return {"message": "LLM Incident Triage Bot is running!"}
|
| 40 |
|
|
|
|
| 41 |
def gradio_triage(description):
|
| 42 |
try:
|
| 43 |
triage_requests.inc()
|