Spaces:
Runtime error
Runtime error
Updated with deepseek model
Browse files
app.py
CHANGED
|
@@ -1,56 +1,74 @@
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
|
| 5 |
# β
Function to analyze CSV data based on accuracy
|
| 6 |
def analyze_csv(file):
|
| 7 |
-
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 45 |
|
| 46 |
# β
Gradio Interface
|
| 47 |
iface = gr.Interface(
|
| 48 |
fn=analyze_csv,
|
| 49 |
inputs=gr.File(label="Upload CSV File"),
|
| 50 |
outputs="text",
|
| 51 |
-
title="Benchmark
|
| 52 |
-
description="Upload a CSV file
|
| 53 |
)
|
| 54 |
|
| 55 |
-
|
| 56 |
-
iface.launch()
|
|
|
|
| 1 |
import os
|
| 2 |
import gradio as gr
|
| 3 |
import pandas as pd
|
| 4 |
+
import torch
|
| 5 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline
|
| 6 |
+
|
| 7 |
+
# β
Use DeepSeek Free Model
|
| 8 |
+
model_name = "deepseek-ai/deepseek-coder-6.7b"
|
| 9 |
+
|
| 10 |
+
# β
Load DeepSeek model & tokenizer
|
| 11 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name)
|
| 12 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.float16, device_map="auto")
|
| 13 |
+
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
|
| 14 |
|
| 15 |
# β
Function to analyze CSV data based on accuracy
|
| 16 |
def analyze_csv(file):
|
| 17 |
+
try:
|
| 18 |
+
df = pd.read_csv(file.name) # Read uploaded CSV
|
| 19 |
+
|
| 20 |
+
# β
Ensure column names are stripped of extra spaces
|
| 21 |
+
df.columns = df.columns.str.strip()
|
| 22 |
+
|
| 23 |
+
# β
Validate required columns
|
| 24 |
+
required_columns = {"Run ID", "Latency (ms)", "Throughput (req/sec)", "Memory Usage (GB)", "CPU Utilization (%)"}
|
| 25 |
+
if not required_columns.issubset(df.columns):
|
| 26 |
+
return f"Error: Missing one or more required columns. Required: {', '.join(required_columns)}"
|
| 27 |
+
|
| 28 |
+
# β
Avoid division errors (replace zero values in Latency & Memory Usage)
|
| 29 |
+
df["Latency (ms)"].replace(0, 1e-6, inplace=True)
|
| 30 |
+
df["Memory Usage (GB)"].replace(0, 1e-6, inplace=True)
|
| 31 |
+
|
| 32 |
+
# β
Calculate Accuracy Score: Throughput / (Latency * Memory Usage)
|
| 33 |
+
df["Accuracy Score"] = df["Throughput (req/sec)"] / (df["Latency (ms)"] * df["Memory Usage (GB)"])
|
| 34 |
+
|
| 35 |
+
# β
Find the best-performing model
|
| 36 |
+
best_model = df.loc[df["Accuracy Score"].idxmax()]
|
| 37 |
+
best_run_id = best_model["Run ID"]
|
| 38 |
+
|
| 39 |
+
# β
Construct analysis summary
|
| 40 |
+
summary = f"""
|
| 41 |
+
**π Best Performing Test Run:** `{best_run_id}`
|
| 42 |
+
|
| 43 |
+
- **Latency:** {best_model["Latency (ms)"]} ms
|
| 44 |
+
- **Throughput:** {best_model["Throughput (req/sec)"]} req/sec
|
| 45 |
+
- **Memory Usage:** {best_model["Memory Usage (GB)"]} GB
|
| 46 |
+
- **CPU Utilization:** {best_model["CPU Utilization (%)"]}%
|
| 47 |
+
- **Accuracy Score:** {best_model["Accuracy Score"]:.6f}
|
| 48 |
+
---
|
| 49 |
+
**π Accuracy Ranking Table**
|
| 50 |
+
```plaintext
|
| 51 |
+
{df[["Run ID", "Accuracy Score"]].sort_values(by="Accuracy Score", ascending=False).to_string(index=False)}
|
| 52 |
+
```
|
| 53 |
+
---
|
| 54 |
+
Based on this benchmark, generate insights on why this test run performed best and provide recommendations.
|
| 55 |
+
"""
|
| 56 |
+
|
| 57 |
+
# β
Generate AI-based insights using DeepSeek
|
| 58 |
+
output = pipe(summary, max_new_tokens=150, do_sample=True, temperature=0.7)
|
| 59 |
+
|
| 60 |
+
return f"{summary}\n\n### π€ AI Insights:\n{output[0]['generated_text']}"
|
| 61 |
+
|
| 62 |
+
except Exception as e:
|
| 63 |
+
return f"β οΈ Error processing CSV: {str(e)}"
|
| 64 |
|
| 65 |
# β
Gradio Interface
|
| 66 |
iface = gr.Interface(
|
| 67 |
fn=analyze_csv,
|
| 68 |
inputs=gr.File(label="Upload CSV File"),
|
| 69 |
outputs="text",
|
| 70 |
+
title="Benchmark Analyzer (DeepSeek Free)",
|
| 71 |
+
description="Upload a benchmark CSV file to analyze test performance based on accuracy."
|
| 72 |
)
|
| 73 |
|
| 74 |
+
iface.launch()
|
|
|