Spaces:
Sleeping
Sleeping
Update app_gradio.py
Browse files- app_gradio.py +9 -11
app_gradio.py
CHANGED
|
@@ -5,6 +5,7 @@ Ultra-Modern 3D UI | Optimized for Gradio 6.0 & HF Free Tier
|
|
| 5 |
from __future__ import annotations
|
| 6 |
import io
|
| 7 |
import time
|
|
|
|
| 8 |
import pandas as pd
|
| 9 |
import numpy as np
|
| 10 |
import gradio as gr
|
|
@@ -19,11 +20,10 @@ SOURCES = [
|
|
| 19 |
"AnalyticsEngine", "ThirdPartyAPI", "LegacyCRM",
|
| 20 |
]
|
| 21 |
|
| 22 |
-
# Updated to dynamically support the new Cache Hit tiers
|
| 23 |
def get_tier_icon(tier_name: str) -> str:
|
| 24 |
if "Regex" in tier_name: return "π’"
|
| 25 |
if "BERT" in tier_name: return "π΅"
|
| 26 |
-
if "Cache Hit" in tier_name: return "β‘"
|
| 27 |
if "fallback" in tier_name: return "π "
|
| 28 |
if "LLM" in tier_name: return "π‘"
|
| 29 |
return "βͺ"
|
|
@@ -36,7 +36,7 @@ EXAMPLE_LOGS = [
|
|
| 36 |
["LegacyCRM", "The 'BulkEmailSender' feature will be deprecated in v5.0."],
|
| 37 |
]
|
| 38 |
|
| 39 |
-
# ββ Custom CSS
|
| 40 |
CUSTOM_CSS = """
|
| 41 |
@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Share+Tech+Mono&family=Exo+2:wght@400;600&display=swap');
|
| 42 |
|
|
@@ -98,7 +98,7 @@ def classify_single(source: str, log_message: str):
|
|
| 98 |
result["label"],
|
| 99 |
f"{icon} {result['tier']}",
|
| 100 |
f"{result['confidence']:.1%}" if result["confidence"] else "N/A",
|
| 101 |
-
f"{latency:.4f} ms"
|
| 102 |
)
|
| 103 |
except Exception as e:
|
| 104 |
return f"Error: {str(e)}", "Fail", "β", "β"
|
|
@@ -110,8 +110,11 @@ def classify_batch(file, progress=gr.Progress(track_tqdm=True)):
|
|
| 110 |
t0 = time.perf_counter()
|
| 111 |
|
| 112 |
try:
|
| 113 |
-
#
|
| 114 |
-
|
|
|
|
|
|
|
|
|
|
| 115 |
total_time_sec = time.perf_counter() - t0
|
| 116 |
|
| 117 |
progress(0.9, desc="π Calculating Metrics...")
|
|
@@ -120,7 +123,6 @@ def classify_batch(file, progress=gr.Progress(track_tqdm=True)):
|
|
| 120 |
label_counts = df["predicted_label"].value_counts().to_dict()
|
| 121 |
tier_counts = df["tier_used"].value_counts().to_dict()
|
| 122 |
|
| 123 |
-
# FIX: Decouple Latency Metrics per tier instead of global distribution
|
| 124 |
tier_lines = []
|
| 125 |
for tier, count in tier_counts.items():
|
| 126 |
tier_df = df[df["tier_used"] == tier]
|
|
@@ -156,7 +158,6 @@ def classify_batch(file, progress=gr.Progress(track_tqdm=True)):
|
|
| 156 |
return None, f"β System Error: {str(e)}"
|
| 157 |
|
| 158 |
# ββ Theme & Layout ββββββββββββββββββββββββββββββββββββββββββ
|
| 159 |
-
|
| 160 |
THEME = gr.themes.Base(
|
| 161 |
primary_hue="blue",
|
| 162 |
secondary_hue="cyan",
|
|
@@ -168,7 +169,6 @@ with gr.Blocks(title="Log AI Engine") as demo:
|
|
| 168 |
gr.HTML("<div style='text-align: center; padding: 20px;'><h1>π LOG CLASSIFICATION SYSTEM</h1></div>")
|
| 169 |
|
| 170 |
with gr.Tabs():
|
| 171 |
-
# TAB 1: Single Log
|
| 172 |
with gr.Tab("β‘ REAL-TIME ANALYZER"):
|
| 173 |
with gr.Row():
|
| 174 |
with gr.Column(scale=1):
|
|
@@ -187,7 +187,6 @@ with gr.Blocks(title="Log AI Engine") as demo:
|
|
| 187 |
run_btn.click(classify_single, [src_in, msg_in], [lbl_out, tier_out, conf_out, lat_out])
|
| 188 |
gr.Examples(examples=EXAMPLE_LOGS, inputs=[src_in, msg_in])
|
| 189 |
|
| 190 |
-
# TAB 2: Batch CSV
|
| 191 |
with gr.Tab("π¦ BATCH PROCESSING"):
|
| 192 |
with gr.Row():
|
| 193 |
with gr.Column():
|
|
@@ -199,7 +198,6 @@ with gr.Blocks(title="Log AI Engine") as demo:
|
|
| 199 |
|
| 200 |
batch_btn.click(classify_batch, inputs=[csv_in], outputs=[csv_out, stats_out])
|
| 201 |
|
| 202 |
-
# ββ Optimized Launch ββββββββββββββββββββββββββββββββββββββββ
|
| 203 |
demo.queue(default_concurrency_limit=2).launch(
|
| 204 |
server_name="0.0.0.0",
|
| 205 |
server_port=7860,
|
|
|
|
| 5 |
from __future__ import annotations
|
| 6 |
import io
|
| 7 |
import time
|
| 8 |
+
import uuid
|
| 9 |
import pandas as pd
|
| 10 |
import numpy as np
|
| 11 |
import gradio as gr
|
|
|
|
| 20 |
"AnalyticsEngine", "ThirdPartyAPI", "LegacyCRM",
|
| 21 |
]
|
| 22 |
|
|
|
|
| 23 |
def get_tier_icon(tier_name: str) -> str:
|
| 24 |
if "Regex" in tier_name: return "π’"
|
| 25 |
if "BERT" in tier_name: return "π΅"
|
| 26 |
+
if "Cache Hit" in tier_name: return "β‘"
|
| 27 |
if "fallback" in tier_name: return "π "
|
| 28 |
if "LLM" in tier_name: return "π‘"
|
| 29 |
return "βͺ"
|
|
|
|
| 36 |
["LegacyCRM", "The 'BulkEmailSender' feature will be deprecated in v5.0."],
|
| 37 |
]
|
| 38 |
|
| 39 |
+
# ββ Custom CSS ββββββββββββββββββββββββ
|
| 40 |
CUSTOM_CSS = """
|
| 41 |
@import url('https://fonts.googleapis.com/css2?family=Rajdhani:wght@600;700&family=Share+Tech+Mono&family=Exo+2:wght@400;600&display=swap');
|
| 42 |
|
|
|
|
| 98 |
result["label"],
|
| 99 |
f"{icon} {result['tier']}",
|
| 100 |
f"{result['confidence']:.1%}" if result["confidence"] else "N/A",
|
| 101 |
+
f"{latency:.4f} ms"
|
| 102 |
)
|
| 103 |
except Exception as e:
|
| 104 |
return f"Error: {str(e)}", "Fail", "β", "β"
|
|
|
|
| 110 |
t0 = time.perf_counter()
|
| 111 |
|
| 112 |
try:
|
| 113 |
+
# FIX: Generate a unique output path per user to prevent data bleeding
|
| 114 |
+
unique_id = uuid.uuid4().hex
|
| 115 |
+
safe_output_path = f"/tmp/classified_output_{unique_id}.csv"
|
| 116 |
+
|
| 117 |
+
output_path, df = classify_csv(file.name, safe_output_path)
|
| 118 |
total_time_sec = time.perf_counter() - t0
|
| 119 |
|
| 120 |
progress(0.9, desc="π Calculating Metrics...")
|
|
|
|
| 123 |
label_counts = df["predicted_label"].value_counts().to_dict()
|
| 124 |
tier_counts = df["tier_used"].value_counts().to_dict()
|
| 125 |
|
|
|
|
| 126 |
tier_lines = []
|
| 127 |
for tier, count in tier_counts.items():
|
| 128 |
tier_df = df[df["tier_used"] == tier]
|
|
|
|
| 158 |
return None, f"β System Error: {str(e)}"
|
| 159 |
|
| 160 |
# ββ Theme & Layout ββββββββββββββββββββββββββββββββββββββββββ
|
|
|
|
| 161 |
THEME = gr.themes.Base(
|
| 162 |
primary_hue="blue",
|
| 163 |
secondary_hue="cyan",
|
|
|
|
| 169 |
gr.HTML("<div style='text-align: center; padding: 20px;'><h1>π LOG CLASSIFICATION SYSTEM</h1></div>")
|
| 170 |
|
| 171 |
with gr.Tabs():
|
|
|
|
| 172 |
with gr.Tab("β‘ REAL-TIME ANALYZER"):
|
| 173 |
with gr.Row():
|
| 174 |
with gr.Column(scale=1):
|
|
|
|
| 187 |
run_btn.click(classify_single, [src_in, msg_in], [lbl_out, tier_out, conf_out, lat_out])
|
| 188 |
gr.Examples(examples=EXAMPLE_LOGS, inputs=[src_in, msg_in])
|
| 189 |
|
|
|
|
| 190 |
with gr.Tab("π¦ BATCH PROCESSING"):
|
| 191 |
with gr.Row():
|
| 192 |
with gr.Column():
|
|
|
|
| 198 |
|
| 199 |
batch_btn.click(classify_batch, inputs=[csv_in], outputs=[csv_out, stats_out])
|
| 200 |
|
|
|
|
| 201 |
demo.queue(default_concurrency_limit=2).launch(
|
| 202 |
server_name="0.0.0.0",
|
| 203 |
server_port=7860,
|