mahesh1209 commited on
Commit
f991080
·
verified ·
1 Parent(s): 26c10c5

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import logging, time, random
2
+ from prometheus_client import start_http_server, Counter, Gauge
3
+ import gradio as gr
4
+
5
+ # Logging setup
6
+ logging.basicConfig(level=logging.INFO)
7
+ logger = logging.getLogger("LLMMonitor")
8
+
9
+ # Prometheus metrics
10
+ requests_total = Counter("llm_requests_total", "Total LLM requests")
11
+ latency_gauge = Gauge("llm_latency_seconds", "LLM response latency")
12
+ error_gauge = Gauge("llm_error_count", "LLM error count")
13
+
14
+ # Simulated LLM call
15
+ def monitor_llm(prompt):
16
+ start = time.time()
17
+ requests_total.inc()
18
+ latency = random.uniform(0.1, 1.5)
19
+ time.sleep(latency)
20
+ latency_gauge.set(latency)
21
+
22
+ if random.random() < 0.2:
23
+ error_gauge.inc()
24
+ logger.warning("LLM error triggered")
25
+ return f"⚠️ Error: Simulated failure for prompt '{prompt}'"
26
+
27
+ logger.info(f"LLM processed: {prompt}")
28
+ return f"✅ LLM response to '{prompt}' in {latency:.2f}s"
29
+
30
+ # Gradio UI
31
+ demo = gr.Interface(fn=monitor_llm, inputs="text", outputs="text", title="LLM Health Monitor")
32
+ start_http_server(8000) # Prometheus metrics exposed at :8000
33
+ demo.launch()