Spaces:
Runtime error
Runtime error
Update app.py
Browse files
app.py
CHANGED
|
@@ -4,19 +4,20 @@ from pydantic import BaseModel
|
|
| 4 |
from prometheus_client import Counter, generate_latest, CONTENT_TYPE_LATEST
|
| 5 |
from transformers import pipeline
|
| 6 |
import gradio as gr
|
|
|
|
| 7 |
|
| 8 |
-
# β
|
| 9 |
app = FastAPI()
|
| 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
|
| 16 |
triage_pipeline = pipeline(
|
| 17 |
"text2text-generation",
|
| 18 |
-
model="
|
| 19 |
-
device=-1
|
| 20 |
)
|
| 21 |
|
| 22 |
# π₯ Request model
|
|
@@ -29,7 +30,7 @@ async def triage(incident: Incident):
|
|
| 29 |
triage_requests.inc()
|
| 30 |
try:
|
| 31 |
prompt = f"Classify this incident and suggest priority:\n\n{incident.description}"
|
| 32 |
-
result = triage_pipeline(prompt, max_new_tokens=
|
| 33 |
return {"triage": result.strip()}
|
| 34 |
except Exception as e:
|
| 35 |
triage_errors.inc()
|
|
@@ -50,7 +51,7 @@ def gradio_triage(description):
|
|
| 50 |
try:
|
| 51 |
triage_requests.inc()
|
| 52 |
prompt = f"Classify this incident and suggest priority:\n\n{description}"
|
| 53 |
-
result = triage_pipeline(prompt, max_new_tokens=
|
| 54 |
return result.strip()
|
| 55 |
except Exception as e:
|
| 56 |
triage_errors.inc()
|
|
@@ -61,9 +62,9 @@ demo = gr.Interface(
|
|
| 61 |
inputs=gr.Textbox(lines=5, placeholder="Describe the incident..."),
|
| 62 |
outputs="text",
|
| 63 |
title="Incident Triage Bot",
|
| 64 |
-
description="Classify incidents and suggest priority using a
|
| 65 |
)
|
| 66 |
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
|
|
|
| 4 |
from prometheus_client import Counter, generate_latest, CONTENT_TYPE_LATEST
|
| 5 |
from transformers import pipeline
|
| 6 |
import gradio as gr
|
| 7 |
+
import uvicorn
|
| 8 |
|
| 9 |
+
# β
FastAPI app
|
| 10 |
app = FastAPI()
|
| 11 |
|
| 12 |
# π Prometheus metrics
|
| 13 |
triage_requests = Counter("triage_requests_total", "Total triage requests")
|
| 14 |
triage_errors = Counter("triage_errors_total", "Total triage errors")
|
| 15 |
|
| 16 |
+
# π§ Load ultra-lightweight model
|
| 17 |
triage_pipeline = pipeline(
|
| 18 |
"text2text-generation",
|
| 19 |
+
model="sshleifer/tiny-t5", # ~25MB model
|
| 20 |
+
device=-1
|
| 21 |
)
|
| 22 |
|
| 23 |
# π₯ Request model
|
|
|
|
| 30 |
triage_requests.inc()
|
| 31 |
try:
|
| 32 |
prompt = f"Classify this incident and suggest priority:\n\n{incident.description}"
|
| 33 |
+
result = triage_pipeline(prompt, max_new_tokens=50)[0]["generated_text"]
|
| 34 |
return {"triage": result.strip()}
|
| 35 |
except Exception as e:
|
| 36 |
triage_errors.inc()
|
|
|
|
| 51 |
try:
|
| 52 |
triage_requests.inc()
|
| 53 |
prompt = f"Classify this incident and suggest priority:\n\n{description}"
|
| 54 |
+
result = triage_pipeline(prompt, max_new_tokens=50)[0]["generated_text"]
|
| 55 |
return result.strip()
|
| 56 |
except Exception as e:
|
| 57 |
triage_errors.inc()
|
|
|
|
| 62 |
inputs=gr.Textbox(lines=5, placeholder="Describe the incident..."),
|
| 63 |
outputs="text",
|
| 64 |
title="Incident Triage Bot",
|
| 65 |
+
description="Classify incidents and suggest priority using a tiny Transformers model"
|
| 66 |
)
|
| 67 |
|
| 68 |
+
# β
Mount Gradio properly
|
| 69 |
+
from fastapi.middleware.wsgi import WSGIMiddleware
|
| 70 |
+
app.mount("/gradio", gr.mount_gradio_app(app, demo, path="/gradio"))
|