logging and monitoring
#4
by
lobrien001
- opened
app.py
CHANGED
|
@@ -1,3 +1,31 @@
|
|
| 1 |
import gradio as gr
|
| 2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
gr.load("models/Sevixdd/roberta-base-finetuned-ner").launch()
|
|
|
|
| 1 |
import gradio as gr
|
| 2 |
|
| 3 |
+
import logging
|
| 4 |
+
import gradio as gr
|
| 5 |
+
from queue import Queue
|
| 6 |
+
import time
|
| 7 |
+
from prometheus_client import start_http_server, Counter, Histogram
|
| 8 |
+
|
| 9 |
+
# ... (Prometheus metrics setup and logging as before) ...
|
| 10 |
+
|
| 11 |
+
# --- Gradio Interface with Metrics Display ---
|
| 12 |
+
with gr.Blocks() as demo:
|
| 13 |
+
gr.Markdown("## Chat with the Bot")
|
| 14 |
+
chatbot = gr.ChatInterface(fn=chat_function)
|
| 15 |
+
|
| 16 |
+
with gr.Row():
|
| 17 |
+
request_count_display = gr.Textbox(label="Request Count")
|
| 18 |
+
avg_latency_display = gr.Textbox(label="Avg. Response Time (s)")
|
| 19 |
+
|
| 20 |
+
# --- Update Metrics Display ---
|
| 21 |
+
def update_metrics():
|
| 22 |
+
while True:
|
| 23 |
+
request_count_display.update(REQUEST_COUNT.collect()[0].samples[0].value)
|
| 24 |
+
avg_latency_display.update(round(REQUEST_LATENCY.collect()[0].samples[0].value, 2))
|
| 25 |
+
time.sleep(5) # Update every 5 seconds
|
| 26 |
+
|
| 27 |
+
demo.load(update_metrics, None, None, every=1) # Call update_metrics every second after initial page load
|
| 28 |
+
|
| 29 |
+
# ... (Start Prometheus metrics server and launch Gradio as before) ...
|
| 30 |
+
|
| 31 |
gr.load("models/Sevixdd/roberta-base-finetuned-ner").launch()
|