import gradio as gr import pandas as pd from transformers import pipeline # Load a summarization model summarizer = pipeline("summarization", model="facebook/bart-large-cnn") def preprocess_csv(file_path): df = pd.read_csv(file_path) events = [] for _, row in df.iterrows(): events.append(f"On {row['Date']} at {row['Time']}, state was {row['State']} → {row['Message Text']}") return "\n".join(events) def analyze_log(file_path, mode): text = preprocess_csv(file_path) # Build prompt depending on mode if mode == "Summarize": prompt = "Summarize the following AHU alarm log:\n\n" + text elif mode == "Highlight anomalies": prompt = "Identify unusual or repeated alarms in this AHU log and explain possible causes:\n\n" + text elif mode == "Suggest maintenance": prompt = "Based on this AHU alarm log, suggest maintenance actions:\n\n" + text else: prompt = text try: summary = summarizer(prompt, max_length=200, min_length=50, do_sample=False) return summary[0]['summary_text'] except Exception as e: return f"Error during summarization: {e}" iface = gr.Interface( fn=analyze_log, inputs=[ gr.File(type="filepath", label="Upload Log File"), gr.Dropdown(choices=["Summarize", "Highlight anomalies", "Suggest maintenance"], label="Analysis Mode") ], outputs="text", title="AHU Log Analyzer", description="Upload your log file (CSV) and choose how you want it analyzed." ) if __name__ == "__main__": iface.launch()