Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -5,6 +5,7 @@ import logging
|
|
| 5 |
import plotly.express as px
|
| 6 |
from sklearn.ensemble import IsolationForest # For anomaly detection
|
| 7 |
from transformers import pipeline
|
|
|
|
| 8 |
|
| 9 |
# Configure logging for debugging
|
| 10 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
@@ -12,8 +13,10 @@ logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(
|
|
| 12 |
# Preload Hugging Face summarization model at startup
|
| 13 |
logging.info("Preloading Hugging Face model...")
|
| 14 |
try:
|
| 15 |
-
|
| 16 |
-
|
|
|
|
|
|
|
| 17 |
except Exception as e:
|
| 18 |
logging.error(f"Failed to preload model: {str(e)}")
|
| 19 |
raise e
|
|
@@ -166,7 +169,7 @@ def process_logs(file_obj, progress=gr.Progress()):
|
|
| 166 |
logging.error("Unsupported file format")
|
| 167 |
return "Unsupported file format. Please upload a CSV file.", None, None, None, None, None
|
| 168 |
|
| 169 |
-
# Use pandas to load CSV
|
| 170 |
progress(0.05, "Loading CSV file...")
|
| 171 |
try:
|
| 172 |
df = pd.read_csv(file_name)
|
|
|
|
| 5 |
import plotly.express as px
|
| 6 |
from sklearn.ensemble import IsolationForest # For anomaly detection
|
| 7 |
from transformers import pipeline
|
| 8 |
+
import torch # For GPU availability check
|
| 9 |
|
| 10 |
# Configure logging for debugging
|
| 11 |
logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(levelname)s - %(message)s')
|
|
|
|
| 13 |
# Preload Hugging Face summarization model at startup
|
| 14 |
logging.info("Preloading Hugging Face model...")
|
| 15 |
try:
|
| 16 |
+
# Check for GPU availability using torch.cuda
|
| 17 |
+
device = 0 if torch.cuda.is_available() else -1
|
| 18 |
+
summarizer = pipeline("text2text-generation", model="google/flan-t5-base", device=device) # Use GPU if available
|
| 19 |
+
logging.info(f"Hugging Face model preloaded successfully on device: {'GPU' if device == 0 else 'CPU'}")
|
| 20 |
except Exception as e:
|
| 21 |
logging.error(f"Failed to preload model: {str(e)}")
|
| 22 |
raise e
|
|
|
|
| 169 |
logging.error("Unsupported file format")
|
| 170 |
return "Unsupported file format. Please upload a CSV file.", None, None, None, None, None
|
| 171 |
|
| 172 |
+
# Use pandas to load CSV
|
| 173 |
progress(0.05, "Loading CSV file...")
|
| 174 |
try:
|
| 175 |
df = pd.read_csv(file_name)
|